@@ -35,93 +35,98 @@ func TestRunCommand(t *testing.T) {
3535 assert .Regexp (t , "Error: failed to load env file from .+" + path + ": open non-existent\\ .env: " + errMsg , buff .String ())
3636 })
3737
38- t .Run ("Run with env file" , func (t * testing.T ) {
39- t .Parallel ()
40-
41- envFile , err := createEnvFile (t .TempDir (), []byte ("CHARACTER=rick_sanchez" ))
42- defer os .Remove (envFile )
43- if err != nil {
44- t .Fatalf ("Failed to write env file: %v" , err )
45- }
46-
47- buff , err := execRunCommand (& []string {}, "run" , "--env-file" , envFile , "--" , "printenv" , "CHARACTER" )
48- if err != nil {
49- t .Fatal (err .Error ())
50- }
51-
52- result , found := findEnvVariableInLogs (& buff )
53- if ! found {
54- t .Fatalf ("Expected printenv in the output: %s" , buff .String ())
55- }
56- assert .Equal (t , "rick_sanchez" , result , fmt .Sprintf ("Expected 'printenv | rick_sanchez' in the output, got 'printenv | %s'" , result ))
57- })
58-
59- t .Run ("Run with env variable" , func (t * testing.T ) {
60- t .Parallel ()
61-
62- // Set environment variables
63- envVars := []string {"CHARACTER=morty_smith" }
64-
65- buff , err := execRunCommand (& envVars , "run" , "--" , "printenv" , "CHARACTER" )
66- if err != nil {
67- t .Fatal (err .Error ())
68- }
69-
70- result , found := findEnvVariableInLogs (& buff )
71- if ! found {
72- t .Fatalf ("Expected printenv in the output: %s" , buff .String ())
73- }
74- assert .Equal (t , "morty_smith" , result , fmt .Sprintf ("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'" , result ))
75- })
76-
77- t .Run ("Run with env variable in command line has priority over the one in the env file" , func (t * testing.T ) {
78- t .Parallel ()
79-
80- envFile , err := createEnvFile (t .TempDir (), []byte ("CHARACTER=rick_sanchez" ))
81- defer os .Remove (envFile )
82- if err != nil {
83- t .Fatalf ("Failed to write env file: %v" , err )
84- }
85-
86- // Set environment variables
87- envVars := []string {"CHARACTER=morty_smith" }
88- buff , err := execRunCommand (& envVars , "run" , "--env-file" , envFile , "--" , "printenv" , "CHARACTER" )
89- if err != nil {
90- t .Fatal (err .Error ())
91- }
92-
93- result , found := findEnvVariableInLogs (& buff )
94- if ! found {
95- t .Fatalf ("Expected printenv in the output: %s" , buff .String ())
96- }
97- assert .Equal (t , "morty_smith" , result , fmt .Sprintf ("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'" , result ))
98- })
99-
100- t .Run ("Run with env variable in local env vars has priority over the one in the env file" , func (t * testing.T ) {
101- // Do not use t.Parallel() here as we are manipulating the environment!
102-
103- // Set environment variables
104- os .Setenv ("CHARACTER" , "morty_smith" )
105- defer os .Unsetenv ("CHARACTER" )
106-
107- envFile , err := createEnvFile (t .TempDir (), []byte ("CHARACTER=rick_sanchez" ))
108- defer os .Remove (envFile )
109-
110- if err != nil {
111- t .Fatalf ("Failed to write env file: %v" , err )
112- }
113-
114- buff , err := execRunCommand (& []string {}, "run" , "--env-file" , envFile , "--" , "printenv" , "CHARACTER" )
115- if err != nil {
116- t .Fatal (err .Error ())
117- }
38+ if runtime .GOOS != "windows" {
39+ t .Run ("Run with env file" , func (t * testing.T ) {
40+ t .Parallel ()
41+
42+ envFile , err := createEnvFile (t .TempDir (), []byte ("CHARACTER=rick_sanchez" ))
43+ defer os .Remove (envFile )
44+ if err != nil {
45+ t .Fatalf ("Failed to write env file: %v" , err )
46+ }
47+
48+ buff , err := execRunCommand (& []string {}, "run" , "--env-file" , envFile , "--" , "printenv" , "CHARACTER" )
49+ if err != nil {
50+ t .Fatal (err .Error ())
51+ }
52+
53+ result , found := findEnvVariableInLogs (& buff )
54+ if ! found {
55+ t .Fatalf ("Expected printenv in the output: %s" , buff .String ())
56+ }
57+ assert .Equal (t , "rick_sanchez" , result , fmt .Sprintf ("Expected 'printenv | rick_sanchez' in the output, got 'printenv | %s'" , result ))
58+ })
59+ }
11860
119- result , found := findEnvVariableInLogs (& buff )
120- if ! found {
121- t .Fatalf ("Expected printenv in the output: %s\n \n " , buff .String ())
122- }
123- assert .Equal (t , "morty_smith" , result , fmt .Sprintf ("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'" , result ))
124- })
61+ // FIXME(@chicoxyzzy): Fix tests to work on Windows
62+ if runtime .GOOS != "windows" {
63+ t .Run ("Run with env variable" , func (t * testing.T ) {
64+ t .Parallel ()
65+
66+ // Set environment variables
67+ envVars := []string {"CHARACTER=morty_smith" }
68+
69+ buff , err := execRunCommand (& envVars , "run" , "--" , "printenv" , "CHARACTER" )
70+ if err != nil {
71+ t .Fatal (err .Error ())
72+ }
73+
74+ result , found := findEnvVariableInLogs (& buff )
75+ if ! found {
76+ t .Fatalf ("Expected printenv in the output: %s" , buff .String ())
77+ }
78+ assert .Equal (t , "morty_smith" , result , fmt .Sprintf ("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'" , result ))
79+ })
80+
81+ t .Run ("Run with env variable in command line has priority over the one in the env file" , func (t * testing.T ) {
82+ t .Parallel ()
83+
84+ envFile , err := createEnvFile (t .TempDir (), []byte ("CHARACTER=rick_sanchez" ))
85+ defer os .Remove (envFile )
86+ if err != nil {
87+ t .Fatalf ("Failed to write env file: %v" , err )
88+ }
89+
90+ // Set environment variables
91+ envVars := []string {"CHARACTER=morty_smith" }
92+ buff , err := execRunCommand (& envVars , "run" , "--env-file" , envFile , "--" , "printenv" , "CHARACTER" )
93+ if err != nil {
94+ t .Fatal (err .Error ())
95+ }
96+
97+ result , found := findEnvVariableInLogs (& buff )
98+ if ! found {
99+ t .Fatalf ("Expected printenv in the output: %s" , buff .String ())
100+ }
101+ assert .Equal (t , "morty_smith" , result , fmt .Sprintf ("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'" , result ))
102+ })
103+
104+ t .Run ("Run with env variable in local env vars has priority over the one in the env file" , func (t * testing.T ) {
105+ // Do not use t.Parallel() here as we are manipulating the environment!
106+
107+ // Set environment variables
108+ os .Setenv ("CHARACTER" , "morty_smith" )
109+ defer os .Unsetenv ("CHARACTER" )
110+
111+ envFile , err := createEnvFile (t .TempDir (), []byte ("CHARACTER=rick_sanchez" ))
112+ defer os .Remove (envFile )
113+
114+ if err != nil {
115+ t .Fatalf ("Failed to write env file: %v" , err )
116+ }
117+
118+ buff , err := execRunCommand (& []string {}, "run" , "--env-file" , envFile , "--" , "printenv" , "CHARACTER" )
119+ if err != nil {
120+ t .Fatal (err .Error ())
121+ }
122+
123+ result , found := findEnvVariableInLogs (& buff )
124+ if ! found {
125+ t .Fatalf ("Expected printenv in the output: %s\n \n " , buff .String ())
126+ }
127+ assert .Equal (t , "morty_smith" , result , fmt .Sprintf ("Expected 'printenv | morty_smith' in the output, got 'printenv | %s'" , result ))
128+ })
129+ }
125130}
126131
127132func execRunCommand (envVars * []string , arg ... string ) (bytes.Buffer , error ) {
0 commit comments