Tests influenced by https://unix.stackexchange.com/questions/748790/where-is-the-syntax-for-etc-environment-documented
(t *testing.T)
| 13 | |
| 14 | // Tests influenced by https://unix.stackexchange.com/questions/748790/where-is-the-syntax-for-etc-environment-documented |
| 15 | func TestParseEnvironmentFile(t *testing.T) { |
| 16 | const fileContent = ` |
| 17 | FOO1=bar |
| 18 | FOO2="bar" |
| 19 | FOO3="bar |
| 20 | FOO4=bar" |
| 21 | FOO5='bar' |
| 22 | FOO6='bar" |
| 23 | export FOO7=bar |
| 24 | FOO8=bar bar bar |
| 25 | #FOO9=bar |
| 26 | FOO10=$PATH |
| 27 | FOO11="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 | |
| 65 | func TestParseEnvironmentConfFile(t *testing.T) { |
| 66 | const fileContent = ` |
nothing calls this directly
no test coverage detected