@@ -17,7 +17,7 @@ package commands
17
17
import (
18
18
"testing"
19
19
20
- "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
20
+ platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
21
21
)
22
22
23
23
func Test_getSuffixToClusterName (t * testing.T ) {
@@ -29,14 +29,14 @@ func Test_getSuffixToClusterName(t *testing.T) {
29
29
cluster2 .Metadata .Name = "test-cluster-1"
30
30
cluster3 .Metadata .Name = "test-cluster-2"
31
31
32
- clusters := []model .Cluster {
32
+ clusters := []platmodel .Cluster {
33
33
cluster1 ,
34
34
cluster2 ,
35
35
cluster3 ,
36
36
}
37
37
38
38
type args struct {
39
- clusters []model .Cluster
39
+ clusters []platmodel .Cluster
40
40
name string
41
41
tempName string
42
42
counter int
@@ -67,43 +67,25 @@ func Test_getSuffixToClusterName(t *testing.T) {
67
67
}
68
68
69
69
func Test_sanitizeClusterName (t * testing.T ) {
70
- type args struct {
71
- name string
72
- }
73
- tests := []struct {
70
+ tests := map [string ]struct {
74
71
name string
75
- args args
76
72
want string
77
73
wantErr bool
78
74
}{
79
- {
80
- name : "should return sanitized string" ,
81
- args : args {
82
- name : "^-.Test!@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
83
- },
84
- want : "test----cluster------test-cluster--12-3" ,
85
- wantErr : false ,
86
- },
87
- {
88
- name : "should return sanitized string" ,
89
- args : args {
90
- name : "^-.123test!@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
91
- },
75
+ "should return sanitized string" : {
76
+ name : "^-.123test!@-:cluster&*`;')test.cluster(-12_3=+::±§." ,
92
77
want : "test----cluster------test-cluster--12-3" ,
93
78
wantErr : false ,
94
79
},
95
- {
96
- name : "should return error of sanitization failed" ,
97
- args : args {
98
- name : "12345" ,
99
- },
80
+ "should return error of sanitization failed" : {
81
+ name : "12345" ,
100
82
want : "" ,
101
83
wantErr : true ,
102
84
},
103
85
}
104
- for _ , tt := range tests {
105
- t .Run (tt . name , func (t * testing.T ) {
106
- got , err := sanitizeClusterName (tt .args . name )
86
+ for name , tt := range tests {
87
+ t .Run (name , func (t * testing.T ) {
88
+ got , err := sanitizeClusterName (tt .name )
107
89
108
90
if (err != nil ) != tt .wantErr {
109
91
t .Errorf ("sanitizeClusterName() error = %v, wantErr %v" , err , tt .wantErr )
@@ -116,63 +98,44 @@ func Test_sanitizeClusterName(t *testing.T) {
116
98
}
117
99
118
100
func Test_validateClusterName (t * testing.T ) {
119
- type args struct {
120
- name string
121
- }
122
- tests := []struct {
101
+ tests := map [string ]struct {
123
102
name string
124
- args args
125
103
wantErr bool
126
104
}{
127
- {
128
- name : "name should be valid" ,
129
- args : args {
130
- name : "test-cluster-123" ,
131
- },
105
+ "name should be valid" : {
106
+ name : "test-cluster-123" ,
132
107
wantErr : false ,
133
108
},
134
- {
135
- name : "name should not be valid (contains uppercase)" ,
136
- args : args {
137
- name : "Test-cluster" ,
138
- },
109
+ "name should not be valid (contains uppercase)" : {
110
+ name : "Test-cluster" ,
139
111
wantErr : true ,
140
112
},
141
- {
142
- name : "name should not be valid (contains invalid chars)" ,
143
- args : args {
144
- name : "test-cluster:test/cluster.123#" ,
145
- },
113
+ "name should not be valid (contains invalid chars)" : {
114
+ name : "test-cluster:test/cluster.123#" ,
146
115
wantErr : true ,
147
116
},
148
- {
149
- name : "name should not be valid (begins with numeric char)" ,
150
- args : args {
151
- name : "2test-cluster" ,
152
- },
117
+ "name should not be valid (begins with numeric char)" : {
118
+ name : "2test-cluster" ,
153
119
wantErr : true ,
154
120
},
155
- {
156
- name : "name should not be valid (too long)" ,
157
- args : args {
158
- name : "this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-123" ,
159
- },
121
+ "name should not be valid (too long)" : {
122
+ name : "this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-this-cluster-name-is-too-long-1-123" ,
160
123
wantErr : true ,
161
124
},
162
125
}
163
- for _ , tt := range tests {
164
- t .Run (tt . name , func (t * testing.T ) {
165
- if err := validateClusterName (tt .args . name ); (err != nil ) != tt .wantErr {
126
+ for name , tt := range tests {
127
+ t .Run (name , func (t * testing.T ) {
128
+ if err := validateClusterName (tt .name ); (err != nil ) != tt .wantErr {
166
129
t .Errorf ("validateClusterName() error = %v, wantErr %v" , err , tt .wantErr )
167
130
}
168
131
})
169
132
}
170
133
}
171
134
172
- func getEmptyClusterEntity () model .Cluster {
135
+ func getEmptyClusterEntity () platmodel .Cluster {
173
136
empty := ""
174
- return model .Cluster {
175
- Metadata : & model .ObjectMeta {
137
+ return platmodel .Cluster {
138
+ Metadata : & platmodel .ObjectMeta {
176
139
Group : "" ,
177
140
Version : "" ,
178
141
Kind : "" ,
@@ -188,9 +151,9 @@ func getEmptyClusterEntity() model.Cluster {
188
151
Created : & empty ,
189
152
UID : & empty ,
190
153
},
191
- Errors : []model .Error {},
192
- ReferencedBy : []model .BaseEntity {},
193
- References : []model .BaseEntity {},
154
+ Errors : []platmodel .Error {},
155
+ ReferencedBy : []platmodel .BaseEntity {},
156
+ References : []platmodel .BaseEntity {},
194
157
Server : "" ,
195
158
Namespaces : []string {},
196
159
}
0 commit comments