| 99 | } |
| 100 | |
| 101 | func TestSave(t *testing.T) { |
| 102 | testCases := []saveTestCase{ |
| 103 | { |
| 104 | name: "Save config default", |
| 105 | config: &LocalCache{ |
| 106 | Vars: map[string]string{ |
| 107 | "key": "value", |
| 108 | }, |
| 109 | }, |
| 110 | expectedConfigFileName: ".devspace/cache.yaml", |
| 111 | expectedConfigFile: LocalCache{ |
| 112 | Vars: map[string]string{ |
| 113 | "key": "value", |
| 114 | }, |
| 115 | }, |
| 116 | }, |
| 117 | { |
| 118 | name: "Save config test.yaml", |
| 119 | config: &LocalCache{ |
| 120 | Vars: map[string]string{ |
| 121 | "key": "value", |
| 122 | }, |
| 123 | }, |
| 124 | expectedConfigFileName: ".devspace/cache-test.yaml", |
| 125 | expectedConfigFile: LocalCache{ |
| 126 | Vars: map[string]string{ |
| 127 | "key": "value", |
| 128 | }, |
| 129 | }, |
| 130 | }, |
| 131 | } |
| 132 | |
| 133 | dir := t.TempDir() |
| 134 | |
| 135 | wdBackup, err := os.Getwd() |
| 136 | if err != nil { |
| 137 | t.Fatalf("Error getting current working directory: %v", err) |
| 138 | } |
| 139 | err = os.Chdir(dir) |
| 140 | if err != nil { |
| 141 | t.Fatalf("Error changing working directory: %v", err) |
| 142 | } |
| 143 | |
| 144 | defer func() { |
| 145 | //Delete temp folder |
| 146 | err = os.Chdir(wdBackup) |
| 147 | if err != nil { |
| 148 | t.Fatalf("Error changing dir back: %v", err) |
| 149 | } |
| 150 | }() |
| 151 | |
| 152 | for _, testCase := range testCases { |
| 153 | testCase.config.cachePath = testCase.expectedConfigFileName |
| 154 | err := testCase.config.Save() |
| 155 | |
| 156 | if testCase.expectedErr == "" { |
| 157 | assert.NilError(t, err, "Error in testCase %s", testCase.name) |
| 158 | } else { |