-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_handler_test.go
More file actions
48 lines (40 loc) · 1.25 KB
/
status_handler_test.go
File metadata and controls
48 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
"time"
)
func TestStatusHandlerReturnsJSON(t *testing.T) {
cluster := NewCluster(ClusterOpts{
ID: "status-node",
DataDir: filepath.Join(t.TempDir(), "data"),
HTTPDataPort: 4321,
DiscoveryPort: 55002,
})
defer cluster.Stop()
if _, err := cluster.FileSystem.InsertFileIntoCluster(context.TODO(), "/test.txt", []byte("hello"), "text/plain", time.Now()); err != nil {
t.Fatalf("store file failed: %v", err)
}
req := httptest.NewRequest(http.MethodGet, "/status", nil)
rr := httptest.NewRecorder()
cluster.handleStatus(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d", rr.Code)
}
var body map[string]interface{}
if err := json.Unmarshal(rr.Body.Bytes(), &body); err != nil {
t.Fatalf("failed to parse status json: %v", err)
}
t.Logf("status response: %s", rr.Body.Bytes())
partitionStats, ok := body["partition_stats"].(map[string]interface{})
if !ok {
t.Fatalf("missing partition_stats in response: %v", body)
}
if totalFiles, ok := partitionStats["total_files"].(float64); !ok || totalFiles < 1 {
t.Fatalf("expected total_files >= 1, got %v", partitionStats["total_files"])
}
}