package catalog import ( "context" "errors" "net/http" "net/http/httptest" "testing" ) func TestUploadRefused(t *testing.T) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("Authorization") != "Bearer tok" { t.Errorf("authorization %q", r.Header.Get("Authorization")) } w.WriteHeader(http.StatusBadRequest) w.Write([]byte(`{"error":"bad_files","message":"These product files can't be used: index.xml: no ProductRating"}`)) })) defer s.Close() _, err := Upload(context.Background(), nil, "test", s.URL, "tok", []byte("zip")) var e *Error if !errors.As(err, &e) || e.Status != 400 || e.Code != "bad_files" { t.Fatalf("got %v", err) } if e.Error() != "the catalog refused the upload (400 bad_files): These product files can't be used: index.xml: no ProductRating" { t.Errorf("message %q", e.Error()) } }