(t *testing.T)
| 190 | } |
| 191 | |
| 192 | func 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 | |
| 240 | func TestCertificateData(t *testing.T) { |
| 241 | caData := []byte("ca-data") |
nothing calls this directly
no test coverage detected