package router

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestBypassNonGitBodyLimitOnlyAllowsReleaseAssetUploads(t *testing.T) {
	tests := []struct {
		name   string
		method string
		path   string
		want   bool
	}{
		{name: "git receive", method: http.MethodPost, path: "/org/repo.git/git-receive-pack", want: true},
		{name: "release asset", method: http.MethodPut, path: "/api/ext/v1/imports/42/release-assets/900", want: true},
		{name: "batch upload remains capped", method: http.MethodPost, path: "/api/ext/v1/imports/42/batches", want: false},
		{name: "wrong method remains capped", method: http.MethodPost, path: "/api/ext/v1/imports/42/release-assets/900", want: false},
		{name: "wrong prefix remains capped", method: http.MethodPut, path: "/api/v3/imports/42/release-assets/900", want: false},
		{name: "extra path segment remains capped", method: http.MethodPut, path: "/api/ext/v1/imports/42/release-assets/900/extra", want: false},
		{name: "invalid import id remains capped", method: http.MethodPut, path: "/api/ext/v1/imports/not-a-number/release-assets/900", want: false},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			req := httptest.NewRequest(test.method, test.path, nil)
			if got := bypassNonGitBodyLimit(req); got != test.want {
				t.Fatalf("bypassNonGitBodyLimit(%s %s) = %t, want %t", test.method, test.path, got, test.want)
			}
		})
	}
}
