Skip to content

Commit ba2c89d

Browse files
committed
Fix lint findings exposed by the CI tools upgrade
Extract repeated output keys and test fixture strings without changing their values. Replace the reflect.Ptr alias with reflect.Pointer for the newer vet analyzer. Validated with golangci-lint 2.15.0, go test ./..., Zizmor, and an AST comparison preserving existing expressions and literal values.
1 parent 3dcb620 commit ba2c89d

104 files changed

Lines changed: 1133 additions & 830 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cmd/context/context_delete_test.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11+
const (
12+
testBar = "bar"
13+
nameFlagArg = "--name"
14+
)
15+
1116
func TestDeleteCurrentContext(t *testing.T) {
1217
cli := di.NewMockDeps(t)
1318
setupConfig(t, &cli)
1419
cmd := DeleteCommand(&cli.Deps)
1520

16-
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--name", "foo")
21+
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, nameFlagArg, "foo")
1722
assert.Errorf(t, err, "cannot delete the current context (foo)")
1823
}
1924

@@ -22,7 +27,7 @@ func TestDeleteNonExistingContext(t *testing.T) {
2227
setupConfig(t, &cli)
2328
cmd := DeleteCommand(&cli.Deps)
2429

25-
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--name", "x")
30+
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, nameFlagArg, "x")
2631
assert.Errorf(t, err, "context with name 'x' not found")
2732
}
2833

@@ -31,7 +36,7 @@ func TestDeleteContext(t *testing.T) {
3136
setupConfig(t, &cli)
3237
cmd := DeleteCommand(&cli.Deps)
3338

34-
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--name", "bar")
39+
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, nameFlagArg, testBar)
3540
assert.NoError(t, err)
3641

3742
cfg, err := config.ReadConfig(cli.ConfigPath)

‎cmd/context/context_save.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
)
1313

1414
const (
15-
APIPathFlag = "api-path"
15+
currentContextKey = "current-context"
16+
APIPathFlag = "api-path"
1617
)
1718

