MCPcopy Create free account
hub / github.com/exercism/cli / TestSubmitRelativePath

Function TestSubmitRelativePath

cmd/submit_test.go:535–574  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

533}
534
535func 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
576func TestSubmitServerErr(t *testing.T) {
577 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 6

newCapturedOutputFunction · 0.85
fakeSubmitServerFunction · 0.85
writeFakeMetadataFunction · 0.85
runSubmitFunction · 0.85
overrideMethod · 0.80
resetMethod · 0.80

Tested by

no test coverage detected