33package main
44
55import (
6+ "fmt"
67 "os"
78 "path/filepath"
89 "strings"
@@ -321,8 +322,11 @@ func TestGetTemplateInfo(t *testing.T) {
321322 require .NoError (t , err )
322323 assert .NotEmpty (t , owner , "owner should not be empty" )
323324 assert .NotEmpty (t , repo , "repo should not be empty" )
324- assert .Equal (t , "mrz1836" , owner , "owner should match go.mod" )
325- assert .Equal (t , "go-template" , repo , "repo should match go.mod" )
325+
326+ // Verify that the values extracted match the module path format
327+ // The owner and repo should be the last two parts of the module path
328+ assert .NotContains (t , owner , "/" , "owner should not contain slashes" )
329+ assert .NotContains (t , repo , "/" , "repo should not contain slashes" )
326330}
327331
328332func TestGetTemplateInfoError (t * testing.T ) {
@@ -361,13 +365,17 @@ func TestCreateReplacements(t *testing.T) {
361365 _ = os .Chdir (originalDir )
362366 }()
363367
368+ // Get the current template info dynamically from go.mod
369+ templateOwner , templateRepo , err := getTemplateInfo ()
370+ require .NoError (t , err )
371+
364372 replacements := createReplacements (owner , repo )
365373
366- // The replacements should use the values from go.mod
374+ // The replacements should use the values from go.mod (dynamic)
367375 expected := []struct { from , to string }{
368- {"mrz1836/go-template" , testOwnerRepoPath },
369- {testGoTemplate , "testrepo" },
370- {"mrz1836" , "testowner" },
376+ {fmt . Sprintf ( "%s/%s" , templateOwner , templateRepo ) , testOwnerRepoPath },
377+ {templateRepo , "testrepo" },
378+ {templateOwner , "testowner" },
371379 }
372380
373381 assert .Equal (t , expected , replacements )
@@ -378,14 +386,18 @@ func TestCreateReplacementsFallback(t *testing.T) {
378386 repo := "testrepo"
379387
380388 // Test fallback behavior when go.mod is not accessible
381- // Stay in magefiles directory where go.mod doesn't exist
389+ // Stay in magefiles directory where go.mod doesn't exist in current dir
382390 replacements := createReplacements (owner , repo )
383391
384- // Should use fallback values
392+ // Get the fallback values dynamically
393+ fallbackOwner , fallbackRepo , err := getFallbackTemplateInfo ()
394+ require .NoError (t , err , "getFallbackTemplateInfo should succeed from magefiles directory" )
395+
396+ // Should use fallback values (dynamic based on current implementation)
385397 expected := []struct { from , to string }{
386- {"mrz1836/go-template" , testOwnerRepoPath },
387- {testGoTemplate , "testrepo" },
388- {"mrz1836" , "testowner" },
398+ {fmt . Sprintf ( "%s/%s" , fallbackOwner , fallbackRepo ) , testOwnerRepoPath },
399+ {fallbackRepo , "testrepo" },
400+ {fallbackOwner , "testowner" },
389401 }
390402
391403 assert .Equal (t , expected , replacements )
0 commit comments