1717package executor
1818
1919import (
20- context2 "context"
2120 "fmt"
22- "github.com/devtron-labs/ci-runner/executor/context"
2321 "github.com/devtron-labs/ci-runner/helper"
2422 "io/ioutil"
2523 "os"
@@ -30,8 +28,6 @@ import (
3028
3129func TestRunScripts (t * testing.T ) {
3230 t .SkipNow ()
33- commandExecutorImpl := helper .NewCommandExecutorImpl ()
34- scriptExecutorImpl := NewScriptExecutorImpl (commandExecutorImpl )
3531 type args struct {
3632 workDirectory string
3733 scriptFileName string
@@ -82,8 +78,7 @@ func TestRunScripts(t *testing.T) {
8278 }
8379 for _ , tt := range tests {
8480 t .Run (tt .name , func (t * testing.T ) {
85- ciCtx := context .BuildCiContext (context2 .Background (), false )
86- got , err := scriptExecutorImpl .RunScripts (ciCtx , tt .args .workDirectory , tt .args .scriptFileName , tt .args .script , tt .args .envVars , tt .args .outputVars )
81+ got , err := RunScripts (tt .args .workDirectory , tt .args .scriptFileName , tt .args .script , tt .args .envVars , tt .args .outputVars )
8782 if (err != nil ) != tt .wantErr {
8883 t .Errorf ("RunScripts() error = %v, wantErr %v" , err , tt .wantErr )
8984 return
@@ -197,9 +192,6 @@ func TestRunScriptsInDocker(t *testing.T) {
197192 type args struct {
198193 executionConf * executionConf
199194 }
200- commandExecutorImpl := helper .NewCommandExecutorImpl ()
201- scriptExecutorImpl := NewScriptExecutorImpl (commandExecutorImpl )
202- stageExecutorImpl := NewStageExecutorImpl (commandExecutorImpl , scriptExecutorImpl )
203195 tests := []struct {
204196 name string
205197 args args
@@ -227,8 +219,7 @@ func TestRunScriptsInDocker(t *testing.T) {
227219 }
228220 for _ , tt := range tests {
229221 t .Run (tt .name , func (t * testing.T ) {
230- ciCtx := context .BuildCiContext (context2 .Background (), false )
231- got , err := RunScriptsInDocker (ciCtx , stageExecutorImpl , tt .args .executionConf )
222+ got , err := RunScriptsInDocker (tt .args .executionConf )
232223 if (err != nil ) != tt .wantErr {
233224 t .Errorf ("RunScriptsInDocker() error = %v, wantErr %v" , err , tt .wantErr )
234225 return
@@ -309,91 +300,3 @@ func Test_writeToEnvFile(t *testing.T) {
309300 })
310301 }
311302}
312-
313- func Test_writeToEnvFile1 (t * testing.T ) {
314- type args struct {
315- envMap map [string ]string
316- filename string
317- }
318- tests := []struct {
319- name string
320- args args
321- wantErr bool
322- fileContents []string
323- }{
324- {
325- name : "empty_env_map" ,
326- args : args {envMap : map [string ]string {}, filename : "test1.env" },
327- wantErr : false ,
328- fileContents : []string {},
329- },
330- {
331- name : "single_env_var" ,
332- args : args {envMap : map [string ]string {"FOO" : "BAR" }, filename : "test2.env" },
333- wantErr : false ,
334- fileContents : []string {`FOO="BAR"` },
335- },
336- {
337- name : "multiple_env_vars" ,
338- args : args {envMap : map [string ]string {"FOO" : "BAR" , "BAR" : "FOO" }, filename : "test3.env" },
339- wantErr : false ,
340- fileContents : []string {`FOO="BAR"` , `BAR="FOO"` },
341- },
342- {
343- name : "error_creating_file" ,
344- args : args {envMap : map [string ]string {"FOO" : "BAR" }, filename : "/dev/null/abcd" },
345- wantErr : true ,
346- fileContents : []string {},
347- },
348- {
349- name : "multiline_env_vars" ,
350- args : args {envMap : map [string ]string {"FOO" : "BAR\n \" BAZ\" %%s\n \t \b " , "BAR" : "FOO" }, filename : "test4.env" },
351- wantErr : false ,
352- fileContents : []string {`FOO="BAR\n\"BAZ\"%%s\n\t\b"` , `BAR="FOO"` },
353- },
354- {
355- name : "emoji_env_vars" ,
356- args : args {envMap : map [string ]string {"FOO" : "BA👍R\n \" BAZ\" %%s\n \t \b " , "BAR" : "FOO" }, filename : "test5.env" },
357- wantErr : false ,
358- fileContents : []string {`FOO="BA👍R\n\"BAZ\"%%s\n\t\b"` , `BAR="FOO"` },
359- },
360- {
361- name : "pos_integer_env_vars" ,
362- args : args {envMap : map [string ]string {"FOO" : "1" , "BAR" : "2" }, filename : "test6.env" },
363- wantErr : false ,
364- fileContents : []string {`FOO=1` , `BAR=2` },
365- },
366- {
367- name : "neg_integer_env_vars" ,
368- args : args {envMap : map [string ]string {"FOO" : "-1" , "BAR" : "-2" }, filename : "test7.env" },
369- wantErr : false ,
370- fileContents : []string {`FOO=-1` , `BAR=-2` },
371- },
372- {
373- name : "float_env_vars" ,
374- args : args {envMap : map [string ]string {"FOO" : "1.0" , "BAR" : "2.0" }, filename : "test8.env" },
375- wantErr : false ,
376- fileContents : []string {`FOO="1.0"` , `BAR="2.0"` },
377- },
378- }
379- for _ , tt := range tests {
380- t .Run (tt .name , func (t * testing.T ) {
381- if err := writeToEnvFile (tt .args .envMap , tt .args .filename ); (err != nil ) != tt .wantErr {
382- t .Errorf ("writeToEnvFile() error = %v, wantErr %v" , err , tt .wantErr )
383- }
384- content , err := os .ReadFile (tt .args .filename )
385- if tt .wantErr && err == nil {
386- t .Errorf ("writeToEnvFile(); wanted error = %v; got nil" , err )
387- } else if ! tt .wantErr && err != nil {
388- t .Errorf ("writeToEnvFile(); wanted no error; got = %v" , err )
389- }
390- if err == nil {
391- for _ , line := range tt .fileContents {
392- if ! strings .Contains (string (content ), line ) {
393- t .Errorf ("writeToEnvFile() not found = %v, content = %v" , line , string (content ))
394- }
395- }
396- }
397- })
398- }
399- }
0 commit comments