@@ -113,6 +113,27 @@ func TestFindExecutable(t *testing.T) {
113
113
assert .Equal (t , filepath .Base (executable ), "dummy" )
114
114
assert .True (t , strings .HasPrefix (executable , dir ))
115
115
})
116
+
117
+ t .Run ("returns string containing path to executable when shim template in plugin is set" , func (t * testing.T ) {
118
+ // write a version file
119
+ data := []byte ("lua 1.1.0" )
120
+ assert .Nil (t , os .WriteFile (filepath .Join (currentDir , ".tool-versions" ), data , 0o666 ))
121
+
122
+ // write a shim template to the plugin shims dir
123
+ setupShimTemplate (t , plugin , "dummy" , "echo 'shim template'" )
124
+
125
+ executable , gotPlugin , version , found , err := FindExecutable (conf , "dummy" , currentDir )
126
+ assert .Nil (t , err )
127
+
128
+ relativePath , err := filepath .Rel (conf .DataDir , executable )
129
+ assert .Nil (t , err )
130
+
131
+ assert .Equal (t , "plugins/lua/shims/dummy" , relativePath )
132
+ assert .Equal (t , "dummy" , filepath .Base (executable ))
133
+ assert .Equal (t , plugin , gotPlugin )
134
+ assert .Equal (t , "" , version )
135
+ assert .True (t , found )
136
+ })
116
137
}
117
138
118
139
func TestFindExecutable_Ref (t * testing.T ) {
@@ -443,6 +464,27 @@ func TestExecutablePaths(t *testing.T) {
443
464
assert .Equal (t , filepath .Base (path1 ), "foo" )
444
465
assert .Equal (t , filepath .Base (path2 ), "bar" )
445
466
})
467
+
468
+ t .Run ("returns list of executable paths for tool version containing shim templates" , func (t * testing.T ) {
469
+ data := []byte ("echo 'foo bar'" )
470
+ err := os .WriteFile (filepath .Join (plugin .Dir , "bin" , "list-bin-paths" ), data , 0o777 )
471
+ assert .Nil (t , err )
472
+
473
+ // write a shim template to the plugin shims dir
474
+ setupShimTemplate (t , plugin , "dummy" , "echo 'shim template'" )
475
+
476
+ executables , err := ExecutablePaths (conf , plugin , toolversions.Version {Type : "version" , Value : "1.2.3" })
477
+ assert .Nil (t , err )
478
+ path1 := executables [0 ]
479
+ path2 := executables [1 ]
480
+ path3 := executables [2 ]
481
+ assert .Equal (t , "foo" , filepath .Base (path2 ))
482
+ assert .Equal (t , "bar" , filepath .Base (path3 ))
483
+
484
+ relativePath , err := filepath .Rel (conf .DataDir , path1 )
485
+ assert .Nil (t , err )
486
+ assert .Equal (t , "plugins/lua/shims" , relativePath )
487
+ })
446
488
}
447
489
448
490
func TestExecutableDirs (t * testing.T ) {
@@ -511,3 +553,19 @@ func installVersion(t *testing.T, conf config.Config, plugin plugins.Plugin, ver
511
553
err := installtest .InstallOneVersion (conf , plugin , "version" , version )
512
554
assert .Nil (t , err )
513
555
}
556
+
557
+ func setupShimTemplate (t * testing.T , plugin plugins.Plugin , shimName string , script string ) {
558
+ t .Helper ()
559
+ shimsDirPath := filepath .Join (plugin .Dir , "shims" )
560
+ os .MkdirAll (shimsDirPath , 0o777 )
561
+
562
+ shimPath := filepath .Join (shimsDirPath , shimName )
563
+ contents := fmt .Sprintf ("#!/usr/bin/env bash\n %s\n " , script )
564
+ err := os .WriteFile (shimPath , []byte (contents ), 0o777 )
565
+ assert .Nil (t , err )
566
+
567
+ t .Cleanup (func () {
568
+ err := os .Remove (shimPath )
569
+ assert .Nil (t , err )
570
+ })
571
+ }
0 commit comments