1819
type SaveArgs struct {
@@ -112,7 +113,7 @@ func RunContextSaveCommand(args *SaveArgs) func(cli *di.Deps, cmd *cobra.Command
112113

113114
if cli.IsJson() {
114115
cli.Printer.PrintJson(map[string]interface{}{
115-
"current-context": cfg.CurrentContext,
116+
currentContextKey: cfg.CurrentContext,
116117
"context": namedCtx.Context,
117118
})
118119
} else {

‎cmd/context/context_save_test.go‎

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14+
const (
15+
testToken = "my-token"
16+
testContextURL = "http://bar.com"
17+
urlFlagArg = "--url"
18+
testCACertContext = "cacertdata"
19+
testAPIPath = "/api"
20+
serviceTokenFlagArg = "--service-token"
21+
caCertPathFlagArg = "--ca-cert-path"
22+
caCertBase64DataFlagArg = "--ca-cert-base64-data"
23+
)
24+
1425
func setupSaveCmd(t *testing.T) (*di.MockDeps, *cobra.Command) {
1526
cli := di.NewMockDeps(t)
1627
cmd := SaveCommand(&cli.Deps)
@@ -29,41 +40,41 @@ func TestSaveContext(t *testing.T) { //nolint:funlen
2940
}{
3041
{
3142
name: "new context",
32-
args: []string{"--name", "baz", "--url", "http://baz.com", "--api-token", "my-token"},
43+
args: []string{nameFlagArg, "baz", urlFlagArg, "http://baz.com", "--api-token", testToken},
3344
expectedContext: config.NamedContext{
3445
Name: "baz",
3546
Context: &config.StsContext{
3647
URL: "http://baz.com",
37-
APIToken: "my-token",
38-
APIPath: "/api",
48+
APIToken: testToken,
49+
APIPath: testAPIPath,
3950
},
4051
},
4152
totalContextInConfig: 7,
4253
wantErr: false,
4354
},
4455
{
4556
name: "existing context",
46-
args: []string{"--name", "bar", "--url", "http://bar.com", "--service-token", "my-token"},
57+
args: []string{nameFlagArg, testBar, urlFlagArg, testContextURL, serviceTokenFlagArg, testToken},
4758
expectedContext: config.NamedContext{
48-
Name: "bar",
59+
Name: testBar,
4960
Context: &config.StsContext{
50-
URL: "http://bar.com",
51-
ServiceToken: "my-token",
52-
APIPath: "/api",
61+
URL: testContextURL,
62+
ServiceToken: testToken,
63+
APIPath: testAPIPath,
5364
},
5465
},
5566
totalContextInConfig: 6,
5667
wantErr: false,
5768
},
5869
{
5970
name: "existing context ca-cert is set with ca-cert-path",
60-
args: []string{"--name", "bar", "--url", "http://bar.com", "--service-token", "my-token", "--ca-cert-path", "testdata/selfSignedCert.crt"},
71+
args: []string{nameFlagArg, testBar, urlFlagArg, testContextURL, serviceTokenFlagArg, testToken, caCertPathFlagArg, "testdata/selfSignedCert.crt"},
6172
expectedContext: config.NamedContext{
62-
Name: "bar",
73+
Name: testBar,
6374
Context: &config.StsContext{
64-
URL: "http://bar.com",
65-
ServiceToken: "my-token",
66-
APIPath: "/api",
75+
URL: testContextURL,
76+
ServiceToken: testToken,
77+
APIPath: testAPIPath,
6778
CaCertBase64Data: selfSignedBase64Cert,
6879
},
6980
},
@@ -72,13 +83,13 @@ func TestSaveContext(t *testing.T) { //nolint:funlen
7283
},
7384
{
7485
name: "new context ca-cert is set with ca-cert-path",
75-
args: []string{"--name", "cacertdata", "--url", "http://bar.com", "--service-token", "my-token", "--ca-cert-base64-data", privateCaBase64Cert},
86+
args: []string{nameFlagArg, testCACertContext, urlFlagArg, testContextURL, serviceTokenFlagArg, testToken, caCertBase64DataFlagArg, privateCaBase64Cert},
7687
expectedContext: config.NamedContext{
77-
Name: "cacertdata",
88+
Name: testCACertContext,
7889
Context: &config.StsContext{
79-
URL: "http://bar.com",
80-
ServiceToken: "my-token",
81-
APIPath: "/api",
90+
URL: testContextURL,
91+
ServiceToken: testToken,
92+
APIPath: testAPIPath,
8293
CaCertBase64Data: privateCaBase64Cert,
8394
},
8495
},
@@ -87,13 +98,13 @@ func TestSaveContext(t *testing.T) { //nolint:funlen
8798
},
8899
{
89100
name: "ca-cert-path takes precedence over ca-cert-base64-data",
90-
args: []string{"--name", "cacertdata", "--url", "http://bar.com", "--service-token", "my-token", "--ca-cert-path", "testdata/selfSignedCert.crt", "--ca-cert-base64-data", privateCaBase64Cert},
101+
args: []string{nameFlagArg, testCACertContext, urlFlagArg, testContextURL, serviceTokenFlagArg, testToken, caCertPathFlagArg, "testdata/selfSignedCert.crt", caCertBase64DataFlagArg, privateCaBase64Cert},
91102
expectedContext: config.NamedContext{
92-
Name: "cacertdata",
103+
Name: testCACertContext,
93104
Context: &config.StsContext{
94-
URL: "http://bar.com",
95-
ServiceToken: "my-token",
96-
APIPath: "/api",
105+
URL: testContextURL,
106+
ServiceToken: testToken,
107+
APIPath: testAPIPath,
97108
CaCertBase64Data: selfSignedBase64Cert,
98109
},
99110
},
@@ -102,13 +113,13 @@ func TestSaveContext(t *testing.T) { //nolint:funlen
102113
},
103114
{
104115
name: "ca-cert ignored if skip-ssl is set",
105-
args: []string{"--name", "bar", "--url", "http://bar.com", "--service-token", "my-token", "--skip-ssl", "--ca-cert-path", "/path/to/ca.crt", "--ca-cert-base64-data", "base64-data"},
116+
args: []string{nameFlagArg, testBar, urlFlagArg, testContextURL, serviceTokenFlagArg, testToken, "--skip-ssl", caCertPathFlagArg, "/path/to/ca.crt", caCertBase64DataFlagArg, "base64-data"},
106117
expectedContext: config.NamedContext{
107-
Name: "bar",
118+
Name: testBar,
108119
Context: &config.StsContext{
109-
URL: "http://bar.com",
110-
ServiceToken: "my-token",
111-
APIPath: "/api",
120+
URL: testContextURL,
121+
ServiceToken: testToken,
122+
APIPath: testAPIPath,
112123
SkipSSL: true,
113124
CaCertBase64Data: "",
114125
CaCertPath: "",
@@ -119,14 +130,14 @@ func TestSaveContext(t *testing.T) { //nolint:funlen
119130
},
120131
{
121132
name: "no save on missing tokens",
122-
args: []string{"--name", "bar", "--url", "http://my-bar.com"},
133+
args: []string{nameFlagArg, testBar, urlFlagArg, "http://my-bar.com"},
123134
expectedContext: config.NamedContext{},
124135
wantErr: true,
125136
errorMessage: "one of the required flags {api-token | service-token} not set",
126137
},
127138
{
128139
name: "ca-cert-path is not found",
129-
args: []string{"--name", "bar", "--url", "http://my-bar.com", "--service-token", "my-token", "--ca-cert-path", "/path/to/ca.crt"},
140+
args: []string{nameFlagArg, testBar, urlFlagArg, "http://my-bar.com", serviceTokenFlagArg, testToken, caCertPathFlagArg, "/path/to/ca.crt"},
130141
expectedContext: config.NamedContext{},
131142
wantErr: true,
132143
errorMessage: "no such file or directory",

‎cmd/context/context_set.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func RunContextSetCommand(args *SetArgs, cli *di.Deps) func(cli *di.Deps, cmd *c
4747

4848
if cli.IsJson() {
4949
cli.Printer.PrintJson(map[string]interface{}{
50-
"current-context": args.Name,
50+
currentContextKey: args.Name,
5151
})
5252
} else {
5353
cli.Printer.PrintLn(fmt.Sprintf("Current context set to %s", args.Name))

‎cmd/context/context_set_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ func TestSetContext(t *testing.T) {
1313
setupConfig(t, &cli)
1414
cmd := SetCommand(&cli.Deps)
1515

16-
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--name", "bar")
16+
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, nameFlagArg, testBar)
1717
assert.NoError(t, err)
1818

1919
cfg, err := config.ReadConfig(cli.ConfigPath)
2020
assert.NoError(t, err)
21-
assert.Equal(t, "bar", cfg.CurrentContext)
21+
assert.Equal(t, testBar, cfg.CurrentContext)
2222
}
2323

2424
func TestSetUnknownContext(t *testing.T) {
2525
cli := di.NewMockDeps(t)
2626
setupConfig(t, &cli)
2727
cmd := SetCommand(&cli.Deps)
2828

29-
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "--name", "x")
29+
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, nameFlagArg, "x")
3030
assert.Errorf(t, err, "context with name 'x' not found")
3131

3232
cfg, err := config.ReadConfig(cli.ConfigPath)

‎cmd/context/context_show.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func RunContextShowCommand(cli *di.Deps, cmd *cobra.Command, cfg *config.Config)
3131

3232
if cli.IsJson() {
3333
cli.Printer.PrintJson(map[string]interface{}{
34-
"current-context": ctx.Context,
34+
currentContextKey: ctx.Context,
3535
"name": cfg.CurrentContext,
3636
})
3737
} else {

‎cmd/context/context_show_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestShowContextJSON(t *testing.T) {
2424
assert.Equal(t, &config.StsContext{
2525
URL: "http://foo.com",
2626
APIToken: "apiToken",
27-
APIPath: "/api",
27+
APIPath: testAPIPath,
2828
}, calls[0]["current-context"])
2929
}
3030

‎cmd/context/context_validate_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestValidationToJson(t *testing.T) {
3232
di.ExecuteCommandWithContextUnsafe(
3333
&cli.Deps,
3434
cmd,
35-
"--url",
35+
urlFlagArg,
3636
"https://test.stackstate.io/",
3737
"--api-token",
3838
"blaat",

‎cmd/dashboard/common_test.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"github.com/stretchr/testify/assert"
77
)
88

9+
const (
10+
testDashboardURN = "urn:custom:dashboard:test"
11+
)
12+
913
func TestResolveDashboardIdOrUrn(t *testing.T) {
1014
tests := []struct {
1115
name string
@@ -24,14 +28,14 @@ func TestResolveDashboardIdOrUrn(t *testing.T) {
2428
{
2529
name: "Should resolve valid identifier",
2630
id: 0,
27-
identifier: "urn:custom:dashboard:test",
28-
expectedResult: "urn:custom:dashboard:test",
31+
identifier: testDashboardURN,
32+
expectedResult: testDashboardURN,
2933
expectedError: "",
3034
},
3135
{
3236
name: "Should prioritize ID when both are provided",
3337
id: 456,
34-
identifier: "urn:custom:dashboard:test",
38+
identifier: testDashboardURN,
3539
expectedResult: "456",
3640
expectedError: "",
3741
},

‎cmd/dashboard/dashboard_apply.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313
"sigs.k8s.io/kustomize/kyaml/yaml"
1414
)
1515

16+
const (
17+
dashboardKey = "dashboard"
18+
)
19+
1620
// ApplyArgs contains arguments for dashboard apply command
1721
type ApplyArgs struct {
1822
File string
@@ -93,7 +97,7 @@ func createDashboard(cli *di.Deps, api *stackstate_api.APIClient, fileBytes []by
9397

9498
if cli.IsJson() {
9599
cli.Printer.PrintJson(map[string]interface{}{
96-
"dashboard": dashboard,
100+
dashboardKey: dashboard,
97101
})
98102
} else {
99103
cli.Printer.Success(fmt.Sprintf("Dashboard created successfully! ID: %d, Name: %s", dashboard.GetId(), dashboard.GetName()))
@@ -118,7 +122,7 @@ func updateDashboard(cli *di.Deps, api *stackstate_api.APIClient, dashboardId st
118122
patchSchema.SetScope(*scope)
119123
}
120124
}
121-
if dashboardContent, ok := dashboardData["dashboard"]; ok {
125+
if dashboardContent, ok := dashboardData[dashboardKey]; ok {
122126
// Convert dashboard content to PersesDashboard
123127
dashboardBytes, err := yaml.Marshal(dashboardContent)
124128
if err == nil {
@@ -137,7 +141,7 @@ func updateDashboard(cli *di.Deps, api *stackstate_api.APIClient, dashboardId st
137141

138142
if cli.IsJson() {
139143
cli.Printer.PrintJson(map[string]interface{}{
140-
"dashboard": dashboard,
144+
dashboardKey: dashboard,
141145
})
142146
} else {
143147
cli.Printer.Success(fmt.Sprintf("Dashboard updated successfully! ID: %d, Name: %s", dashboard.GetId(), dashboard.GetName()))

0 commit comments

Comments
 (0)