MCPcopy Create free account
hub / github.com/archlinux-de/pkgstats-cli / validateRequest

Function validateRequest

internal/api/submit/client_test.go:45–84  ·  view source on GitHub ↗
(t *testing.T, req *http.Request)

Source from the content-addressed store, hash-verified

43}
44
45func validateRequest(t *testing.T, req *http.Request) {
46 if req.Method != http.MethodPost {
47 t.Error("Invalid Method", req.Method)
48 }
49 if req.Header.Get("Accept") != "application/json" {
50 t.Error("Invalid Accept Header", req.Header.Get("Accept"))
51 }
52 if req.UserAgent() != build.UserAgent {
53 t.Error("Invalid User-Agent", req.UserAgent())
54 }
55
56 request := submit.Request{}
57 body, err := io.ReadAll(req.Body)
58 if err != nil {
59 t.Errorf("Could not read request body %s", err)
60 }
61 err = json.Unmarshal(body, &request)
62 if err != nil {
63 t.Errorf("Could not decode JSON: %s", err)
64 }
65
66 if request.Version != submit.Version {
67 t.Error("Invalid version value")
68 }
69 if strings.Join(request.Pacman.Packages, ",") != "pacman,linux" {
70 t.Error("Invalid packages value")
71 }
72 if request.System.Architecture != system.X86_64 {
73 t.Error("Invalid cpuarch value")
74 }
75 if request.OS.Architecture != system.I686 {
76 t.Error("Invalid arch value")
77 }
78 if request.OS.Id != runtime.GOOS {
79 t.Error("Invalid id value")
80 }
81 if request.Pacman.Mirror != mirror {
82 t.Error("Invalid mirror value")
83 }
84}
85
86func TestSendRequestFollowsRedirect(t *testing.T) {
87 server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {

Callers 3

TestSendRequestFunction · 0.85

Calls 1

GetMethod · 0.80

Tested by

no test coverage detected