(t *testing.T)
| 237 | } |
| 238 | |
| 239 | func TestCorruptMetadata(t *testing.T) { |
| 240 | tempDir := t.TempDir() |
| 241 | s := New(tempDir, testCfg) |
| 242 | err := s.CreateOrUpdate( |
| 243 | Metadata{ |
| 244 | Endpoints: map[string]any{ |
| 245 | "ep1": endpoint{Foo: "bar"}, |
| 246 | }, |
| 247 | Metadata: context{Bar: "baz"}, |
| 248 | Name: "source", |
| 249 | }) |
| 250 | assert.NilError(t, err) |
| 251 | |
| 252 | // Simulate the meta.json file getting corrupted |
| 253 | // by some external process. |
| 254 | contextDir := s.meta.contextDir(contextdirOf("source")) |
| 255 | contextFile := filepath.Join(contextDir, metaFile) |
| 256 | err = os.WriteFile(contextFile, nil, 0o600) |
| 257 | assert.NilError(t, err) |
| 258 | |
| 259 | // Assert that the error message gives the user some clue where to look. |
| 260 | _, err = s.GetMetadata("source") |
| 261 | assert.ErrorContains(t, err, fmt.Sprintf("parsing %s: unexpected end of JSON input", contextFile)) |
| 262 | } |
| 263 | |
| 264 | func TestNames(t *testing.T) { |
| 265 | names, err := Names(nil) |
nothing calls this directly
no test coverage detected
searching dependent graphs…