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

Function TestSubmitServerErr

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

Source from the content-addressed store, hash-verified

574}
575
576func TestSubmitServerErr(t *testing.T) {
577 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
578 w.WriteHeader(http.StatusBadRequest)
579 fmt.Fprintf(w, `{"error": {"type": "error", "message": "test error"}}`)
580 })
581
582 ts := httptest.NewServer(handler)
583 defer ts.Close()
584
585 tmpDir, err := os.MkdirTemp("", "submit-err-tmp-dir")
586 defer os.RemoveAll(tmpDir)
587 assert.NoError(t, err)
588
589 v := viper.New()
590 v.Set("token", "abc123")
591 v.Set("workspace", tmpDir)
592 v.Set("apibaseurl", ts.URL)
593
594 cfg := config.Config{
595 Persister: config.InMemoryPersister{},
596 UserViperConfig: v,
597 DefaultBaseURL: "http://example.com",
598 }
599
600 dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
601 os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
602 writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
603
604 err = os.WriteFile(filepath.Join(dir, "file-1.txt"), []byte("This is file 1"), os.FileMode(0755))
605 assert.NoError(t, err)
606
607 files := []string{
608 filepath.Join(dir, "file-1.txt"),
609 }
610
611 err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files)
612
613 assert.Regexp(t, `expected response with Content-Type "application/json" but got status "400 Bad Request" with Content-Type "text/plain; charset=utf-8"`, err.Error())
614}
615
616func TestHandleErrorResponse(t *testing.T) {
617 handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 3

writeFakeMetadataFunction · 0.85
runSubmitFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected