summaryrefslogblamecommitdiff
path: root/main_test.go
blob: d1b864d3864af1f80b024b104f50ba92120c82f9 (plain) (tree)





























                                                                      
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))
	}
}