From f4ed08916ef727b5caafd207ba4ef9f406a7d86e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Apr 2026 10:17:55 +0300 Subject: docs,test: HTTP upload API and curl auth example (ask 23) Document daemon plain-HTTP mode, PUT /upload paths for five uptimed files, Bearer token header, and env flags. Add table-driven test asserting each kind maps to the expected filename in stats-dir. Made-with: Cursor --- internal/daemon/daemon_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'internal') diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index d4133f2..404ff45 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -317,3 +317,41 @@ func TestUploadBadKind(t *testing.T) { t.Fatalf("status %d", res.StatusCode) } } + +func TestUploadAllKindsWriteExpectedFiles(t *testing.T) { + statsDir := t.TempDir() + srv := httptest.NewServer(Handler(statsDir)) + defer srv.Close() + cases := []struct { + kind string + wantName string + body string + }{ + {"txt", "myhost.txt", "a"}, + {"cur.txt", "myhost.cur.txt", "b"}, + {"records", "myhost.records", "c"}, + {"os.txt", "myhost.os.txt", "d"}, + {"cpuinfo.txt", "myhost.cpuinfo.txt", "e"}, + } + for _, tc := range cases { + t.Run(tc.kind, func(t *testing.T) { + url := srv.URL + "/upload/myhost/" + tc.kind + req, _ := http.NewRequest(http.MethodPut, url, strings.NewReader(tc.body)) + res, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatal(err) + } + res.Body.Close() + if res.StatusCode != http.StatusNoContent { + t.Fatalf("status %d", res.StatusCode) + } + b, err := os.ReadFile(filepath.Join(statsDir, tc.wantName)) + if err != nil { + t.Fatal(err) + } + if string(b) != tc.body { + t.Fatalf("file %s: got %q want %q", tc.wantName, b, tc.body) + } + }) + } +} -- cgit v1.2.3