Skip to content

Commit c081f20

Browse files
authored
Fix linting errors after v2 update (#235)
1 parent 148783e commit c081f20

11 files changed

Lines changed: 61 additions & 42 deletions

File tree

cmd/bundle.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package cmd implements the mass CLI commands.
12
package cmd
23

34
import (
@@ -6,6 +7,7 @@ import (
67
"context"
78
"embed"
89
"encoding/json"
10+
"errors"
911
"fmt"
1012
"os"
1113
"path/filepath"
@@ -316,7 +318,7 @@ func bundleDir(cmd *cobra.Command, args []string) (string, error) {
316318
hasPositional := len(args) > 0
317319
flagSet := cmd.Flags().Changed("bundle-directory")
318320
if hasPositional && flagSet {
319-
return "", fmt.Errorf("cannot specify both a positional path and --bundle-directory; use one")
321+
return "", errors.New("cannot specify both a positional path and --bundle-directory; use one")
320322
}
321323
if hasPositional {
322324
return args[0], nil
@@ -561,7 +563,7 @@ func runBundleGet(cmd *cobra.Command, args []string) error {
561563

562564
bundleID := args[0]
563565
if !strings.Contains(bundleID, "@") {
564-
bundleID = bundleID + "@latest"
566+
bundleID += "@latest"
565567
}
566568

567569
outputFormat, err := cmd.Flags().GetString("output")

cmd/environment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ func runEnvironmentCreate(cmd *cobra.Command, args []string) error {
277277
return nil
278278
}
279279

280+
//nolint:dupl // parallel CRUD shape with other entity update commands
280281
func runEnvironmentUpdate(cmd *cobra.Command, args []string) error {
281282
ctx := context.Background()
282283

cmd/instance.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
var instanceTemplates embed.FS
2727

2828
// NewCmdInstance returns a cobra command for managing instances of IaC deployed in environments.
29-
func NewCmdInstance() *cobra.Command { //nolint:funlen // cobra command builders are necessarily long
29+
func NewCmdInstance() *cobra.Command {
3030
instanceCmd := &cobra.Command{
3131
Use: "instance",
3232
Aliases: []string{"inst", "package", "instance"},
@@ -183,6 +183,7 @@ func renderInstance(instance *api.Instance) error {
183183
return nil
184184
}
185185

186+
//nolint:gocognit // sequential flag parsing and dispatch, not branching logic
186187
func runInstanceDeploy(cmd *cobra.Command, args []string) error {
187188
ctx := context.Background()
188189

cmd/project.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func runProjectCreate(cmd *cobra.Command, args []string) error {
259259
return nil
260260
}
261261

262+
//nolint:dupl // parallel CRUD shape with other entity update commands
262263
func runProjectUpdate(cmd *cobra.Command, args []string) error {
263264
ctx := context.Background()
264265

cmd/repository.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"embed"
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"os"
1112
"strings"
@@ -167,31 +168,31 @@ func runRepositoryList(input *repositoryListInput) error {
167168

168169
func buildOciReposFilter(input *repositoryListInput) (*api.OciReposFilter, error) {
169170
filter := &api.OciReposFilter{}
170-
any := false
171+
hasFilter := false
171172

172173
if input.kind != "" {
173174
mediaType, resolveErr := resolveArtifactType(input.kind)
174175
if resolveErr != nil {
175176
return nil, resolveErr
176177
}
177178
filter.ArtifactType = mediaType
178-
any = true
179+
hasFilter = true
179180
}
180181
if input.search != "" {
181182
filter.Search = input.search
182-
any = true
183+
hasFilter = true
183184
}
184185
switch {
185186
case input.name != "" && input.prefix != "":
186-
return nil, fmt.Errorf("--name and --prefix are mutually exclusive")
187+
return nil, errors.New("--name and --prefix are mutually exclusive")
187188
case input.name != "":
188189
filter.Name = &api.OciRepoNameFilter{Eq: input.name}
189-
any = true
190+
hasFilter = true
190191
case input.prefix != "":
191192
filter.Name = &api.OciRepoNameFilter{StartsWith: input.prefix}
192-
any = true
193+
hasFilter = true
193194
}
194-
if !any {
195+
if !hasFilter {
195196
return nil, nil //nolint:nilnil // explicit nil filter is the no-filter signal to the API
196197
}
197198
return filter, nil

internal/api/bundle.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010

1111
// Bundle represents a Massdriver bundle (IaC module) and its metadata.
1212
type Bundle struct {
13-
ID string `json:"id" mapstructure:"id"`
14-
Name string `json:"name" mapstructure:"name"`
15-
Version string `json:"version" mapstructure:"version"`
16-
Description string `json:"description,omitempty" mapstructure:"description"`
17-
Icon string `json:"icon,omitempty" mapstructure:"icon"`
18-
SourceURL string `json:"sourceUrl,omitempty" mapstructure:"sourceUrl"`
19-
Repo string `json:"repo,omitempty" mapstructure:"repo"`
20-
CreatedAt time.Time `json:"createdAt,omitzero" mapstructure:"createdAt"`
21-
UpdatedAt time.Time `json:"updatedAt,omitzero" mapstructure:"updatedAt"`
22-
Dependencies []BundleSlot `json:"dependencies,omitempty" mapstructure:"dependencies"`
23-
Resources []BundleSlot `json:"resources,omitempty" mapstructure:"resources"`
13+
ID string `json:"id" mapstructure:"id"`
14+
Name string `json:"name" mapstructure:"name"`
15+
Version string `json:"version" mapstructure:"version"`
16+
Description string `json:"description,omitempty" mapstructure:"description"`
17+
Icon string `json:"icon,omitempty" mapstructure:"icon"`
18+
SourceURL string `json:"sourceUrl,omitempty" mapstructure:"sourceUrl"`
19+
Repo string `json:"repo,omitempty" mapstructure:"repo"`
20+
CreatedAt time.Time `json:"createdAt,omitzero" mapstructure:"createdAt"`
21+
UpdatedAt time.Time `json:"updatedAt,omitzero" mapstructure:"updatedAt"`
22+
Dependencies []BundleSlot `json:"dependencies,omitempty" mapstructure:"dependencies"`
23+
Resources []BundleSlot `json:"resources,omitempty" mapstructure:"resources"`
2424
}
2525

2626
// BundleSlot describes one of a bundle's input dependencies or output

internal/api/oci_repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ func GetOciRepo(ctx context.Context, mdClient *client.Client, id string) (*OciRe
5151
UpdatedAt: r.UpdatedAt,
5252
}
5353
for _, rc := range r.ReleaseChannels.Items {
54-
repo.ReleaseChannels = append(repo.ReleaseChannels, OciReleaseChannel{Name: rc.Name, Tag: rc.Tag})
54+
repo.ReleaseChannels = append(repo.ReleaseChannels, OciReleaseChannel(rc))
5555
}
5656
for _, tag := range r.Tags.Items {
57-
repo.Tags = append(repo.Tags, OciRepoTag{Tag: tag.Tag, CreatedAt: tag.CreatedAt})
57+
repo.Tags = append(repo.Tags, OciRepoTag(tag))
5858
}
5959

6060
return &repo, nil
@@ -81,7 +81,7 @@ func ListOciRepos(ctx context.Context, mdClient *client.Client, filter *OciRepos
8181
UpdatedAt: r.UpdatedAt,
8282
}
8383
for _, rc := range r.ReleaseChannels.Items {
84-
repo.ReleaseChannels = append(repo.ReleaseChannels, OciReleaseChannel{Name: rc.Name, Tag: rc.Tag})
84+
repo.ReleaseChannels = append(repo.ReleaseChannels, OciReleaseChannel(rc))
8585
}
8686
repos = append(repos, repo)
8787
}

internal/api/scalars/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func isEmpty(v any) bool {
4444
}
4545
rv = rv.Elem()
4646
}
47-
switch rv.Kind() {
47+
switch rv.Kind() { //nolint:exhaustive // only nil-able container kinds need the IsNil check
4848
case reflect.Map, reflect.Slice:
4949
return rv.IsNil()
5050
}

internal/commands/instance/deploy_test.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,15 @@ func TestRunDeployReusesLastConfig(t *testing.T) {
6565
t.Errorf("got %s, wanted COMPLETED", dep.Status)
6666
}
6767

68-
input, ok := createDeploymentVars["input"].(map[string]any)
69-
if !ok {
70-
t.Fatalf("expected input map, got %T", createDeploymentVars["input"])
71-
}
68+
input := mustInputMap(t, createDeploymentVars)
7269
if input["message"] != "redeploy" {
7370
t.Errorf("expected message 'redeploy', got %v", input["message"])
7471
}
7572
if input["action"] != "PROVISION" {
7673
t.Errorf("expected action 'PROVISION', got %v", input["action"])
7774
}
7875

79-
gotParams := map[string]any{}
80-
gqlmock.MustUnmarshalJSON([]byte(input["params"].(string)), &gotParams)
76+
gotParams := unmarshalParams(t, input)
8177
wantParams := map[string]any{"size": "small"}
8278
if !reflect.DeepEqual(gotParams, wantParams) {
8379
t.Errorf("got params %v, wanted %v", gotParams, wantParams)
@@ -131,9 +127,8 @@ func TestRunDeployWithParamsReplacesConfig(t *testing.T) {
131127
t.Fatal(err)
132128
}
133129

134-
input := createDeploymentVars["input"].(map[string]any)
135-
gotParams := map[string]any{}
136-
gqlmock.MustUnmarshalJSON([]byte(input["params"].(string)), &gotParams)
130+
input := mustInputMap(t, createDeploymentVars)
131+
gotParams := unmarshalParams(t, input)
137132
wantParams := map[string]any{"size": "6GB"}
138133
if !reflect.DeepEqual(gotParams, wantParams) {
139134
t.Errorf("got params %v, wanted %v", gotParams, wantParams)
@@ -186,9 +181,8 @@ func TestRunDeployWithPatchQueriesUpdatesLastConfig(t *testing.T) {
186181
t.Fatal(err)
187182
}
188183

189-
input := createDeploymentVars["input"].(map[string]any)
190-
gotParams := map[string]any{}
191-
gqlmock.MustUnmarshalJSON([]byte(input["params"].(string)), &gotParams)
184+
input := mustInputMap(t, createDeploymentVars)
185+
gotParams := unmarshalParams(t, input)
192186
wantParams := map[string]any{"cidr": "10.0.0.0/20", "name": "keep"}
193187
if !reflect.DeepEqual(gotParams, wantParams) {
194188
t.Errorf("got params %v, wanted %v", gotParams, wantParams)
@@ -239,13 +233,12 @@ func TestRunDeployWithDecommissionAction(t *testing.T) {
239233
t.Fatal(err)
240234
}
241235

242-
input := createDeploymentVars["input"].(map[string]any)
236+
input := mustInputMap(t, createDeploymentVars)
243237
if input["action"] != "DECOMMISSION" {
244238
t.Errorf("expected action 'DECOMMISSION', got %v", input["action"])
245239
}
246240

247-
gotParams := map[string]any{}
248-
gqlmock.MustUnmarshalJSON([]byte(input["params"].(string)), &gotParams)
241+
gotParams := unmarshalParams(t, input)
249242
wantParams := map[string]any{"size": "small"}
250243
if !reflect.DeepEqual(gotParams, wantParams) {
251244
t.Errorf("got params %v, wanted %v", gotParams, wantParams)
@@ -287,3 +280,23 @@ func TestRunDeployFailsWhenDeploymentFails(t *testing.T) {
287280
t.Fatal("expected error, got nil")
288281
}
289282
}
283+
284+
func mustInputMap(t *testing.T, vars map[string]any) map[string]any {
285+
t.Helper()
286+
input, ok := vars["input"].(map[string]any)
287+
if !ok {
288+
t.Fatalf("expected input map, got %T", vars["input"])
289+
}
290+
return input
291+
}
292+
293+
func unmarshalParams(t *testing.T, input map[string]any) map[string]any {
294+
t.Helper()
295+
raw, ok := input["params"].(string)
296+
if !ok {
297+
t.Fatalf("expected params string, got %T", input["params"])
298+
}
299+
out := map[string]any{}
300+
gqlmock.MustUnmarshalJSON([]byte(raw), &out)
301+
return out
302+
}

internal/resourcetype/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Delete(ctx context.Context, mdClient *client.Client, name string, force boo
3535
}
3636
}
3737

38-
deletedRT, deleteErr := api.DeleteResourceType(ctx, mdClient, name)
38+
deletedRT, deleteErr := api.DeleteResourceType(ctx, mdClient, name) //nolint:staticcheck // pending migration to OCI-native flow
3939
if deleteErr != nil {
4040
return fmt.Errorf("error deleting resource type: %w", deleteErr)
4141
}

0 commit comments

Comments
 (0)