@@ -6,76 +6,88 @@ import (
66 "github.com/stackrox/roxie/internal/deployer"
77 "github.com/stackrox/roxie/internal/logger"
88 "github.com/stackrox/roxie/internal/types"
9+ "github.com/stretchr/testify/assert"
910 "github.com/stretchr/testify/require"
11+ "k8s.io/utils/ptr"
1012)
1113
1214func TestClusterDefaults (t * testing.T ) {
1315 tests := []struct {
1416 name string
1517 clusterType types.ClusterType
1618 wantResourceProfile types.ResourceProfile
17- wantExposure types.Exposure
18- wantPortForwarding bool
19+ wantExposure * types.Exposure
20+ wantPortForwarding * bool
1921 }{
2022 {
2123 name : "kind cluster with default params" ,
2224 clusterType : types .ClusterTypeKind ,
2325 wantResourceProfile : types .ResourceProfileSmall ,
24- wantExposure : types .ExposureNone ,
25- wantPortForwarding : true ,
26+ wantExposure : ptr . To ( types .ExposureNone ) ,
27+ wantPortForwarding : ptr . To ( true ) ,
2628 },
2729 {
2830 name : "kind cluster with already correct params" ,
2931 clusterType : types .ClusterTypeKind ,
3032 wantResourceProfile : types .ResourceProfileSmall ,
31- wantExposure : types .ExposureNone ,
32- wantPortForwarding : true ,
33+ wantExposure : ptr . To ( types .ExposureNone ) ,
34+ wantPortForwarding : ptr . To ( true ) ,
3335 },
3436 {
3537 name : "kind cluster with partial match" ,
3638 clusterType : types .ClusterTypeKind ,
3739 wantResourceProfile : types .ResourceProfileSmall ,
38- wantExposure : types .ExposureNone ,
39- wantPortForwarding : true ,
40+ wantExposure : ptr . To ( types .ExposureNone ) ,
41+ wantPortForwarding : ptr . To ( true ) ,
4042 },
4143 {
4244 name : "unknown cluster type" ,
4345 clusterType : types .ClusterTypeUnknown ,
4446 wantResourceProfile : types .ResourceProfileAcsDefaults ,
45- wantExposure : types . ExposureNone ,
46- wantPortForwarding : false ,
47+ wantExposure : nil ,
48+ wantPortForwarding : nil ,
4749 },
4850 {
4951 name : "minikube cluster" ,
5052 clusterType : types .ClusterTypeMinikube ,
5153 wantResourceProfile : types .ResourceProfileSmall ,
52- wantExposure : types .ExposureNone ,
53- wantPortForwarding : true ,
54+ wantExposure : ptr . To ( types .ExposureNone ) ,
55+ wantPortForwarding : ptr . To ( true ) ,
5456 },
5557 {
5658 name : "crc cluster" ,
5759 clusterType : types .ClusterTypeCRC ,
5860 wantResourceProfile : types .ResourceProfileSmall ,
59- wantExposure : types .ExposureNone ,
60- wantPortForwarding : true ,
61+ wantExposure : ptr . To ( types .ExposureNone ) ,
62+ wantPortForwarding : ptr . To ( true ) ,
6163 },
6264 }
6365
6466 for _ , tt := range tests {
6567 t .Run (tt .name , func (t * testing.T ) {
66- config := deployer.Config {}
68+ config := deployer .NewConfig ()
6769 err := ApplyClusterDefaults (logger .New (), tt .clusterType , & config )
6870 require .NoError (t , err )
6971
7072 gotResourceProfile := ResolveAutoResourceProfile (tt .clusterType )
7173 if gotResourceProfile != tt .wantResourceProfile {
7274 t .Errorf ("Apply() resources = %v, want %v" , gotResourceProfile , tt .wantResourceProfile )
7375 }
74- if config .Central .Exposure != tt .wantExposure {
75- t .Errorf ("Apply() exposure = %v, want %v" , config .Central .Exposure , tt .wantExposure )
76+
77+ if tt .wantExposure == nil {
78+ assert .Nil (t , config .Central .Exposure , "central exposure is not nil" )
79+ } else {
80+ require .NotNil (t , config .Central .Exposure , "central exposure is nil" )
81+ assert .Equal (t , * tt .wantExposure , * config .Central .Exposure ,
82+ "exposure = %v, want %v" , * config .Central .Exposure , * tt .wantExposure )
7683 }
77- if config .Central .PortForwardingEnabled () != tt .wantPortForwarding {
78- t .Errorf ("Apply() portForward = %v, want %v" , config .Central .PortForwardingEnabled (), tt .wantPortForwarding )
84+
85+ if tt .wantPortForwarding == nil {
86+ assert .Nil (t , config .Central .PortForwarding , "central port forwarding is not nil" )
87+ } else {
88+ require .NotNil (t , config .Central .PortForwarding , "central port forwarding is nil" )
89+ assert .Equal (t , * tt .wantPortForwarding , * config .Central .PortForwarding ,
90+ "portForward = %v, want %v" , * config .Central .PortForwarding , * tt .wantPortForwarding )
7991 }
8092 })
8193 }
0 commit comments