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

Function TestErrorReadingFile

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

Source from the content-addressed store, hash-verified

104}
105
106func TestErrorReadingFile(t *testing.T) {
107 commandLineFile, _ := ioutil.TempFile("", "")
108 defer os.Remove(commandLineFile.Name())
109
110 if err := ioutil.WriteFile(commandLineFile.Name(), []byte("bogus value"), 0644); err != nil {
111 t.Fatalf("Error creating tempfile: %v", err)
112 }
113
114 loadingRules := ClientConfigLoadingRules{
115 ExplicitPath: commandLineFile.Name(),
116 }
117
118 _, err := loadingRules.Load()
119 if err == nil {
120 t.Fatalf("Expected error for unloadable file, got none")
121 }
122 if !strings.Contains(err.Error(), commandLineFile.Name()) {
123 t.Fatalf("Expected error about '%s', got %s", commandLineFile.Name(), err.Error())
124 }
125}
126
127func TestErrorReadingNonFile(t *testing.T) {
128 tmpdir, err := ioutil.TempDir("", "")

Callers

nothing calls this directly

Calls 3

LoadMethod · 0.95
ErrorMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected