diff --git a/internal/healthcheck/client.go b/internal/healthcheck/client.go index ebd573f0..d3f1e7ea 100644 --- a/internal/healthcheck/client.go +++ b/internal/healthcheck/client.go @@ -24,7 +24,7 @@ func NewClient(client *http.Client) *Client { // DiskUsage returns disk usage statistics or an error if unable to obtain. // Do not include the port in the host. -func (c Client) DiskUsage(ctx context.Context, host string) (DiskUsageResponse, error) { +func (c Client) DiskUsage(ctx context.Context, host, homeDir string) (DiskUsageResponse, error) { var diskResp DiskUsageResponse u, err := url.Parse(host) if err != nil { @@ -37,6 +37,11 @@ func (c Client) DiskUsage(ctx context.Context, host string) (DiskUsageResponse, if err != nil { return diskResp, fmt.Errorf("new request: %w", err) } + + q := req.URL.Query() + q.Set("dir", homeDir) + req.URL.RawQuery = q.Encode() + resp, err := c.httpDo(req) if err != nil { return diskResp, fmt.Errorf("http do: %w", err) diff --git a/internal/healthcheck/client_test.go b/internal/healthcheck/client_test.go index 03e19e3b..3d5c237d 100644 --- a/internal/healthcheck/client_test.go +++ b/internal/healthcheck/client_test.go @@ -19,7 +19,10 @@ func TestClient_DiskUsage(t *testing.T) { httpClient = &http.Client{} ) - const host = "http://10.1.1.1" + const ( + host = "http://10.1.1.1" + homeDir = "/home/test" + ) t.Run("happy path", func(t *testing.T) { client := NewClient(httpClient) @@ -32,8 +35,9 @@ func TestClient_DiskUsage(t *testing.T) { } client.httpDo = func(req *http.Request) (*http.Response, error) { - require.Equal(t, "http://10.1.1.1:1251/disk", req.URL.String()) + require.Equal(t, "http://10.1.1.1:1251/disk?dir=%2Fhome%2Ftest", req.URL.String()) require.Equal(t, "GET", req.Method) + require.Equal(t, homeDir, req.URL.Query().Get("dir")) b, err := json.Marshal(want) if err != nil { @@ -42,7 +46,7 @@ func TestClient_DiskUsage(t *testing.T) { return &http.Response{Body: io.NopCloser(bytes.NewReader(b))}, nil } - got, err := client.DiskUsage(ctx, host) + got, err := client.DiskUsage(ctx, host, homeDir) require.NoError(t, err) require.Equal(t, want, got) @@ -53,7 +57,7 @@ func TestClient_DiskUsage(t *testing.T) { client.httpDo = func(req *http.Request) (*http.Response, error) { return nil, errors.New("boom") } - _, err := client.DiskUsage(ctx, host) + _, err := client.DiskUsage(ctx, host, "") require.Error(t, err) require.EqualError(t, err, "http do: boom") @@ -73,7 +77,7 @@ func TestClient_DiskUsage(t *testing.T) { }, nil } - _, err := client.DiskUsage(ctx, host) + _, err := client.DiskUsage(ctx, host, "") require.Error(t, err) require.EqualError(t, err, "something bad happened") @@ -88,7 +92,7 @@ func TestClient_DiskUsage(t *testing.T) { }, nil } - _, err := client.DiskUsage(ctx, host) + _, err := client.DiskUsage(ctx, host, "") require.Error(t, err) require.EqualError(t, err, "malformed json: unexpected EOF") @@ -103,7 +107,7 @@ func TestClient_DiskUsage(t *testing.T) { }, nil } - _, err := client.DiskUsage(ctx, host) + _, err := client.DiskUsage(ctx, host, "") require.Error(t, err) require.EqualError(t, err, "invalid response: 0 free bytes")