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

Function TestCheckKubeContextNamespace

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

Source from the content-addressed store, hash-verified

218}
219
220func TestCheckKubeContextNamespace(t *testing.T) {
221 context1 := "context1"
222 ns1 := "n1"
223 ns2 := "ns2"
224
225 localCache := &localcache.LocalCache{
226 LastContext: &localcache.LastContextConfig{
227 Context: context1,
228 Namespace: ns1,
229 },
230 }
231 clusters := make(map[string]*api.Cluster)
232 clusters["cluster1"] = &api.Cluster{
233 Server: "server1",
234 }
235
236 contexts := make(map[string]*api.Context)
237 contexts[context1] = &api.Context{
238 Cluster: "cluster1",
239 }
240
241 loader := &configTesting.Loader{
242 RawConfig: &api.Config{
243 Clusters: clusters,
244 Contexts: contexts,
245 },
246 }
247
248 fakeLogger := fakelogger.NewFakeLogger()
249 fakeLogger.SetLevel(4)
250
251 ns := []string{ns1, ns2}
252 for _, n := range ns {
253 // creating client
254 client, err := NewClientFromContext(context1, ns2, false, loader)
255 if err != nil {
256 t.Fatal(err)
257 }
258 assert.Assert(t, client.CurrentContext() == context1)
259 assert.Assert(t, client.Namespace() == ns2)
260
261 fakeLogger.SetAnswer(n)
262 // checking kubeContext and reseting the client
263 isTerminalIn = true
264 client, err = CheckKubeContext(client, localCache, false, false, true, fakeLogger)
265 if err != nil {
266 t.Fatal(err)
267 }
268 assert.Assert(t, client.CurrentContext() == context1)
269 assert.Assert(t, client.Namespace() == n)
270 }
271}

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