Skip to content

Commit bac17a6

Browse files
author
Gustavo Bazan
authored
task: fix linting warnings (#3887)
1 parent 7a051e6 commit bac17a6

File tree

2 files changed

+44
-47
lines changed

2 files changed

+44
-47
lines changed

internal/cli/plugin/plugin_github_asset_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ func Test_getIDsForOSArch(t *testing.T) {
326326

327327
for _, tt := range tests {
328328
t.Run(tt.name, func(t *testing.T) {
329+
t.Parallel()
329330
opts := &GithubAsset{}
330331

331332
assetID, signatureID, pubKeyID, err := opts.getIDsForOSArch(tt.pluginAssets, tt.os, tt.arch)
@@ -350,11 +351,11 @@ func Test_parseGithubRepoValues(t *testing.T) {
350351
expectedOwner = "mongodb"
351352
expectedName = "atlas-cli-plugin-example"
352353
)
353-
var v1_0_0, _ = semver.NewVersion("1.0.0")
354-
//nolint:revive,stylecheck
355-
var v1_0_0_PRE, _ = semver.NewVersion("1.0.0-prerelease")
356-
//nolint:revive,stylecheck
357-
var v1_0_0_BETA_AND_META, _ = semver.NewVersion("1.0.0-beta+very-meta")
354+
var (
355+
v1, _ = semver.NewVersion("1.0.0")
356+
v1pre, _ = semver.NewVersion("1.0.0-prerelease")
357+
v1pseudo, _ = semver.NewVersion("1.0.0-beta+very-meta")
358+
)
358359

359360
tests := []struct {
360361
arg string
@@ -368,22 +369,22 @@ func Test_parseGithubRepoValues(t *testing.T) {
368369
},
369370
{
370371
arg: "mongodb/atlas-cli-plugin-example@1.0.0",
371-
expectedVersion: v1_0_0,
372+
expectedVersion: v1,
372373
expectError: false,
373374
},
374375
{
375376
arg: "mongodb/atlas-cli-plugin-example@v1.0.0",
376-
expectedVersion: v1_0_0,
377+
expectedVersion: v1,
377378
expectError: false,
378379
},
379380
{
380381
arg: "mongodb/atlas-cli-plugin-example@1.0.0-prerelease",
381-
expectedVersion: v1_0_0_PRE,
382+
expectedVersion: v1pre,
382383
expectError: false,
383384
},
384385
{
385386
arg: "mongodb/atlas-cli-plugin-example@1.0.0-beta+very-meta",
386-
expectedVersion: v1_0_0_BETA_AND_META,
387+
expectedVersion: v1pseudo,
387388
expectError: false,
388389
},
389390
{
@@ -398,7 +399,7 @@ func Test_parseGithubRepoValues(t *testing.T) {
398399
},
399400
{
400401
arg: "mongodb/atlas-cli-plugin-example/@v1",
401-
expectedVersion: v1_0_0,
402+
expectedVersion: v1,
402403
expectError: false,
403404
},
404405
{
@@ -408,7 +409,7 @@ func Test_parseGithubRepoValues(t *testing.T) {
408409
},
409410
{
410411
arg: "https://github.com/mongodb/atlas-cli-plugin-example@v1.0",
411-
expectedVersion: v1_0_0,
412+
expectedVersion: v1,
412413
expectError: false,
413414
},
414415
{
@@ -418,7 +419,7 @@ func Test_parseGithubRepoValues(t *testing.T) {
418419
},
419420
{
420421
arg: "github.com/mongodb/atlas-cli-plugin-example/@v1.0.0",
421-
expectedVersion: v1_0_0,
422+
expectedVersion: v1,
422423
expectError: false,
423424
},
424425
{

internal/cli/plugin/update_test.go

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,123 +20,119 @@ import (
2020
"testing"
2121

2222
"github.com/Masterminds/semver/v3"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2325
)
2426

2527
func Test_extractPluginSpecifierAndVersionFromArg(t *testing.T) {
26-
var v1_0_0, _ = semver.NewVersion("1.0.0")
27-
//nolint:revive,stylecheck
28-
var v1_0_0_PRE, _ = semver.NewVersion("1.0.0-prerelease")
29-
//nolint:revive,stylecheck
30-
var v1_0_0_BETA_AND_META, _ = semver.NewVersion("1.0.0-beta+very-meta")
28+
var (
29+
v1, _ = semver.NewVersion("1.0.0")
30+
v1pre, _ = semver.NewVersion("1.0.0-prerelease")
31+
v1pseudo, _ = semver.NewVersion("1.0.0-beta+very-meta")
32+
)
3133

3234
tests := []struct {
3335
arg string
3436
expectedPluginSpecifier string
3537
expectedVersion *semver.Version
36-
expectError bool
38+
expectError require.ErrorAssertionFunc
3739
}{
3840
{
3941
arg: "mongodb/atlas-cli-plugin-example",
4042
expectedPluginSpecifier: "mongodb/atlas-cli-plugin-example",
4143
expectedVersion: nil,
42-
expectError: false,
44+
expectError: require.NoError,
4345
},
4446
{
4547
arg: "atlas-cli-plugin-example@1.0.0",
4648
expectedPluginSpecifier: "atlas-cli-plugin-example",
47-
expectedVersion: v1_0_0,
48-
expectError: false,
49+
expectedVersion: v1,
50+
expectError: require.NoError,
4951
},
5052
{
5153
arg: "atlas-cli-plugin-example@1.0.0-prerelease",
5254
expectedPluginSpecifier: "atlas-cli-plugin-example",
53-
expectedVersion: v1_0_0_PRE,
54-
expectError: false,
55+
expectedVersion: v1pre,
56+
expectError: require.NoError,
5557
},
5658
{
5759
arg: "atlas-cli-plugin-example@1.0.0-beta+very-meta",
5860
expectedPluginSpecifier: "atlas-cli-plugin-example",
59-
expectedVersion: v1_0_0_BETA_AND_META,
60-
expectError: false,
61+
expectedVersion: v1pseudo,
62+
expectError: require.NoError,
6163
},
6264
{
6365
arg: "atlas-cli-plugin-example@",
6466
expectedPluginSpecifier: "",
6567
expectedVersion: nil,
66-
expectError: true,
68+
expectError: require.Error,
6769
},
6870
{
6971
arg: "mongodb/atlas-cli-plugin-example/",
7072
expectedPluginSpecifier: "mongodb/atlas-cli-plugin-example/",
7173
expectedVersion: nil,
72-
expectError: false,
74+
expectError: require.NoError,
7375
},
7476
{
7577
arg: "mongodb/atlas-cli-plugin-example/@v1",
7678
expectedPluginSpecifier: "mongodb/atlas-cli-plugin-example/",
77-
expectedVersion: v1_0_0,
78-
expectError: false,
79+
expectedVersion: v1,
80+
expectError: require.NoError,
7981
},
8082
{
8183
arg: "https://github.com/mongodb/atlas-cli-plugin-example",
8284
expectedPluginSpecifier: "https://github.com/mongodb/atlas-cli-plugin-example",
8385
expectedVersion: nil,
84-
expectError: false,
86+
expectError: require.NoError,
8587
},
8688
{
8789
arg: "https://github.com/mongodb/atlas-cli-plugin-example@v1.0",
8890
expectedPluginSpecifier: "https://github.com/mongodb/atlas-cli-plugin-example",
89-
expectedVersion: v1_0_0,
90-
expectError: false,
91+
expectedVersion: v1,
92+
expectError: require.NoError,
9193
},
9294
{
9395
arg: "github.com/mongodb/atlas-cli-plugin-example/",
9496
expectedPluginSpecifier: "github.com/mongodb/atlas-cli-plugin-example/",
9597
expectedVersion: nil,
96-
expectError: false,
98+
expectError: require.NoError,
9799
},
98100
{
99101
arg: "github.com/mongodb/atlas-cli-plugin-example/@v1.0.0",
100102
expectedPluginSpecifier: "github.com/mongodb/atlas-cli-plugin-example/",
101-
expectedVersion: v1_0_0,
102-
expectError: false,
103+
expectedVersion: v1,
104+
expectError: require.NoError,
103105
},
104106
{
105107
arg: "/mongodb/atlas-cli-plugin-example/",
106108
expectedPluginSpecifier: "/mongodb/atlas-cli-plugin-example/",
107109
expectedVersion: nil,
108-
expectError: false,
110+
expectError: require.NoError,
109111
},
110112
{
111113
arg: "mongodb@atlas-cli-plugin-example",
112114
expectedPluginSpecifier: "",
113115
expectedVersion: nil,
114-
expectError: true,
116+
expectError: require.Error,
115117
},
116118
{
117119
arg: "mongodb@atlas-cli-plugin-example@1.0",
118120
expectedPluginSpecifier: "",
119121
expectedVersion: nil,
120-
expectError: true,
122+
expectError: require.Error,
121123
},
122124
}
123125

124126
for _, tt := range tests {
125127
t.Run(tt.arg, func(t *testing.T) {
128+
t.Parallel()
126129
pluginSpecifier, version, err := extractPluginSpecifierAndVersionFromArg(tt.arg)
127-
128-
if (err != nil) != tt.expectError {
129-
t.Errorf("expected error: %v, got: %v", tt.expectError, err)
130-
}
131-
132-
if pluginSpecifier != tt.expectedPluginSpecifier {
133-
t.Errorf("expected plugin specifier: %s, got: %s", tt.expectedPluginSpecifier, pluginSpecifier)
134-
}
130+
tt.expectError(t, err)
131+
assert.Equal(t, tt.expectedPluginSpecifier, pluginSpecifier)
135132

136133
if tt.expectedVersion != nil && !tt.expectedVersion.Equal(version) {
137134
t.Errorf("expected version: %s, got: %s", tt.expectedVersion.String(), version.String())
138135
}
139-
140136
if tt.expectedVersion == nil && version != nil {
141137
t.Errorf("expected version to be nil, got: %s", version.String())
142138
}

0 commit comments

Comments
 (0)