MCPcopy
hub / github.com/wavetermdev/waveterm / TestParseEnvironmentFile

Function TestParseEnvironmentFile

pkg/util/pamparse/pamparse_test.go:15–63  ·  view source on GitHub ↗

Tests influenced by https://unix.stackexchange.com/questions/748790/where-is-the-syntax-for-etc-environment-documented

(t *testing.T)

Source from the content-addressed store, hash-verified

13
14// Tests influenced by https://unix.stackexchange.com/questions/748790/where-is-the-syntax-for-etc-environment-documented
15func TestParseEnvironmentFile(t *testing.T) {
16 const fileContent = `
17FOO1=bar
18FOO2="bar"
19FOO3="bar
20FOO4=bar"
21FOO5='bar'
22FOO6='bar"
23export FOO7=bar
24FOO8=bar bar bar
25#FOO9=bar
26FOO10=$PATH
27FOO11="foo#bar"
28 `
29
30 // create a temporary file with the content
31 tempFile := filepath.Join(t.TempDir(), "pam_env")
32 if err := os.WriteFile(tempFile, []byte(fileContent), 0644); err != nil {
33 t.Fatalf("failed to write file: %v", err)
34 }
35
36 // parse the file
37 got, err := pamparse.ParseEnvironmentFile(tempFile)
38 if err != nil {
39 t.Fatalf("failed to parse pam environment file: %v", err)
40 }
41
42 want := map[string]string{
43 "FOO1": "bar",
44 "FOO2": "bar",
45 "FOO3": "bar",
46 "FOO4": "bar\"",
47 "FOO5": "bar",
48 "FOO6": "bar",
49 "FOO7": "bar",
50 "FOO8": "bar bar bar",
51 "FOO10": "$PATH",
52 "FOO11": "foo",
53 }
54
55 if len(got) != len(want) {
56 t.Fatalf("expected %d environment variables, got %d", len(want), len(got))
57 }
58 for k, v := range want {
59 if got[k] != v {
60 t.Errorf("expected %q to be %q, got %q", k, v, got[k])
61 }
62 }
63}
64
65func TestParseEnvironmentConfFile(t *testing.T) {
66 const fileContent = `

Callers

nothing calls this directly

Calls 2

ParseEnvironmentFileFunction · 0.92
WriteFileMethod · 0.80

Tested by

no test coverage detected