@@ -12,96 +12,176 @@ import (
1212
1313func TestClusterDefaults (t * testing.T ) {
1414 tests := []struct {
15- name string
16- clusterType types.ClusterType
17- wantResourceProfile types.ResourceProfile
18- wantExposure * types.Exposure
19- wantPortForwarding * bool
15+ name string
16+ clusterType types.ClusterType
17+ config deployer.Config
18+ wantConfig deployer.Config
2019 }{
2120 {
22- name : "kind cluster with default params" ,
23- clusterType : types .ClusterTypeKind ,
24- wantResourceProfile : types .ResourceProfileSmall ,
25- wantExposure : ptr .To (types .ExposureNone ),
26- wantPortForwarding : ptr .To (true ),
21+ name : "kind cluster with default params" ,
22+ clusterType : types .ClusterTypeKind ,
23+ wantConfig : deployer.Config {
24+ Central : deployer.CentralConfig {
25+ Exposure : ptr .To (types .ExposureNone ),
26+ PortForwarding : ptr .To (true ),
27+ },
28+ },
2729 },
2830 {
29- name : "kind cluster with already correct params" ,
30- clusterType : types .ClusterTypeKind ,
31- wantResourceProfile : types .ResourceProfileSmall ,
32- wantExposure : ptr .To (types .ExposureNone ),
33- wantPortForwarding : ptr .To (true ),
31+ name : "kind cluster with already correct params" ,
32+ clusterType : types .ClusterTypeKind ,
33+ wantConfig : deployer.Config {
34+ Central : deployer.CentralConfig {
35+ Exposure : ptr .To (types .ExposureNone ),
36+ PortForwarding : ptr .To (true ),
37+ },
38+ },
3439 },
3540 {
36- name : "kind cluster with partial match" ,
37- clusterType : types .ClusterTypeKind ,
38- wantResourceProfile : types .ResourceProfileSmall ,
39- wantExposure : ptr .To (types .ExposureNone ),
40- wantPortForwarding : ptr .To (true ),
41+ name : "kind cluster with partial match" ,
42+ clusterType : types .ClusterTypeKind ,
43+ wantConfig : deployer.Config {
44+ Central : deployer.CentralConfig {
45+ Exposure : ptr .To (types .ExposureNone ),
46+ PortForwarding : ptr .To (true ),
47+ },
48+ },
4149 },
4250 {
43- name : "unknown cluster type" ,
44- clusterType : types .ClusterTypeUnknown ,
45- wantResourceProfile : types .ResourceProfileAcsDefaults ,
46- wantExposure : nil ,
47- wantPortForwarding : nil ,
51+ name : "unknown cluster type" ,
52+ clusterType : types .ClusterTypeUnknown ,
53+ wantConfig : deployer.Config {},
4854 },
4955 {
50- name : "minikube cluster" ,
51- clusterType : types .ClusterTypeMinikube ,
52- wantResourceProfile : types .ResourceProfileSmall ,
53- wantExposure : ptr .To (types .ExposureNone ),
54- wantPortForwarding : ptr .To (true ),
56+ name : "minikube cluster" ,
57+ clusterType : types .ClusterTypeMinikube ,
58+ wantConfig : deployer.Config {
59+ Central : deployer.CentralConfig {
60+ Exposure : ptr .To (types .ExposureNone ),
61+ PortForwarding : ptr .To (true ),
62+ },
63+ },
5564 },
5665 {
57- name : "crc cluster" ,
58- clusterType : types .ClusterTypeCRC ,
59- wantResourceProfile : types .ResourceProfileSmall ,
60- wantExposure : ptr .To (types .ExposureNone ),
61- wantPortForwarding : ptr .To (true ),
66+ name : "crc cluster" ,
67+ clusterType : types .ClusterTypeCRC ,
68+ wantConfig : deployer.Config {
69+ Central : deployer.CentralConfig {
70+ Exposure : ptr .To (types .ExposureNone ),
71+ PortForwarding : ptr .To (true ),
72+ },
73+ },
6274 },
6375 {
64- name : "gke cluster" ,
65- clusterType : types .ClusterTypeInfraGKE ,
66- wantResourceProfile : types .ResourceProfileMedium ,
67- wantExposure : ptr .To (types .ExposureLoadBalancer ),
68- wantPortForwarding : ptr .To (false ),
76+ name : "gke cluster" ,
77+ clusterType : types .ClusterTypeInfraGKE ,
78+ wantConfig : deployer.Config {
79+ Central : deployer.CentralConfig {
80+ Exposure : ptr .To (types .ExposureLoadBalancer ),
81+ PortForwarding : ptr .To (false ),
82+ },
83+ },
6984 },
7085 {
71- name : "openshift cluster" ,
72- clusterType : types .ClusterTypeInfraOpenShift4 ,
73- wantResourceProfile : types .ResourceProfileMedium ,
74- wantExposure : ptr .To (types .ExposureLoadBalancer ),
75- wantPortForwarding : ptr .To (false ),
86+ name : "openshift cluster" ,
87+ clusterType : types .ClusterTypeInfraOpenShift4 ,
88+ wantConfig : deployer.Config {
89+ Central : deployer.CentralConfig {
90+ Exposure : ptr .To (types .ExposureLoadBalancer ),
91+ PortForwarding : ptr .To (false ),
92+ },
93+ },
94+ },
95+ {
96+ name : "cluster does not override existing values" ,
97+ clusterType : types .ClusterTypeInfraGKE ,
98+ config : deployer.Config {
99+ Central : deployer.CentralConfig {
100+ Exposure : ptr .To (types .ExposureNone ),
101+ PortForwarding : ptr .To (true ),
102+ },
103+ },
104+ wantConfig : deployer.Config {
105+ Central : deployer.CentralConfig {
106+ Exposure : ptr .To (types .ExposureNone ),
107+ PortForwarding : ptr .To (true ),
108+ },
109+ },
76110 },
77111 }
78112
79113 for _ , tt := range tests {
80114 t .Run (tt .name , func (t * testing.T ) {
81- config := deployer . NewConfig ()
115+ config := tt . config
82116 _ , err := ApplyClusterDefaults (tt .clusterType , & config )
83117 require .NoError (t , err )
84118
85- gotResourceProfile := ResolveAutoResourceProfile (tt .clusterType )
86- if gotResourceProfile != tt .wantResourceProfile {
87- t .Errorf ("Apply() resources = %v, want %v" , gotResourceProfile , tt .wantResourceProfile )
88- }
89-
90- if tt .wantExposure == nil {
119+ if tt .wantConfig .Central .Exposure == nil {
91120 assert .Nil (t , config .Central .Exposure , "central exposure is not nil" )
92121 } else {
93122 require .NotNil (t , config .Central .Exposure , "central exposure is nil" )
94- assert .Equal (t , * tt .wantExposure , * config .Central .Exposure ,
95- "exposure = %v, want %v" , * config .Central .Exposure , * tt .wantExposure )
123+ assert .Equal (t , * tt .wantConfig . Central . Exposure , * config .Central .Exposure ,
124+ "exposure = %v, want %v" , * config .Central .Exposure , * tt .wantConfig . Central . Exposure )
96125 }
97126
98- if tt .wantPortForwarding == nil {
127+ if tt .wantConfig . Central . PortForwarding == nil {
99128 assert .Nil (t , config .Central .PortForwarding , "central port forwarding is not nil" )
100129 } else {
101130 require .NotNil (t , config .Central .PortForwarding , "central port forwarding is nil" )
102- assert .Equal (t , * tt .wantPortForwarding , * config .Central .PortForwarding ,
103- "portForward = %v, want %v" , * config .Central .PortForwarding , * tt .wantPortForwarding )
131+ assert .Equal (t , * tt .wantConfig . Central . PortForwarding , * config .Central .PortForwarding ,
132+ "portForward = %v, want %v" , * config .Central .PortForwarding , * tt .wantConfig . Central . PortForwarding )
104133 }
105134 })
106135 }
107136}
137+
138+ func TestResolveAutoResourceProfile (t * testing.T ) {
139+ tests := []struct {
140+ name string
141+ clusterType types.ClusterType
142+ want types.ResourceProfile
143+ }{
144+ {
145+ name : "kind cluster" ,
146+ clusterType : types .ClusterTypeKind ,
147+ want : types .ResourceProfileSmall ,
148+ },
149+ {
150+ name : "minikube cluster" ,
151+ clusterType : types .ClusterTypeMinikube ,
152+ want : types .ResourceProfileSmall ,
153+ },
154+ {
155+ name : "k3s cluster" ,
156+ clusterType : types .ClusterTypeK3s ,
157+ want : types .ResourceProfileSmall ,
158+ },
159+ {
160+ name : "crc cluster" ,
161+ clusterType : types .ClusterTypeCRC ,
162+ want : types .ResourceProfileSmall ,
163+ },
164+ {
165+ name : "gke cluster" ,
166+ clusterType : types .ClusterTypeInfraGKE ,
167+ want : types .ResourceProfileMedium ,
168+ },
169+ {
170+ name : "openshift cluster" ,
171+ clusterType : types .ClusterTypeInfraOpenShift4 ,
172+ want : types .ResourceProfileMedium ,
173+ },
174+ {
175+ name : "unknown cluster type" ,
176+ clusterType : types .ClusterTypeUnknown ,
177+ want : types .ResourceProfileAcsDefaults ,
178+ },
179+ }
180+
181+ for _ , tt := range tests {
182+ t .Run (tt .name , func (t * testing.T ) {
183+ got := ResolveAutoResourceProfile (tt .clusterType )
184+ assert .Equal (t , tt .want , got )
185+ })
186+ }
187+ }
0 commit comments