@@ -3,6 +3,7 @@ package scheduler_test
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "os/exec"
89 "strings"
@@ -32,37 +33,37 @@ func TestShellCommand(t *testing.T) {
3233
3334 mock , err := pgxmock .NewPool () //
3435 assert .NoError (t , err )
35- pge := pgengine .NewDB (mock , "scheduler_unit_test " )
36- scheduler := scheduler .New (pge , log .Init (config.LoggingOpts {LogLevel : "panic" , LogDBLevel : "none" }))
36+ pge := pgengine .NewDB (mock , "--log-database-level=none " )
37+ sch := scheduler .New (pge , log .Init (config.LoggingOpts {LogLevel : "panic" , LogDBLevel : "none" }))
3738 ctx := context .Background ()
3839
39- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {}, []string {"" })
40+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {}, []string {"" })
4041 assert .EqualError (t , err , "program command cannot be empty" , "Empty command should out, fail" )
4142
42- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping0" }, nil )
43+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping0" }, nil )
4344 assert .NoError (t , err , "Command with nil param is out, OK" )
4445
45- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping1" }, []string {})
46+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping1" }, []string {})
4647 assert .NoError (t , err , "Command with empty array param is OK" )
4748
48- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping2" }, []string {"" })
49+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping2" }, []string {"" })
4950 assert .NoError (t , err , "Command with empty string param is OK" )
5051
51- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping3" }, []string {"[]" })
52+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping3" }, []string {"[]" })
5253 assert .NoError (t , err , "Command with empty json array param is OK" )
5354
54- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping3" }, []string {"[null]" })
55+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping3" }, []string {"[null]" })
5556 assert .NoError (t , err , "Command with nil array param is OK" )
5657
57- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping4" }, []string {`["localhost"]` })
58+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping4" }, []string {`["localhost"]` })
5859 assert .NoError (t , err , "Command with one param is OK" )
5960
60- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping5" }, []string {`["localhost", "-4"]` })
61+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping5" }, []string {`["localhost", "-4"]` })
6162 assert .NoError (t , err , "Command with many params is OK" )
6263
63- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "pong" }, nil )
64- assert .IsType (t , ( * exec .Error )( nil ), err , "Uknown command should produce error " )
64+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "pong" }, nil )
65+ assert .True (t , errors . Is ( err , exec .ErrNotFound ), "Unknown command should produce exec.Error " )
6566
66- err = scheduler .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping5" }, []string {`{"param1": "localhost"}` })
67- assert .IsType (t , (* json .UnmarshalTypeError )(nil ), err , "Command should fail with mailformed json parameter" )
67+ err = sch .ExecuteProgramCommand (ctx , & pgengine.ChainTask {Command : "ping5" }, []string {`{"param1": "localhost"}` })
68+ assert .IsType (t , (* json .UnmarshalTypeError )(nil ), err , "Command should fail with malformed json parameter" )
6869}
0 commit comments