|
| 1 | +package deployer |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
| 9 | +) |
| 10 | + |
| 11 | +func TestConfigureSpec_CentralEndpoint(t *testing.T) { |
| 12 | + tests := []struct { |
| 13 | + name string |
| 14 | + spec map[string]interface{} |
| 15 | + centralNamespace string |
| 16 | + expected string |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "sets internal endpoint when not provided", |
| 20 | + spec: map[string]interface{}{}, |
| 21 | + centralNamespace: "acs-central", |
| 22 | + expected: "central.acs-central.svc:443", |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "sets internal endpoint with custom namespace", |
| 26 | + spec: map[string]interface{}{}, |
| 27 | + centralNamespace: "stackrox", |
| 28 | + expected: "central.stackrox.svc:443", |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "preserves user-provided endpoint", |
| 32 | + spec: map[string]interface{}{"centralEndpoint": "central.example.com:443"}, |
| 33 | + centralNamespace: "acs-central", |
| 34 | + expected: "central.example.com:443", |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "user-provided endpoint takes precedence over internal default", |
| 38 | + spec: map[string]interface{}{"centralEndpoint": "10.0.0.1:443"}, |
| 39 | + centralNamespace: "stackrox", |
| 40 | + expected: "10.0.0.1:443", |
| 41 | + }, |
| 42 | + } |
| 43 | + |
| 44 | + for _, tt := range tests { |
| 45 | + t.Run(tt.name, func(t *testing.T) { |
| 46 | + sc := &SecuredClusterConfig{ |
| 47 | + Spec: tt.spec, |
| 48 | + } |
| 49 | + roxie := NewRoxieConfig() |
| 50 | + central := &CentralConfig{Namespace: tt.centralNamespace} |
| 51 | + |
| 52 | + err := sc.ConfigureSpec(&roxie, central) |
| 53 | + require.NoError(t, err, "ConfigureSpec failed") |
| 54 | + |
| 55 | + got, found, err := unstructured.NestedString(sc.Spec, "centralEndpoint") |
| 56 | + require.NoError(t, err, "failed to get centralEndpoint from spec") |
| 57 | + require.True(t, found, "centralEndpoint not found in spec") |
| 58 | + assert.Equal(t, tt.expected, got) |
| 59 | + }) |
| 60 | + } |
| 61 | +} |
0 commit comments