(t *testing.T)
| 33 | } |
| 34 | |
| 35 | func TestExists(t *testing.T) { |
| 36 | testCases := []existsTestCase{ |
| 37 | { |
| 38 | name: "Only custom file name exists", |
| 39 | configPath: "mypath.yaml", |
| 40 | files: map[string]interface{}{ |
| 41 | "mypath.yaml": "", |
| 42 | }, |
| 43 | expectedanswer: true, |
| 44 | }, |
| 45 | { |
| 46 | name: "Default file name does not exist", |
| 47 | files: map[string]interface{}{ |
| 48 | "mypath.yaml": "", |
| 49 | }, |
| 50 | expectedanswer: false, |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | dir := t.TempDir() |
| 55 | |
| 56 | wdBackup, err := os.Getwd() |
| 57 | if err != nil { |
| 58 | t.Fatalf("Error getting current working directory: %v", err) |
| 59 | } |
| 60 | err = os.Chdir(dir) |
| 61 | if err != nil { |
| 62 | t.Fatalf("Error changing working directory: %v", err) |
| 63 | } |
| 64 | |
| 65 | defer func() { |
| 66 | //Delete temp folder |
| 67 | err = os.Chdir(wdBackup) |
| 68 | if err != nil { |
| 69 | t.Fatalf("Error changing dir back: %v", err) |
| 70 | } |
| 71 | }() |
| 72 | |
| 73 | for _, testCase := range testCases { |
| 74 | testExists(testCase, t) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func testExists(testCase existsTestCase, t *testing.T) { |
| 79 | defer func() { |
nothing calls this directly
no test coverage detected