Skip to content

Commit d3388af

Browse files
STAC-22985: Address review comments
1 parent 18b67e8 commit d3388af

File tree

9 files changed

+66
-47
lines changed

9 files changed

+66
-47
lines changed

cmd/cmd_rules_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,27 @@ func TestNounsAndVerbsExistAsFilesInDirectories(t *testing.T) {
3434
}
3535

3636
func TestVerbCommandCheckForJsonOuput(t *testing.T) {
37+
var jsonCheckAllowList = map[string]struct{}{
38+
"otelcomponentmapping/otelcomponentmapping_status.go": {},
39+
"otelrelationmapping/otelrelationmapping_status.go": {},
40+
}
41+
3742
root := setupCmd(t)
3843
for _, nounCmd := range root.Commands() {
3944
for _, verbCmd := range nounCmd.Commands() {
4045
nounName := strings.ReplaceAll(nounCmd.Name(), "-", "")
4146
verbName := strings.ReplaceAll(verbCmd.Name(), "-", "_")
4247
verCmdGoFile := fmt.Sprintf("%s/%s_%s.go", nounName, nounName, verbName)
48+
49+
if _, ok := jsonCheckAllowList[verCmdGoFile]; ok {
50+
continue
51+
}
52+
4353
verbCmdGoCode, err := os.ReadFile(verCmdGoFile)
4454
if err != nil {
4555
t.Fatal(err)
4656
}
57+
4758
if !strings.Contains(string(verbCmdGoCode), "if cli.IsJson() {") {
4859
t.Errorf("%s does not check whether to print to json!", verCmdGoFile)
4960
}

cmd/otelcomponentmapping/otelcomponentmapping_list_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
package otelcomponentmapping
1+
package otelcomponentmapping_test
22

33
import (
44
"testing"
55

6-
"github.com/stackvista/stackstate-cli/cmd/otelmapping"
6+
"github.com/stackvista/stackstate-cli/cmd/otelcomponentmapping"
7+
"github.com/stackvista/stackstate-cli/cmd/otelmapping_test"
78
"github.com/stackvista/stackstate-cli/internal/di"
89
"github.com/stackvista/stackstate-cli/internal/printer"
910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestListOtelComponentMappingsJson(t *testing.T) {
1314
cli := di.NewMockDeps(t)
14-
cmd := OtelComponentMappingListCommand(&cli.Deps)
15-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingsResponse.Result = otelmapping.TestAllMappingItems
15+
cmd := otelcomponentmapping.OtelComponentMappingListCommand(&cli.Deps)
16+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingsResponse.Result = otelmapping_test.TestAllMappingItems
1617

1718
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "-o", "json")
1819

@@ -21,7 +22,7 @@ func TestListOtelComponentMappingsJson(t *testing.T) {
2122

2223
expected := []map[string]interface{}{
2324
{
24-
"otel component mappings": otelmapping.TestAllMappingItems,
25+
"otel component mappings": otelmapping_test.TestAllMappingItems,
2526
},
2627
}
2728

@@ -30,8 +31,8 @@ func TestListOtelComponentMappingsJson(t *testing.T) {
3031

3132
func TestOtelComponentMappingListTable(t *testing.T) {
3233
cli := di.NewMockDeps(t)
33-
cmd := OtelComponentMappingListCommand(&cli.Deps)
34-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingsResponse.Result = otelmapping.TestAllMappingItems
34+
cmd := otelcomponentmapping.OtelComponentMappingListCommand(&cli.Deps)
35+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingsResponse.Result = otelmapping_test.TestAllMappingItems
3536

3637
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd)
3738

@@ -42,8 +43,8 @@ func TestOtelComponentMappingListTable(t *testing.T) {
4243
{
4344
Header: []string{"Name", "Identifier"},
4445
Data: [][]interface{}{
45-
{otelmapping.TestSomeOtelMappingItem.Name, "identifier"},
46-
{otelmapping.TestSomeOtelMappingItem2.Name, "identifier2"},
46+
{otelmapping_test.TestSomeOtelMappingItem.Name, "identifier"},
47+
{otelmapping_test.TestSomeOtelMappingItem2.Name, "identifier2"},
4748
},
4849
MissingTableDataMsg: printer.NotFoundMsg{Types: "otel mappings"},
4950
},

cmd/otelcomponentmapping/otelcomponentmapping_status.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"github.com/stackvista/stackstate-cli/internal/di"
88
)
99

10-
// if cli.IsJson() {
11-
// cli.Printer.PrintJson(
12-
1310
func OtelComponentMappingStatusCommand(deps *di.Deps) *cobra.Command {
1411
args := &otelmapping.StatusArgs{}
1512
cmd := &cobra.Command{

cmd/otelcomponentmapping/otelcomponentmapping_status_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
package otelcomponentmapping
1+
package otelcomponentmapping_test
22

33
import (
44
"testing"
55

6-
"github.com/stackvista/stackstate-cli/cmd/otelmapping"
6+
"github.com/stackvista/stackstate-cli/cmd/otelcomponentmapping"
7+
"github.com/stackvista/stackstate-cli/cmd/otelmapping_test"
78
"github.com/stackvista/stackstate-cli/internal/di"
89
"github.com/stackvista/stackstate-cli/internal/printer"
910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestOtelComponentMappingStatusJson(t *testing.T) {
1314
cli := di.NewMockDeps(t)
14-
cmd := OtelComponentMappingStatusCommand(&cli.Deps)
15-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingStatusResponse.Result = *otelmapping.TestSomeOtelMappingStatus
15+
cmd := otelcomponentmapping.OtelComponentMappingStatusCommand(&cli.Deps)
16+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingStatusResponse.Result = *otelmapping_test.TestSomeOtelMappingStatus
1617

1718
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--identifier", "identifier", "-o", "json")
1819

@@ -21,7 +22,7 @@ func TestOtelComponentMappingStatusJson(t *testing.T) {
2122

2223
expected := []map[string]interface{}{
2324
{
24-
"otel-component-mapping": otelmapping.TestSomeOtelMappingStatus,
25+
"otel-component-mapping": otelmapping_test.TestSomeOtelMappingStatus,
2526
},
2627
}
2728

@@ -30,8 +31,8 @@ func TestOtelComponentMappingStatusJson(t *testing.T) {
3031

3132
func TestOtelComponentMappingStatusTable(t *testing.T) {
3233
cli := di.NewMockDeps(t)
33-
cmd := OtelComponentMappingStatusCommand(&cli.Deps)
34-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingStatusResponse.Result = *otelmapping.TestSomeOtelMappingStatus
34+
cmd := otelcomponentmapping.OtelComponentMappingStatusCommand(&cli.Deps)
35+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelComponentMappingStatusResponse.Result = *otelmapping_test.TestSomeOtelMappingStatus
3536

3637
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--identifier", "identifier")
3738

@@ -42,22 +43,22 @@ func TestOtelComponentMappingStatusTable(t *testing.T) {
4243
{
4344
Header: []string{"Name", "Identifier", "Components", "Relations"},
4445
Data: [][]interface{}{
45-
{otelmapping.TestSomeOtelMappingStatusItem.Name, "identifier", otelmapping.TestComponentCount, otelmapping.TestRelationCount},
46+
{otelmapping_test.TestSomeOtelMappingStatusItem.Name, "identifier", otelmapping_test.TestComponentCount, otelmapping_test.TestRelationCount},
4647
},
4748
MissingTableDataMsg: printer.NotFoundMsg{Types: "otel mappings"},
4849
},
4950
{
5051
Header: []string{"Metric", "10s ago", "10-20s ago", "20-30s ago"},
5152
Data: [][]interface{}{
52-
{"latency seconds", otelmapping.TestMetricValue, otelmapping.TestMetricValue, otelmapping.TestMetricValue},
53+
{"latency seconds", otelmapping_test.TestMetricValue, otelmapping_test.TestMetricValue, otelmapping_test.TestMetricValue},
5354
},
5455
MissingTableDataMsg: printer.NotFoundMsg{Types: "metrics"},
5556
},
5657
{
5758
Header: []string{"Issue Id", "Level", "Message"},
5859
Data: [][]interface{}{
59-
{"-", otelmapping.TestError1.Level, otelmapping.TestError1.Message},
60-
{"-", otelmapping.TestError2.Level, otelmapping.TestError2.Message},
60+
{"-", otelmapping_test.TestError1.Level, otelmapping_test.TestError1.Message},
61+
{"-", otelmapping_test.TestError2.Level, otelmapping_test.TestError2.Message},
6162
},
6263
MissingTableDataMsg: printer.NotFoundMsg{Types: "otel component mapping errors"},
6364
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package otelmapping
1+
package otelmapping_test
22

33
import (
44
"github.com/stackvista/stackstate-cli/generated/stackstate_api"

cmd/otelrelationmapping/otelrelationmapping_list_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
package otelrelationmapping
1+
package otelrelationmapping_test
22

33
import (
44
"testing"
55

6-
"github.com/stackvista/stackstate-cli/cmd/otelmapping"
6+
"github.com/stackvista/stackstate-cli/cmd/otelmapping_test"
7+
"github.com/stackvista/stackstate-cli/cmd/otelrelationmapping"
78
"github.com/stackvista/stackstate-cli/internal/di"
89
"github.com/stackvista/stackstate-cli/internal/printer"
910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestOtelRelationMappingListJson(t *testing.T) {
1314
cli := di.NewMockDeps(t)
14-
cmd := OtelRelationMappingListCommand(&cli.Deps)
15-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingsResponse.Result = otelmapping.TestAllMappingItems
15+
cmd := otelrelationmapping.OtelRelationMappingListCommand(&cli.Deps)
16+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingsResponse.Result = otelmapping_test.TestAllMappingItems
1617

1718
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "-o", "json")
1819

@@ -21,7 +22,7 @@ func TestOtelRelationMappingListJson(t *testing.T) {
2122

2223
expected := []map[string]interface{}{
2324
{
24-
"otel relation mappings": otelmapping.TestAllMappingItems,
25+
"otel relation mappings": otelmapping_test.TestAllMappingItems,
2526
},
2627
}
2728

@@ -30,8 +31,8 @@ func TestOtelRelationMappingListJson(t *testing.T) {
3031

3132
func TestOtelRelationMappingListTable(t *testing.T) {
3233
cli := di.NewMockDeps(t)
33-
cmd := OtelRelationMappingListCommand(&cli.Deps)
34-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingsResponse.Result = otelmapping.TestAllMappingItems
34+
cmd := otelrelationmapping.OtelRelationMappingListCommand(&cli.Deps)
35+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingsResponse.Result = otelmapping_test.TestAllMappingItems
3536

3637
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd)
3738

@@ -42,8 +43,8 @@ func TestOtelRelationMappingListTable(t *testing.T) {
4243
{
4344
Header: []string{"Name", "Identifier"},
4445
Data: [][]interface{}{
45-
{otelmapping.TestSomeOtelMappingItem.Name, "identifier"},
46-
{otelmapping.TestSomeOtelMappingItem2.Name, "identifier2"},
46+
{otelmapping_test.TestSomeOtelMappingItem.Name, "identifier"},
47+
{otelmapping_test.TestSomeOtelMappingItem2.Name, "identifier2"},
4748
},
4849
MissingTableDataMsg: printer.NotFoundMsg{Types: "otel mappings"},
4950
},

cmd/otelrelationmapping/otelrelationmapping_status.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"github.com/stackvista/stackstate-cli/internal/di"
88
)
99

10-
// if cli.IsJson() {
11-
// cli.Printer.PrintJson(
12-
1310
func OtelRelationMappingStatusCommand(deps *di.Deps) *cobra.Command {
1411
args := &otelmapping.StatusArgs{}
1512
cmd := &cobra.Command{

cmd/otelrelationmapping/otelrelationmapping_status_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
package otelrelationmapping
1+
package otelrelationmapping_test
22

33
import (
44
"testing"
55

6-
"github.com/stackvista/stackstate-cli/cmd/otelmapping"
6+
"github.com/stackvista/stackstate-cli/cmd/otelmapping_test"
7+
"github.com/stackvista/stackstate-cli/cmd/otelrelationmapping"
78
"github.com/stackvista/stackstate-cli/internal/di"
89
"github.com/stackvista/stackstate-cli/internal/printer"
910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestOtelRelationMappingStatusJson(t *testing.T) {
1314
cli := di.NewMockDeps(t)
14-
cmd := OtelRelationMappingStatusCommand(&cli.Deps)
15-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingStatusResponse.Result = *otelmapping.TestSomeOtelMappingStatus
15+
cmd := otelrelationmapping.OtelRelationMappingStatusCommand(&cli.Deps)
16+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingStatusResponse.Result = *otelmapping_test.TestSomeOtelMappingStatus
1617

1718
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--identifier", "identifier", "-o", "json")
1819

@@ -21,7 +22,7 @@ func TestOtelRelationMappingStatusJson(t *testing.T) {
2122

2223
expected := []map[string]interface{}{
2324
{
24-
"otel-relation-mapping": otelmapping.TestSomeOtelMappingStatus,
25+
"otel-relation-mapping": otelmapping_test.TestSomeOtelMappingStatus,
2526
},
2627
}
2728

@@ -30,8 +31,8 @@ func TestOtelRelationMappingStatusJson(t *testing.T) {
3031

3132
func TestOtelRelationMappingStatusTable(t *testing.T) {
3233
cli := di.NewMockDeps(t)
33-
cmd := OtelRelationMappingStatusCommand(&cli.Deps)
34-
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingStatusResponse.Result = *otelmapping.TestSomeOtelMappingStatus
34+
cmd := otelrelationmapping.OtelRelationMappingStatusCommand(&cli.Deps)
35+
cli.MockClient.ApiMocks.OtelMappingApi.GetOtelRelationMappingStatusResponse.Result = *otelmapping_test.TestSomeOtelMappingStatus
3536

3637
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "--identifier", "identifier")
3738

@@ -42,22 +43,22 @@ func TestOtelRelationMappingStatusTable(t *testing.T) {
4243
{
4344
Header: []string{"Name", "Identifier", "Components", "Relations"},
4445
Data: [][]interface{}{
45-
{otelmapping.TestSomeOtelMappingStatusItem.Name, "identifier", otelmapping.TestComponentCount, otelmapping.TestRelationCount},
46+
{otelmapping_test.TestSomeOtelMappingStatusItem.Name, "identifier", otelmapping_test.TestComponentCount, otelmapping_test.TestRelationCount},
4647
},
4748
MissingTableDataMsg: printer.NotFoundMsg{Types: "otel mappings"},
4849
},
4950
{
5051
Header: []string{"Metric", "10s ago", "10-20s ago", "20-30s ago"},
5152
Data: [][]interface{}{
52-
{"latency seconds", otelmapping.TestMetricValue, otelmapping.TestMetricValue, otelmapping.TestMetricValue},
53+
{"latency seconds", otelmapping_test.TestMetricValue, otelmapping_test.TestMetricValue, otelmapping_test.TestMetricValue},
5354
},
5455
MissingTableDataMsg: printer.NotFoundMsg{Types: "metrics"},
5556
},
5657
{
5758
Header: []string{"Issue Id", "Level", "Message"},
5859
Data: [][]interface{}{
59-
{"-", otelmapping.TestError1.Level, otelmapping.TestError1.Message},
60-
{"-", otelmapping.TestError2.Level, otelmapping.TestError2.Message},
60+
{"-", otelmapping_test.TestError1.Level, otelmapping_test.TestError1.Message},
61+
{"-", otelmapping_test.TestError2.Level, otelmapping_test.TestError2.Message},
6162
},
6263
MissingTableDataMsg: printer.NotFoundMsg{Types: "otel relation mapping errors"},
6364
},

stackstate-cli.iml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="WEB_MODULE" version="4">
3+
<component name="Go" enabled="true" />
4+
<component name="NewModuleRootManager" inherit-compiler-output="true">
5+
<exclude-output />
6+
<content url="file://$MODULE_DIR$" />
7+
<orderEntry type="inheritedJdk" />
8+
<orderEntry type="sourceFolder" forTests="false" />
9+
</component>
10+
</module>

0 commit comments

Comments
 (0)