@@ -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
2527func 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