@@ -37,6 +37,14 @@ const (
3737func Test_plugin (t * testing.T ) {
3838 if os .Getenv (forkEnvVar ) == "" {
3939 g := NewWithT (t )
40+ tmpDir := os .TempDir ()
41+ defer os .Remove (tmpDir )
42+
43+ // Create a bash based plugin used for the test which gets added to the PATH variable.
44+ pluginPath := filepath .Join (tmpDir , "clusterctl-foo" )
45+ pathVar := os .Getenv ("PATH" )
46+ g .Expect (os .WriteFile (pluginPath , []byte (pluginCode ), 0755 )).To (Succeed ()) //nolint:gosec
47+
4048 tt := []struct {
4149 name string
4250 command string
@@ -52,19 +60,11 @@ func Test_plugin(t *testing.T) {
5260 expected : "1.0.0" ,
5361 },
5462 }
55-
56- tmpDir := os .TempDir ()
57- defer os .Remove (tmpDir )
58-
59- pluginPath := filepath .Join (tmpDir , "clusterctl-foo" )
60- path := os .Getenv ("PATH" )
61- g .Expect (os .WriteFile (pluginPath , []byte (pluginCode ), 0755 )).To (Succeed ()) //nolint:gosec
62-
6363 for _ , tc := range tt {
6464 t .Run (tc .name , func (t * testing.T ) {
6565 g := NewWithT (t )
66- stdout , _ , err := runForkTest (t .Name (), fmt .Sprintf ("%s=%s" , pluginCommandEnvVar , tc .command ), fmt .Sprintf ("PATH=%s:%s" , tmpDir , path ))
67- g .Expect (err ).NotTo ( HaveOccurred ())
66+ stdout , _ , err := runForkTest (t .Name (), fmt .Sprintf ("%s=%s" , pluginCommandEnvVar , tc .command ), fmt .Sprintf ("PATH=%s:%s" , tmpDir , pathVar ))
67+ g .Expect (err ).To ( Succeed ())
6868 g .Expect (stdout ).To (ContainSubstring (tc .expected ))
6969 })
7070 }
0 commit comments