aboutsummaryrefslogtreecommitdiff
path: root/handler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'handler_test.go')
-rw-r--r--handler_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/handler_test.go b/handler_test.go
index e300d19..b1d5d2e 100644
--- a/handler_test.go
+++ b/handler_test.go
@@ -1,9 +1,14 @@
package main
import (
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "strings"
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
var config = `
@@ -120,3 +125,44 @@ func TestPackageLevelURL(t *testing.T) {
</html>
`)
}
+
+func TestPostRejected(t *testing.T) {
+ t.Parallel()
+
+ h := CreateHandler(&Config{
+ URL: "go.uberalt.org",
+ Packages: map[string]Package{
+ "zap": {
+ Repo: "github.com/uber-go/zap",
+ },
+ },
+ })
+ srv := httptest.NewServer(h)
+ t.Cleanup(srv.Close)
+
+ tests := []struct {
+ desc string
+ path string
+ }{
+ {desc: "index", path: "/"},
+ {desc: "package", path: "/zap"},
+ {desc: "subpackage", path: "/zap/zapcore"},
+ }
+
+ for _, tt := range tests {
+ tt := tt
+ t.Run(tt.desc, func(t *testing.T) {
+ t.Parallel()
+
+ res, err := http.Post(srv.URL+tt.path, "text/plain", strings.NewReader("foo"))
+ require.NoError(t, err)
+ defer res.Body.Close()
+
+ body, err := io.ReadAll(res.Body)
+ require.NoError(t, err)
+
+ assert.Equal(t, http.StatusNotFound, res.StatusCode,
+ "expected 404, got:\n%s", string(body))
+ })
+ }
+}