@@ -52,10 +52,11 @@ func TestReadConfigValid(t *testing.T) {
52
52
validConfigPath := writeConfig (t , `
53
53
log_level = 1
54
54
port = "9999"
55
- kubeconfig = "test"
55
+ sse_base_url = "https://example.com"
56
+ kubeconfig = "./path/to/config"
56
57
list_output = "yaml"
57
58
read_only = true
58
- disable_destructive = false
59
+ disable_destructive = true
59
60
60
61
denied_resources = [
61
62
{group = "apps", version = "v1", kind = "Deployment"},
@@ -84,33 +85,62 @@ disabled_tools = ["pods_delete", "pods_top", "pods_log", "pods_run", "pods_exec"
84
85
config .DeniedResources [0 ].Kind != "Deployment" {
85
86
t .Errorf ("Unexpected denied resources: %v" , config .DeniedResources [0 ])
86
87
}
88
+ })
89
+ t .Run ("log_level parsed correctly" , func (t * testing.T ) {
87
90
if config .LogLevel != 1 {
88
91
t .Fatalf ("Unexpected log level: %v" , config .LogLevel )
89
92
}
93
+ })
94
+ t .Run ("port parsed correctly" , func (t * testing.T ) {
90
95
if config .Port != "9999" {
91
96
t .Fatalf ("Unexpected port value: %v" , config .Port )
92
97
}
93
- if config .SSEBaseURL != "" {
98
+ })
99
+ t .Run ("sse_base_url parsed correctly" , func (t * testing.T ) {
100
+ if config .SSEBaseURL != "https://example.com" {
94
101
t .Fatalf ("Unexpected sse_base_url value: %v" , config .SSEBaseURL )
95
102
}
96
- if config .KubeConfig != "test" {
103
+ })
104
+ t .Run ("kubeconfig parsed correctly" , func (t * testing.T ) {
105
+ if config .KubeConfig != "./path/to/config" {
97
106
t .Fatalf ("Unexpected kubeconfig value: %v" , config .KubeConfig )
98
107
}
108
+ })
109
+ t .Run ("list_output parsed correctly" , func (t * testing.T ) {
99
110
if config .ListOutput != "yaml" {
100
111
t .Fatalf ("Unexpected list_output value: %v" , config .ListOutput )
101
112
}
113
+ })
114
+ t .Run ("read_only parsed correctly" , func (t * testing.T ) {
102
115
if ! config .ReadOnly {
103
116
t .Fatalf ("Unexpected read-only mode: %v" , config .ReadOnly )
104
117
}
105
- if config .DisableDestructive {
118
+ })
119
+ t .Run ("disable_destructive parsed correctly" , func (t * testing.T ) {
120
+ if ! config .DisableDestructive {
106
121
t .Fatalf ("Unexpected disable destructive: %v" , config .DisableDestructive )
107
122
}
123
+ })
124
+ t .Run ("enabled_tools parsed correctly" , func (t * testing.T ) {
108
125
if len (config .EnabledTools ) != 8 {
109
126
t .Fatalf ("Unexpected enabled tools: %v" , config .EnabledTools )
127
+
110
128
}
129
+ for i , tool := range []string {"configuration_view" , "events_list" , "namespaces_list" , "pods_list" , "resources_list" , "resources_get" , "resources_create_or_update" , "resources_delete" } {
130
+ if config .EnabledTools [i ] != tool {
131
+ t .Errorf ("Expected enabled tool %d to be %s, got %s" , i , tool , config .EnabledTools [i ])
132
+ }
133
+ }
134
+ })
135
+ t .Run ("disabled_tools parsed correctly" , func (t * testing.T ) {
111
136
if len (config .DisabledTools ) != 5 {
112
137
t .Fatalf ("Unexpected disabled tools: %v" , config .DisabledTools )
113
138
}
139
+ for i , tool := range []string {"pods_delete" , "pods_top" , "pods_log" , "pods_run" , "pods_exec" } {
140
+ if config .DisabledTools [i ] != tool {
141
+ t .Errorf ("Expected disabled tool %d to be %s, got %s" , i , tool , config .DisabledTools [i ])
142
+ }
143
+ }
114
144
})
115
145
}
116
146
0 commit comments