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

Function TestMigratingFile

tools/clientcmd/loader_test.go:484–516  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

482}
483
484func TestMigratingFile(t *testing.T) {
485 sourceFile, _ := ioutil.TempFile("", "")
486 defer os.Remove(sourceFile.Name())
487 destinationFile, _ := ioutil.TempFile("", "")
488 // delete the file so that we'll write to it
489 os.Remove(destinationFile.Name())
490
491 WriteToFile(testConfigAlfa, sourceFile.Name())
492
493 loadingRules := ClientConfigLoadingRules{
494 MigrationRules: map[string]string{destinationFile.Name(): sourceFile.Name()},
495 }
496
497 if _, err := loadingRules.Load(); err != nil {
498 t.Errorf("unexpected error %v", err)
499 }
500
501 // the load should have recreated this file
502 defer os.Remove(destinationFile.Name())
503
504 sourceContent, err := ioutil.ReadFile(sourceFile.Name())
505 if err != nil {
506 t.Errorf("unexpected error %v", err)
507 }
508 destinationContent, err := ioutil.ReadFile(destinationFile.Name())
509 if err != nil {
510 t.Errorf("unexpected error %v", err)
511 }
512
513 if !reflect.DeepEqual(sourceContent, destinationContent) {
514 t.Errorf("source and destination do not match")
515 }
516}
517
518func TestMigratingFileLeaveExistingFileAlone(t *testing.T) {
519 sourceFile, _ := ioutil.TempFile("", "")

Callers

nothing calls this directly

Calls 4

LoadMethod · 0.95
WriteToFileFunction · 0.85
ErrorfMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected