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

Function TestSendRequest

internal/api/submit/client_test.go:20–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18const mirror = "https://geo.mirror.pkgbuild.com/"
19
20func TestSendRequest(t *testing.T) {
21 server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
22 if req.URL.String() != "/api/submit" {
23 t.Error("/api/submit was not called")
24 }
25
26 validateRequest(t, req)
27
28 rw.WriteHeader(http.StatusNoContent)
29 }))
30 defer server.Close()
31
32 client := submit.Client{Client: server.Client(), BaseURL: server.URL}
33 request := &submit.Request{
34 Version: submit.Version,
35 System: submit.System{Architecture: system.X86_64},
36 OS: submit.OS{Architecture: system.I686, Id: runtime.GOOS},
37 Pacman: submit.Pacman{Packages: []string{"pacman", "linux"}, Mirror: mirror},
38 }
39 err := client.SendRequest(*request)
40 if err != nil {
41 t.Error(err)
42 }
43}
44
45func validateRequest(t *testing.T, req *http.Request) {
46 if req.Method != http.MethodPost {

Callers

nothing calls this directly

Calls 2

SendRequestMethod · 0.95
validateRequestFunction · 0.85

Tested by

no test coverage detected