@@ -17,7 +17,7 @@ package commands
1717import (
1818 "testing"
1919
20- "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
20+ platmodel "github.com/codefresh-io/go-sdk/pkg/codefresh/model"
2121)
2222
2323func Test_getSuffixToClusterName (t * testing.T ) {
@@ -29,14 +29,14 @@ func Test_getSuffixToClusterName(t *testing.T) {
2929 cluster2 .Metadata .Name = "test-cluster-1"
3030 cluster3 .Metadata .Name = "test-cluster-2"
3131
32- clusters := []model .Cluster {
32+ clusters := []platmodel .Cluster {
3333 cluster1 ,
3434 cluster2 ,
3535 cluster3 ,
3636 }
3737
3838 type args struct {
39- clusters []model .Cluster
39+ clusters []platmodel .Cluster
4040 name string
4141 tempName string
4242 counter int
@@ -67,43 +67,25 @@ func Test_getSuffixToClusterName(t *testing.T) {
6767}
6868
6969func Test_sanitizeClusterName (t * testing.T ) {
70- type args struct {
71- name string
72- }
73- tests := []struct {
70+ tests := map [string ]struct {
7471 name string
75- args args
7672 want string
7773 wantErr bool
7874 }{
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=+::±§." ,
9277 want : "test----cluster------test-cluster--12-3" ,
9378 wantErr : false ,
9479 },
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" ,
10082 want : "" ,
10183 wantErr : true ,
10284 },
10385 }
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 )
10789
10890 if (err != nil ) != tt .wantErr {
10991 t .Errorf ("sanitizeClusterName() error = %v, wantErr %v" , err , tt .wantErr )
@@ -116,63 +98,44 @@ func Test_sanitizeClusterName(t *testing.T) {
11698}
11799
118100func Test_validateClusterName (t * testing.T ) {
119- type args struct {
120- name string
121- }
122- tests := []struct {
101+ tests := map [string ]struct {
123102 name string
124- args args
125103 wantErr bool
126104 }{
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" ,
132107 wantErr : false ,
133108 },
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" ,
139111 wantErr : true ,
140112 },
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#" ,
146115 wantErr : true ,
147116 },
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" ,
153119 wantErr : true ,
154120 },
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" ,
160123 wantErr : true ,
161124 },
162125 }
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 {
166129 t .Errorf ("validateClusterName() error = %v, wantErr %v" , err , tt .wantErr )
167130 }
168131 })
169132 }
170133}
171134
172- func getEmptyClusterEntity () model .Cluster {
135+ func getEmptyClusterEntity () platmodel .Cluster {
173136 empty := ""
174- return model .Cluster {
175- Metadata : & model .ObjectMeta {
137+ return platmodel .Cluster {
138+ Metadata : & platmodel .ObjectMeta {
176139 Group : "" ,
177140 Version : "" ,
178141 Kind : "" ,
@@ -188,9 +151,9 @@ func getEmptyClusterEntity() model.Cluster {
188151 Created : & empty ,
189152 UID : & empty ,
190153 },
191- Errors : []model .Error {},
192- ReferencedBy : []model .BaseEntity {},
193- References : []model .BaseEntity {},
154+ Errors : []platmodel .Error {},
155+ ReferencedBy : []platmodel .BaseEntity {},
156+ References : []platmodel .BaseEntity {},
194157 Server : "" ,
195158 Namespaces : []string {},
196159 }
0 commit comments