(t *testing.T)
| 63 | } |
| 64 | |
| 65 | func TestParseEnvironmentConfFile(t *testing.T) { |
| 66 | const fileContent = ` |
| 67 | TEST DEFAULT=@{HOME}/.config\ state OVERRIDE=./config\ s |
| 68 | FOO DEFAULT=@{HOME}/.config\ s |
| 69 | STRING DEFAULT="string" |
| 70 | STRINGOVERRIDE DEFAULT="string" OVERRIDE="string2" |
| 71 | FOO11="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 | } |
nothing calls this directly
no test coverage detected