| 144 | } |
| 145 | |
| 146 | func TestFileCache_missingFileIsFine(t *testing.T) { |
| 147 | t.Parallel() |
| 148 | dir := t.TempDir() |
| 149 | path := filepath.Join(dir, "nested", "cache.json") |
| 150 | |
| 151 | c, err := New(Config{Enabled: true, Path: path}) |
| 152 | require.NoError(t, err) |
| 153 | |
| 154 | _, ok := c.Lookup("anything") |
| 155 | assert.False(t, ok) |
| 156 | |
| 157 | c.Store("hello", "world") |
| 158 | |
| 159 | got, ok := c.Lookup("hello") |
| 160 | assert.True(t, ok) |
| 161 | assert.Equal(t, "world", got) |
| 162 | |
| 163 | // And the directory should have been created. |
| 164 | _, err = os.Stat(path) |
| 165 | assert.NoError(t, err) |
| 166 | } |
| 167 | |
| 168 | func TestFileCache_corruptFile(t *testing.T) { |
| 169 | t.Parallel() |