MCPcopy Index your code
hub / github.com/devspace-sh/devspace / TestCheckKubeContext

Function TestCheckKubeContext

pkg/devspace/kubectl/client_test.go:146–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestCheckKubeContext(t *testing.T) {
147 context1 := "context1"
148 context2 := "context2"
149 ns1 := "n1"
150 ns2 := "ns2"
151
152 localCache := &localcache.LocalCache{
153 LastContext: &localcache.LastContextConfig{
154 Context: context1,
155 Namespace: ns1,
156 },
157 }
158
159 testCases := []testCaseContext{
160 {
161 // selecting last context
162 selectContext: context1,
163 namespace: ns1, // ns2 should be reverted to back to ns1
164 },
165 {
166 // selecting current context
167 selectContext: context2,
168 namespace: ns2, // same ns should be used
169 },
170 }
171
172 clusters := make(map[string]*api.Cluster)
173 clusters["cluster1"] = &api.Cluster{
174 Server: "server1",
175 }
176 clusters["cluster2"] = &api.Cluster{
177 Server: "server2",
178 }
179
180 contexts := make(map[string]*api.Context)
181 contexts[context1] = &api.Context{
182 Cluster: "cluster1",
183 }
184 contexts[context2] = &api.Context{
185 Cluster: "cluster2",
186 }
187
188 loader := &configTesting.Loader{
189 RawConfig: &api.Config{
190 Clusters: clusters,
191 Contexts: contexts,
192 },
193 }
194
195 fakeLogger := fakelogger.NewFakeLogger()
196 fakeLogger.SetLevel(4)
197
198 for _, tc := range testCases {
199 // creating client
200 client, err := NewClientFromContext(context2, ns2, false, loader)
201 if err != nil {
202 t.Fatal(err)
203 }

Callers

nothing calls this directly

Calls 7

SetLevelMethod · 0.95
SetAnswerMethod · 0.95
NewClientFromContextFunction · 0.85
CheckKubeContextFunction · 0.85
CurrentContextMethod · 0.65
NamespaceMethod · 0.65
FatalMethod · 0.45

Tested by

no test coverage detected