@@ -11,6 +11,7 @@ import (
1111 "github.com/go-nv/goenv/internal/utils"
1212 "github.com/go-nv/goenv/testing/testutil"
1313 "github.com/spf13/cobra"
14+ "github.com/stretchr/testify/assert"
1415)
1516
1617func TestAliasCommand (t * testing.T ) {
@@ -144,33 +145,22 @@ func TestAliasCommand(t *testing.T) {
144145 return
145146 }
146147
147- if err != nil {
148- t .Errorf ("Unexpected error: %v" , err )
149- return
150- }
148+ assert .NoError (t , err )
151149
152150 if tt .expectedOutput != "" {
153151 got := strings .TrimSpace (stdout .String ())
154- if got != tt .expectedOutput {
155- t .Errorf ("Expected output '%s', got '%s'" , tt .expectedOutput , got )
156- }
152+ assert .Equal (t , tt .expectedOutput , got )
157153 }
158154
159155 // For set operations, verify the file was written correctly
160156 if len (tt .args ) == 2 && tt .expectedError == "" {
161157 aliasesFile := filepath .Join (tmpDir , "aliases" )
162158 content , err := os .ReadFile (aliasesFile )
163- if err != nil {
164- t .Errorf ("Failed to read aliases file: %v" , err )
165- return
166- }
159+ assert .NoError (t , err , "Failed to read aliases file" )
167160
168161 // Check that alias was written
169162 expectedLine := tt .args [0 ] + "=" + tt .args [1 ]
170- if ! strings .Contains (string (content ), expectedLine ) {
171- t .Errorf ("Expected aliases file to contain '%s', got:\n %s" ,
172- expectedLine , string (content ))
173- }
163+ assert .Contains (t , string (content ), expectedLine )
174164 }
175165 })
176166 }
@@ -259,33 +249,22 @@ func TestUnaliasCommand(t *testing.T) {
259249 return
260250 }
261251
262- if err != nil {
263- t .Errorf ("Unexpected error: %v" , err )
264- return
265- }
252+ assert .NoError (t , err )
266253
267254 // Verify the alias was removed from the file
268255 if len (tt .args ) == 1 && tt .expectedError == "" {
269256 aliasesFile := filepath .Join (tmpDir , "aliases" )
270257 content , err := os .ReadFile (aliasesFile )
271- if err != nil {
272- t .Errorf ("Failed to read aliases file: %v" , err )
273- return
274- }
258+ assert .NoError (t , err , "Failed to read aliases file" )
275259
276260 // Check that alias was removed
277261 removedAlias := tt .args [0 ]
278- if strings .Contains (string (content ), removedAlias + "=" ) {
279- t .Errorf ("Expected alias '%s' to be removed, but it still exists in:\n %s" ,
280- removedAlias , string (content ))
281- }
262+ assert .NotContains (t , string (content ), removedAlias + "=" )
282263
283264 // Check that other aliases are still present
284265 for name := range tt .setupAliases {
285266 if name != removedAlias {
286- if ! strings .Contains (string (content ), name + "=" ) {
287- t .Errorf ("Expected alias '%s' to still exist" , name )
288- }
267+ assert .Contains (t , string (content ), name + "=" )
289268 }
290269 }
291270 }
@@ -347,23 +326,15 @@ func TestAliasResolution(t *testing.T) {
347326 cmd .SetArgs ([]string {tt .aliasName })
348327
349328 err := cmd .Execute ()
350- if err != nil {
351- t .Errorf ("Failed to set global with alias: %v" , err )
352- return
353- }
329+ assert .NoError (t , err , "Failed to set global with alias" )
354330
355331 // Verify the resolved version was written
356332 globalFile := filepath .Join (tmpDir , "version" )
357333 content , err := os .ReadFile (globalFile )
358- if err != nil {
359- t .Errorf ("Failed to read global version file: %v" , err )
360- return
361- }
334+ assert .NoError (t , err , "Failed to read global version file" )
362335
363336 got := strings .TrimSpace (string (content ))
364- if got != tt .expectedOutput {
365- t .Errorf ("Expected global version to be '%s', got '%s'" , tt .expectedOutput , got )
366- }
337+ assert .Equal (t , tt .expectedOutput , got )
367338 }
368339
369340 if tt .useLocal {
@@ -380,26 +351,18 @@ func TestAliasResolution(t *testing.T) {
380351 cmd .SetArgs ([]string {tt .aliasName })
381352
382353 err := cmd .Execute ()
383- if err != nil {
384- t .Errorf ("Failed to set local with alias: %v" , err )
385- return
386- }
354+ assert .NoError (t , err , "Failed to set local with alias" )
387355
388356 // Verify the resolved version was written
389357 // setupTestEnv changes to testHome directory, so local file should be there
390358 cwd , _ := os .Getwd ()
391359 localFile := filepath .Join (cwd , ".go-version" )
392360
393361 content , err := os .ReadFile (localFile )
394- if err != nil {
395- t .Errorf ("Failed to read local version file: %v" , err )
396- return
397- }
362+ assert .NoError (t , err , "Failed to read local version file" )
398363
399364 got := strings .TrimSpace (string (content ))
400- if got != tt .expectedOutput {
401- t .Errorf ("Expected local version to be '%s', got '%s'" , tt .expectedOutput , got )
402- }
365+ assert .Equal (t , tt .expectedOutput , got )
403366 }
404367 })
405368 }
0 commit comments