Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCII-950] Add test for pkg/status/render #21106

Merged
merged 13 commits into from
Nov 30, 2023
5 changes: 4 additions & 1 deletion cmd/process-agent/subcommands/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func getAndWriteStatus(log log.Component, statusURL string, w io.Writer, options
option(&s)
}

body, err = json.Marshal(s)
status := map[string]interface{}{}
status["processAgentStatus"] = s
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to add the top-level key because the template for process agent change in a previous PR https://github.com/DataDog/datadog-agent/pull/20824/files#diff-5399c03d823d8e2533aa6fc4d1a1f523a999353a481c78c3f1a60cabecad1cbfR8

I'm planning on reusing the existing code of the pkg/status on follow-up PR to DRY the code 😄


body, err = json.Marshal(status)
if err != nil {
writeError(log, w, err)
return
Expand Down
8 changes: 5 additions & 3 deletions cmd/process-agent/subcommands/status/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func fakeStatusServer(t *testing.T, stats status.Status) *httptest.Server {

func TestStatus(t *testing.T) {
testTime := time.Now()
expectedStatus := status.Status{
statusData := map[string]status.Status{}
statusInfo := status.Status{
Date: float64(testTime.UnixNano()),
Core: status.CoreStatus{
Metadata: hostMetadataUtils.Payload{
Expand All @@ -51,12 +52,13 @@ func TestStatus(t *testing.T) {
},
Expvars: status.ProcessExpvars{},
}
statusData["processAgentStatus"] = statusInfo

server := fakeStatusServer(t, expectedStatus)
server := fakeStatusServer(t, statusInfo)
defer server.Close()

// Build what the expected status should be
j, err := json.Marshal(expectedStatus)
j, err := json.Marshal(statusData)
require.NoError(t, err)
expectedOutput, err := render.FormatProcessAgentStatus(j)
require.NoError(t, err)
Expand Down
515 changes: 515 additions & 0 deletions pkg/status/render/fixtures/agent_status.text

Large diffs are not rendered by default.

Loading