MCPcopy
hub / github.com/kubernetes/client-go / TestModifyContext

Function TestModifyContext

tools/clientcmd/client_config_test.go:192–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

190}
191
192func TestModifyContext(t *testing.T) {
193 expectedCtx := map[string]bool{
194 "updated": true,
195 "clean": true,
196 }
197
198 tempPath, err := ioutil.TempFile("", "testclientcmd-")
199 if err != nil {
200 t.Fatalf("unexpected error: %v", err)
201 }
202 defer os.Remove(tempPath.Name())
203
204 pathOptions := NewDefaultPathOptions()
205 config := createValidTestConfig()
206
207 pathOptions.GlobalFile = tempPath.Name()
208
209 // define new context and assign it - our path options config
210 config.Contexts["updated"] = &clientcmdapi.Context{
211 Cluster: "updated",
212 AuthInfo: "updated",
213 }
214 config.CurrentContext = "updated"
215
216 if err := ModifyConfig(pathOptions, *config, true); err != nil {
217 t.Errorf("Unexpected error: %v", err)
218 }
219
220 startingConfig, err := pathOptions.GetStartingConfig()
221 if err != nil {
222 t.Fatalf("Unexpected error: %v", err)
223 }
224
225 // make sure the current context was updated
226 matchStringArg("updated", startingConfig.CurrentContext, t)
227
228 // there should now be two contexts
229 if len(startingConfig.Contexts) != len(expectedCtx) {
230 t.Fatalf("unexpected nuber of contexts, expecting %v, but found %v", len(expectedCtx), len(startingConfig.Contexts))
231 }
232
233 for key := range startingConfig.Contexts {
234 if !expectedCtx[key] {
235 t.Fatalf("expected context %q to exist", key)
236 }
237 }
238}
239
240func TestCertificateData(t *testing.T) {
241 caData := []byte("ca-data")

Callers

nothing calls this directly

Calls 7

NewDefaultPathOptionsFunction · 0.85
createValidTestConfigFunction · 0.85
ModifyConfigFunction · 0.85
matchStringArgFunction · 0.85
ErrorfMethod · 0.65
GetStartingConfigMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected