@@ -2,105 +2,65 @@ package deployer
22
33import (
44 "testing"
5- )
6-
7- func TestSetCentralEndpoint (t * testing.T ) {
8- tests := []struct {
9- name string
10- input string
11- expectedCentralEndpoint string
12- expectedUserProvidedEndpoint string
13- }{
14- {
15- name : "plain host:port" ,
16- input : "10.0.0.1:443" ,
17- expectedCentralEndpoint : "10.0.0.1:443" ,
18- expectedUserProvidedEndpoint : "10.0.0.1:443" ,
19- },
20- {
21- name : "strips https prefix" ,
22- input : "https://10.0.0.1:443" ,
23- expectedCentralEndpoint : "10.0.0.1:443" ,
24- expectedUserProvidedEndpoint : "10.0.0.1:443" ,
25- },
26- {
27- name : "hostname with port" ,
28- input : "central.example.com:443" ,
29- expectedCentralEndpoint : "central.example.com:443" ,
30- expectedUserProvidedEndpoint : "central.example.com:443" ,
31- },
32- {
33- name : "strips https from hostname" ,
34- input : "https://central.example.com:443" ,
35- expectedCentralEndpoint : "central.example.com:443" ,
36- expectedUserProvidedEndpoint : "central.example.com:443" ,
37- },
38- {
39- name : "strips http prefix" ,
40- input : "http://10.0.0.1:443" ,
41- expectedCentralEndpoint : "10.0.0.1:443" ,
42- expectedUserProvidedEndpoint : "10.0.0.1:443" ,
43- },
44- {
45- name : "strips http from hostname" ,
46- input : "http://central.example.com:443" ,
47- expectedCentralEndpoint : "central.example.com:443" ,
48- expectedUserProvidedEndpoint : "central.example.com:443" ,
49- },
50- }
515
52- for _ , tt := range tests {
53- t .Run (tt .name , func (t * testing.T ) {
54- d := & Deployer {}
55- d .SetCentralEndpoint (tt .input )
56-
57- if d .centralEndpoint != tt .expectedCentralEndpoint {
58- t .Errorf ("centralEndpoint: got %q, want %q" , d .centralEndpoint , tt .expectedCentralEndpoint )
59- }
60- if d .userProvidedCentralEndpoint != tt .expectedUserProvidedEndpoint {
61- t .Errorf ("userProvidedCentralEndpoint: got %q, want %q" , d .userProvidedCentralEndpoint , tt .expectedUserProvidedEndpoint )
62- }
63- })
64- }
65- }
6+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
7+ )
668
67- func TestGetCentralEndpointForSensor (t * testing.T ) {
9+ func TestConfigureSpec_CentralEndpoint (t * testing.T ) {
6810 tests := []struct {
6911 name string
70- userProvided string
12+ centralEndpoint string
7113 centralNamespace string
7214 expected string
7315 }{
7416 {
7517 name : "falls back to internal endpoint" ,
76- userProvided : "" ,
18+ centralEndpoint : "" ,
7719 centralNamespace : "acs-central" ,
7820 expected : "central.acs-central.svc:443" ,
7921 },
8022 {
8123 name : "falls back to internal endpoint with custom namespace" ,
82- userProvided : "" ,
24+ centralEndpoint : "" ,
8325 centralNamespace : "stackrox" ,
8426 expected : "central.stackrox.svc:443" ,
8527 },
8628 {
87- name : "uses user- provided endpoint" ,
88- userProvided : "10.0.0.1 :443" ,
29+ name : "uses provided central endpoint" ,
30+ centralEndpoint : "central.example.com :443" ,
8931 centralNamespace : "acs-central" ,
32+ expected : "central.example.com:443" ,
33+ },
34+ {
35+ name : "provided endpoint takes precedence over namespace" ,
36+ centralEndpoint : "10.0.0.1:443" ,
37+ centralNamespace : "stackrox" ,
9038 expected : "10.0.0.1:443" ,
9139 },
9240 }
9341
9442 for _ , tt := range tests {
9543 t .Run (tt .name , func (t * testing.T ) {
96- d := & Deployer {
97- centralNamespace : tt .centralNamespace ,
98- userProvidedCentralEndpoint : tt . userProvided ,
44+ sc := & SecuredClusterConfig {
45+ CentralEndpoint : tt .centralEndpoint ,
46+ Spec : make ( map [ string ] interface {}) ,
9947 }
48+ roxie := & RoxieConfig {FeatureFlags : make (map [string ]bool )}
49+ central := & CentralConfig {Namespace : tt .centralNamespace }
10050
101- result := d .getCentralEndpointForSensor ()
102- if result != tt .expected {
103- t .Errorf ("got %q, want %q" , result , tt .expected )
51+ if err := sc .ConfigureSpec (roxie , central ); err != nil {
52+ t .Fatalf ("ConfigureSpec failed: %v" , err )
53+ }
54+
55+ got , found , err := unstructured .NestedString (sc .Spec , "centralEndpoint" )
56+ if err != nil {
57+ t .Fatalf ("failed to get centralEndpoint from spec: %v" , err )
58+ }
59+ if ! found {
60+ t .Fatal ("centralEndpoint not found in spec" )
61+ }
62+ if got != tt .expected {
63+ t .Errorf ("got %q, want %q" , got , tt .expected )
10464 }
10565 })
10666 }
0 commit comments