(t *testing.T)
| 533 | } |
| 534 | |
| 535 | func TestSubmitRelativePath(t *testing.T) { |
| 536 | co := newCapturedOutput() |
| 537 | co.override() |
| 538 | defer co.reset() |
| 539 | |
| 540 | // The fake endpoint will populate this when it receives the call from the command. |
| 541 | submittedFiles := map[string]string{} |
| 542 | ts := fakeSubmitServer(t, submittedFiles) |
| 543 | defer ts.Close() |
| 544 | |
| 545 | tmpDir, err := os.MkdirTemp("", "relative-path") |
| 546 | defer os.RemoveAll(tmpDir) |
| 547 | assert.NoError(t, err) |
| 548 | |
| 549 | dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise") |
| 550 | os.MkdirAll(dir, os.FileMode(0755)) |
| 551 | |
| 552 | writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise") |
| 553 | |
| 554 | v := viper.New() |
| 555 | v.Set("token", "abc123") |
| 556 | v.Set("workspace", tmpDir) |
| 557 | v.Set("apibaseurl", ts.URL) |
| 558 | |
| 559 | cfg := config.Config{ |
| 560 | Persister: config.InMemoryPersister{}, |
| 561 | UserViperConfig: v, |
| 562 | } |
| 563 | |
| 564 | err = os.WriteFile(filepath.Join(dir, "file.txt"), []byte("This is a file."), os.FileMode(0755)) |
| 565 | |
| 566 | err = os.Chdir(dir) |
| 567 | assert.NoError(t, err) |
| 568 | |
| 569 | err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{"file.txt"}) |
| 570 | assert.NoError(t, err) |
| 571 | |
| 572 | assert.Equal(t, 1, len(submittedFiles)) |
| 573 | assert.Equal(t, "This is a file.", submittedFiles["file.txt"]) |
| 574 | } |
| 575 | |
| 576 | func TestSubmitServerErr(t *testing.T) { |
| 577 | handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected