Skip to content

Commit 440952a

Browse files
authored
Merge pull request #124 from StackVista/stac-23271
STAC-23271 Remove dashboard feature flag
2 parents a2f4e10 + 4783552 commit 440952a

File tree

4 files changed

+32
-149
lines changed

4 files changed

+32
-149
lines changed

cmd/dashboard/dashboard_describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func RunDashboardDescribeCommand(args *DescribeArgs) di.CmdWithApiFn {
4848
return common.NewResponseError(err, resp)
4949
}
5050

51-
yamlData, err := yaml.Marshal(dashboard)
51+
yamlData, err := yaml.Marshal(dashboard.DashboardReadFullSchema)
5252
if err != nil {
5353
return common.NewExecutionError(fmt.Errorf("failed to marshal dashboard: %v", err))
5454
}

cmd/dashboard/dashboard_edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func RunDashboardEditCommand(args *EditArgs) di.CmdWithApiFn {
6161
}
6262

6363
// Convert dashboard to pretty JSON for editing
64-
originalYAML, err := yaml.Marshal(dashboard)
64+
originalYAML, err := yaml.Marshal(dashboard.DashboardReadFullSchema)
6565
if err != nil {
6666
return common.NewExecutionError(fmt.Errorf("failed to marshal dashboard to YAML: %v", err))
6767
}

cmd/sts.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ func STSCommand(cli *di.Deps) *cobra.Command {
3232
cmd.AddCommand(TopologySyncCommand(cli))
3333
cmd.AddCommand(AgentCommand(cli))
3434
cmd.AddCommand(UserSessionCommand(cli))
35+
cmd.AddCommand(DashboardCommand(cli))
3536

3637
// Experimental commands for otel mapping
3738
if os.Getenv("STS_EXPERIMENTAL_OTEL_MAPPING") != "" {
3839
cmd.AddCommand(OtelComponentMappingCommand(cli))
3940
cmd.AddCommand(OtelRelationtMappingCommand(cli))
4041
}
4142

42-
// Only add dashboard command if experimental feature is enabled
43-
if os.Getenv("STS_EXPERIMENTAL_DASHBOARD") != "" {
44-
cmd.AddCommand(DashboardCommand(cli))
45-
}
46-
4743
return cmd
4844
}

cmd/sts_test.go

Lines changed: 29 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,12 @@
11
package cmd
22

33
import (
4-
"os"
54
"testing"
65

7-
"github.com/spf13/cobra"
86
"github.com/stackvista/stackstate-cli/internal/di"
97
"github.com/stretchr/testify/assert"
108
)
119

