(t *testing.T)
| 695 | } |
| 696 | |
| 697 | func TestExerciseDirnameMatchesMetadataSlug(t *testing.T) { |
| 698 | submittedFiles := map[string]string{} |
| 699 | ts := fakeSubmitServer(t, submittedFiles) |
| 700 | defer ts.Close() |
| 701 | |
| 702 | tmpDir, err := os.MkdirTemp("", "submit-files") |
| 703 | defer os.RemoveAll(tmpDir) |
| 704 | assert.NoError(t, err) |
| 705 | |
| 706 | dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise-doesnt-match-metadata-slug") |
| 707 | os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755)) |
| 708 | writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise") |
| 709 | |
| 710 | file1 := filepath.Join(dir, "file-1.txt") |
| 711 | err = os.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755)) |
| 712 | assert.NoError(t, err) |
| 713 | |
| 714 | v := viper.New() |
| 715 | v.Set("token", "abc123") |
| 716 | v.Set("workspace", tmpDir) |
| 717 | v.Set("apibaseurl", ts.URL) |
| 718 | |
| 719 | cfg := config.Config{ |
| 720 | Persister: config.InMemoryPersister{}, |
| 721 | Dir: tmpDir, |
| 722 | UserViperConfig: v, |
| 723 | } |
| 724 | |
| 725 | err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file1}) |
| 726 | if assert.Error(t, err) { |
| 727 | assert.Regexp(t, "directory does not match exercise slug", err.Error()) |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | func writeFakeMetadata(t *testing.T, dir, trackID, exerciseSlug string) { |
| 732 | metadata := &workspace.ExerciseMetadata{ |
nothing calls this directly
no test coverage detected