Skip to content

Commit 9990292

Browse files
authored
CLOUDP-181546: slow query logs (#1985)
1 parent c42a774 commit 9990292

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

internal/cli/atlas/performanceadvisor/slowquerylogs/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
atlasv2 "go.mongodb.org/atlas-sdk/admin"
2929
)
3030

31-
const listTemplate = `NAMESPACE LINE{{range .SlowQuery}}
31+
const listTemplate = `NAMESPACE LINE{{range .SlowQueries}}
3232
{{.Namespace}} {{.Line}}{{end}}
3333
`
3434

internal/cli/atlas/performanceadvisor/slowquerylogs/list_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,48 @@
1717
package slowquerylogs
1818

1919
import (
20+
"bytes"
2021
"testing"
2122

2223
"github.com/golang/mock/gomock"
24+
"github.com/mongodb/mongodb-atlas-cli/internal/cli"
2325
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
2426
mocks "github.com/mongodb/mongodb-atlas-cli/internal/mocks/atlas"
2527
"github.com/mongodb/mongodb-atlas-cli/internal/test"
28+
"github.com/stretchr/testify/assert"
2629
atlasv2 "go.mongodb.org/atlas-sdk/admin"
2730
)
2831

2932
func TestSlowQueryLogsList_Run(t *testing.T) {
3033
ctrl := gomock.NewController(t)
3134
mockStore := mocks.NewMockPerformanceAdvisorSlowQueriesLister(ctrl)
32-
33-
var expected *atlasv2.PerformanceAdvisorSlowQueryList
35+
buf := new(bytes.Buffer)
36+
expected := atlasv2.PerformanceAdvisorSlowQueryList{
37+
SlowQueries: []atlasv2.PerformanceAdvisorSlowQuery{{
38+
Line: atlasv2.PtrString("test"),
39+
Namespace: atlasv2.PtrString("test"),
40+
},
41+
},
42+
}
3443

3544
listOpts := &ListOpts{
3645
store: mockStore,
46+
OutputOpts: cli.OutputOpts{
47+
Template: listTemplate,
48+
OutWriter: buf,
49+
},
3750
}
3851

3952
mockStore.
4053
EXPECT().
4154
PerformanceAdvisorSlowQueries(listOpts.newSlowQueryOptions(listOpts.ProjectID, listOpts.ProcessName)).
42-
Return(expected, nil).
55+
Return(&expected, nil).
4356
Times(1)
4457

4558
if err := listOpts.Run(); err != nil {
4659
t.Fatalf("Run() unexpected error: %v", err)
4760
}
61+
assert.Equal(t, "NAMESPACE LINE\ntest test\n", buf.String())
4862
}
4963

5064
func TestListBuilder(t *testing.T) {

0 commit comments

Comments
 (0)