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

Function TestLoadFromFile

tools/auth/clientauth_test.go:28–69  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestLoadFromFile(t *testing.T) {
29 loadAuthInfoTests := []struct {
30 authData string
31 authInfo *clientauth.Info
32 expectErr bool
33 }{
34 {
35 `{"user": "user", "password": "pass"}`,
36 &clientauth.Info{User: "user", Password: "pass"},
37 false,
38 },
39 {
40 "", nil, true,
41 },
42 }
43 for _, loadAuthInfoTest := range loadAuthInfoTests {
44 tt := loadAuthInfoTest
45 aifile, err := ioutil.TempFile("", "testAuthInfo")
46 if err != nil {
47 t.Errorf("Unexpected error: %v", err)
48 }
49 if tt.authData != "missing" {
50 defer os.Remove(aifile.Name())
51 defer aifile.Close()
52 _, err = aifile.WriteString(tt.authData)
53 if err != nil {
54 t.Errorf("Unexpected error: %v", err)
55 }
56 } else {
57 aifile.Close()
58 os.Remove(aifile.Name())
59 }
60 authInfo, err := clientauth.LoadFromFile(aifile.Name())
61 gotErr := err != nil
62 if gotErr != tt.expectErr {
63 t.Errorf("expected errorness: %v, actual errorness: %v", tt.expectErr, gotErr)
64 }
65 if !reflect.DeepEqual(authInfo, tt.authInfo) {
66 t.Errorf("Expected %v, got %v", tt.authInfo, authInfo)
67 }
68 }
69}

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.45

Tested by

no test coverage detected