MCPcopy
hub / github.com/kubernetes/kubectl / Test_processEnvFileLine

Function Test_processEnvFileLine

pkg/cmd/util/env_file_test.go:26–71  ·  view source on GitHub ↗

Test the cases of proccessEnvFileLine that can be run without touching the environment.

(t *testing.T)

Source from the content-addressed store, hash-verified

24// Test the cases of proccessEnvFileLine that can be run without touching the
25// environment.
26func Test_processEnvFileLine(t *testing.T) {
27 testCases := []struct {
28 name string
29 line []byte
30 currentLine int
31 expectedKey string
32 expectedValue string
33 expectedErr string
34 }{
35 {"the utf8bom is trimmed on the first line",
36 append(utf8bom, 'a', '=', 'c'), 0, "a", "c", ""},
37
38 {"the utf8bom is NOT trimmed on the second line",
39 append(utf8bom, 'a', '=', 'c'), 1, "", "", "not a valid key name"},
40
41 {"no key is returned on a comment line",
42 []byte{' ', '#', 'c'}, 0, "", "", ""},
43
44 {"no key is returned on a blank line",
45 []byte{' ', ' ', '\t'}, 0, "", "", ""},
46
47 {"key is returned even with no value",
48 []byte{' ', 'x', '='}, 0, "x", "", ""},
49 }
50 for _, tt := range testCases {
51 t.Run(tt.name, func(t *testing.T) {
52 key, value, err := processEnvFileLine(tt.line, `filename`, tt.currentLine)
53 t.Logf("Testing that %s.", tt.name)
54 if tt.expectedKey != key {
55 t.Errorf("\texpected key %q, received %q", tt.expectedKey, key)
56 }
57 if tt.expectedValue != value {
58 t.Errorf("\texpected value %q, received %q", tt.expectedValue, value)
59 }
60 if len(tt.expectedErr) == 0 {
61 if err != nil {
62 t.Errorf("\tunexpected err %v", err)
63 }
64 } else {
65 if !strings.Contains(err.Error(), tt.expectedErr) {
66 t.Errorf("\terr %v doesn't match expected %q", err, tt.expectedErr)
67 }
68 }
69 })
70 }
71}
72
73// proccessEnvFileLine needs to fetch the value from the environment if no
74// equals sign is provided.

Callers

nothing calls this directly

Calls 3

processEnvFileLineFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…