TestPathConfigExists asserts that `Path` identifies existent config files
(t *testing.T)
| 21 | |
| 22 | // TestPathConfigExists asserts that `Path` identifies existent config files |
| 23 | func TestPathConfigExists(t *testing.T) { |
| 24 | |
| 25 | // initialize a temporary config file |
| 26 | confFile, err := os.CreateTemp("", "cheat-test") |
| 27 | if err != nil { |
| 28 | t.Errorf("failed to create temp file: %v", err) |
| 29 | } |
| 30 | |
| 31 | // clean up the temp file |
| 32 | defer os.Remove(confFile.Name()) |
| 33 | |
| 34 | // package cheatpaths |
| 35 | paths := []string{ |
| 36 | "/cheat-test-conf-does-not-exist", |
| 37 | confFile.Name(), |
| 38 | } |
| 39 | |
| 40 | // assert |
| 41 | got, err := Path(paths) |
| 42 | if err != nil { |
| 43 | t.Errorf("failed to identify config file: %v", err) |
| 44 | } |
| 45 | if got != confFile.Name() { |
| 46 | t.Errorf( |
| 47 | "failed to return config path: want: %s, got: %s", |
| 48 | confFile.Name(), |
| 49 | got, |
| 50 | ) |
| 51 | } |
| 52 | } |