MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / TestParseEnvironmentConfFile

Function TestParseEnvironmentConfFile

pkg/util/pamparse/pamparse_test.go:65–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestParseEnvironmentConfFile(t *testing.T) {
66 const fileContent = `
67TEST DEFAULT=@{HOME}/.config\ state OVERRIDE=./config\ s
68FOO DEFAULT=@{HOME}/.config\ s
69STRING DEFAULT="string"
70STRINGOVERRIDE DEFAULT="string" OVERRIDE="string2"
71FOO11="foo#bar"
72 `
73
74 // create a temporary file with the content
75 tempFile := filepath.Join(t.TempDir(), "pam_env_conf")
76 if err := os.WriteFile(tempFile, []byte(fileContent), 0644); err != nil {
77 t.Fatalf("failed to write file: %v", err)
78 }
79
80 // parse the file
81 got, err := pamparse.ParseEnvironmentConfFile(tempFile, &pamparse.PamParseOpts{
82 Home: "/home/user",
83 Shell: "/bin/bash"},
84 )
85 if err != nil {
86 t.Fatalf("failed to parse pam environment conf file: %v", err)
87 }
88
89 want := map[string]string{
90 "TEST": "./config\\ s:/home/user/.config\\ state",
91 "FOO": "/home/user/.config\\ s",
92 "STRING": "string",
93 "STRINGOVERRIDE": "string2:string",
94 "FOO11": "foo",
95 }
96
97 if len(got) != len(want) {
98 t.Fatalf("expected %d environment variables, got %d", len(want), len(got))
99 }
100 for k, v := range want {
101 if got[k] != v {
102 t.Errorf("expected %q to be %q, got %q", k, v, got[k])
103 }
104 }
105}

Callers

nothing calls this directly

Calls 2

ParseEnvironmentConfFileFunction · 0.92
WriteFileMethod · 0.80

Tested by

no test coverage detected