diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 10:17:55 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 10:17:55 +0300 |
| commit | f4ed08916ef727b5caafd207ba4ef9f406a7d86e (patch) | |
| tree | 7d21132a3215e83946308a365f3e8015e34b569a /internal | |
| parent | 7374be02a89cad4d0df4460a98b42764d191ad92 (diff) | |
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
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/daemon/daemon_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
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) + } + }) + } +} |
