crossplane

Форк
0
/
version_test.go 
96 строк · 2.2 Кб
1
/*
2
Copyright 2020 The Crossplane Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package version
18

19
import (
20
	"errors"
21
	"testing"
22

23
	"github.com/google/go-cmp/cmp"
24

25
	"github.com/crossplane/crossplane-runtime/pkg/test"
26
)
27

28
func TestInRange(t *testing.T) {
29
	type args struct {
30
		version string
31
		r       string
32
	}
33
	type want struct {
34
		is  bool
35
		err error
36
	}
37
	cases := map[string]struct {
38
		reason string
39
		args   args
40
		want   want
41
	}{
42
		"ValidInRange": {
43
			reason: "Should return true when a valid semantic version is in a valid range.",
44
			args: args{
45
				version: "v0.13.0",
46
				r:       ">0.12.0",
47
			},
48
			want: want{
49
				is: true,
50
			},
51
		},
52
		"ValidNotInRange": {
53
			reason: "Should return false when a valid semantic version is not in a valid range.",
54
			args: args{
55
				version: "v0.13.0",
56
				r:       ">0.13.0",
57
			},
58
			want: want{
59
				is: false,
60
			},
61
		},
62
		"InvalidVersion": {
63
			reason: "Should return error when version is invalid.",
64
			args: args{
65
				version: "v0a.13.0",
66
			},
67
			want: want{
68
				err: errors.New("Invalid Semantic Version"),
69
			},
70
		},
71
		"InvalidRange": {
72
			reason: "Should return error when range is invalid.",
73
			args: args{
74
				version: "v0.13.0",
75
				r:       ">a2",
76
			},
77
			want: want{
78
				err: errors.New("improper constraint: >a2"),
79
			},
80
		},
81
	}
82

83
	for name, tc := range cases {
84
		t.Run(name, func(t *testing.T) {
85
			version = tc.args.version
86
			is, err := New().InConstraints(tc.args.r)
87
			if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" {
88
				t.Errorf("\n%s\nInRange(...): -want err, +got err:\n%s", tc.reason, diff)
89
			}
90

91
			if diff := cmp.Diff(tc.want.is, is, test.EquateErrors()); diff != "" {
92
				t.Errorf("\n%s\nInRange(...): -want, +got:\n%s", tc.reason, diff)
93
			}
94
		})
95
	}
96
}
97

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.