12-
const dashboardCommand = "dashboard"
13-
14-
// Helper function to manage STS_EXPERIMENTAL_DASHBOARD environment variable
15-
func withDashboardEnv(value string, fn func()) {
16-
originalValue := os.Getenv("STS_EXPERIMENTAL_DASHBOARD")
17-
defer func() {
18-
if originalValue == "" {
19-
_ = os.Unsetenv("STS_EXPERIMENTAL_DASHBOARD")
20-
} else {
21-
_ = os.Setenv("STS_EXPERIMENTAL_DASHBOARD", originalValue)
22-
}
23-
}()
24-
25-
if value == "" {
26-
_ = os.Unsetenv("STS_EXPERIMENTAL_DASHBOARD")
27-
} else {
28-
_ = os.Setenv("STS_EXPERIMENTAL_DASHBOARD", value)
29-
}
30-
31-
fn()
32-
}
33-
3410
func TestSTSCommand(t *testing.T) {
3511
cli := di.NewMockDeps(t)
3612
cmd := STSCommand(&cli.Deps)
@@ -42,135 +18,46 @@ func TestSTSCommand(t *testing.T) {
4218
}
4319

4420
func TestSTSCommandContainsExpectedSubcommands(t *testing.T) {
45-
withDashboardEnv("", func() {
46-
cli := di.NewMockDeps(t)
47-
cmd := STSCommand(&cli.Deps)
48-
49-
expectedCommands := []string{
50-
"context",
51-
"version",
52-
"script",
53-
"settings",
54-
"stackpack",
55-
"monitor",
56-
"service-token",
57-
"health",
58-
"license",
59-
"graph",
60-
"rbac",
61-
"topic",
62-
"topology-sync",
63-
"agent",
64-
"user-session",
65-
}
21+
cli := di.NewMockDeps(t)
22+
cmd := STSCommand(&cli.Deps)
6623

67-
// Verify expected commands are present
68-
for _, expectedCmd := range expectedCommands {
69-
found := false
70-
for _, subCmd := range cmd.Commands() {
71-
if subCmd.Use == expectedCmd {
72-
found = true
73-
break
74-
}
75-
}
76-
assert.True(t, found, "Expected command '%s' not found", expectedCmd)
77-
}
24+
expectedCommands := []string{
25+
"context",
26+
"version",
27+
"script",
28+
"settings",
29+
"stackpack",
30+
"monitor",
31+
"service-token",
32+
"health",
33+
"license",
34+
"graph",
35+
"rbac",
36+
"topic",
37+
"topology-sync",
38+
"agent",
39+
"user-session",
40+
"dashboard",
41+
}
7842

79-
// Verify dashboard command is NOT present when env var is not set
80-
dashboardFound := false
43+
// Verify expected commands are present
44+
for _, expectedCmd := range expectedCommands {
45+
found := false
8146
for _, subCmd := range cmd.Commands() {
82-
if subCmd.Use == dashboardCommand {
83-
dashboardFound = true
47+
if subCmd.Use == expectedCmd {
48+
found = true
8449
break
8550
}
8651
}
87-
assert.False(t, dashboardFound, "Dashboard command should not be present when STS_EXPERIMENTAL_DASHBOARD is not set")
88-
})
89-
}
90-
91-
func TestSTSCommandDashboardExperimentalFeature(t *testing.T) {
92-
tests := []struct {
93-
name string
94-
envVarValue string
95-
shouldIncludeDashboard bool
96-
}{
97-
{
98-
name: "Dashboard command not included when env var is empty",
99-
envVarValue: "",
100-
shouldIncludeDashboard: false,
101-
},
102-
{
103-
name: "Dashboard command included when env var is set to 'true'",
104-
envVarValue: "true",
105-
shouldIncludeDashboard: true,
106-
},
107-
{
108-
name: "Dashboard command included when env var is set to any non-empty value",
109-
envVarValue: "any-value",
110-
shouldIncludeDashboard: true,
111-
},
112-
}
113-
114-
for _, tt := range tests {
115-
t.Run(tt.name, func(t *testing.T) {
116-
withDashboardEnv(tt.envVarValue, func() {
117-
cli := di.NewMockDeps(t)
118-
cmd := STSCommand(&cli.Deps)
119-
120-
// Check if dashboard command is present
121-
dashboardFound := false
122-
for _, subCmd := range cmd.Commands() {
123-
if subCmd.Use == dashboardCommand {
124-
dashboardFound = true
125-
break
126-
}
127-
}
128-
129-
if tt.shouldIncludeDashboard {
130-
assert.True(t, dashboardFound, "Dashboard command should be present when STS_EXPERIMENTAL_DASHBOARD='%s'", tt.envVarValue)
131-
} else {
132-
assert.False(t, dashboardFound, "Dashboard command should not be present when STS_EXPERIMENTAL_DASHBOARD='%s'", tt.envVarValue)
133-
}
134-
})
135-
})
52+
assert.True(t, found, "Expected command '%s' not found", expectedCmd)
13653
}
13754
}
13855

13956
func TestSTSCommandStructure(t *testing.T) {
140-
withDashboardEnv("1", func() {
141-
cli := di.NewMockDeps(t)
142-
cmd := STSCommand(&cli.Deps)
143-
144-
// Verify the command has the expected number of subcommands (15 regular + 1 dashboard)
145-
assert.Len(t, cmd.Commands(), 16, "Expected 16 subcommands when dashboard is enabled")
146-
147-
// Verify that dashboard command is included and properly configured
148-
var dashboardCmd *cobra.Command
149-
for _, subCmd := range cmd.Commands() {
150-
if subCmd.Use == dashboardCommand {
151-
dashboardCmd = subCmd
152-
break
153-
}
154-
}
155-
assert.NotNil(t, dashboardCmd, "Dashboard command should be present")
156-
assert.Equal(t, dashboardCommand, dashboardCmd.Use)
157-
assert.NotEmpty(t, dashboardCmd.Short)
158-
})
159-
}
160-
161-
func TestSTSCommandWithoutDashboard(t *testing.T) {
162-
withDashboardEnv("", func() {
163-
cli := di.NewMockDeps(t)
164-
cmd := STSCommand(&cli.Deps)
165-
166-
// Verify the command has the expected number of subcommands (15 regular, no dashboard)
167-
assert.Len(t, cmd.Commands(), 15, "Expected 15 subcommands when dashboard is disabled")
57+
cli := di.NewMockDeps(t)
58+
cmd := STSCommand(&cli.Deps)
16859

169-
// Double-check that no command has "dashboard" as its Use field
170-
for _, subCmd := range cmd.Commands() {
171-
assert.NotEqual(t, dashboardCommand, subCmd.Use, "Dashboard command should not be present")
172-
}
173-
})
60+
assert.Len(t, cmd.Commands(), 16, "Expected 16 subcommands")
17461
}
17562

17663
func TestSTSCommandUsageTemplate(t *testing.T) {

0 commit comments

Comments
 (0)