diff options
Diffstat (limited to 'main_test.go')
-rw-r--r-- | main_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..d1b864d --- /dev/null +++ b/main_test.go @@ -0,0 +1,30 @@ +package main + +import ( + "io" + "net/http" + "net/http/httptest" + "net/url" + "testing" +) + +func TestSyncRejection(t *testing.T) { + server := httptest.NewServer(endpoint{"my.site"}) + defer server.Close() + + client := http.DefaultClient + r, err := client.PostForm(server.URL, url.Values{ + "source": []string{"https||:example.org/somewhere"}, + "target": []string{"my.site/target"}, + }) + if err != nil { + t.Fatal(err) + } + if r.StatusCode != 400 { + t.Fatalf("want 400, got %v", r.Status) + } + bb, _ := io.ReadAll(r.Body) + if string(bb) != errSrcInvalid { + t.Fatalf("want %s, got %s", errSrcInvalid, string(bb)) + } +} |