@@ -26,17 +26,27 @@ When everything is battoned down, it is time to run forth.`,
2626 logger .Error (fmt .Sprintf (
2727 "Unknown args: %v" , args ))
2828 } else {
29- Run ()
29+ exitCode := Run ()
30+ os .Exit (int (exitCode ))
3031 }
3132 },
3233}
3334
35+ const (
36+ TestPass = iota
37+ TestFail
38+ Aborted
39+ InternalError
40+ BadUsage
41+ NoTests
42+ )
43+
3444func init () {
3545 rootCmd .AddCommand (runCmd )
3646}
3747
3848// Run executes all plugins with handling for the command line
39- func Run () (err error ) {
49+ func Run () (exitCode int ) {
4050
4151 // Setup for handling SIGTERM (Ctrl+C)
4252 setupCloseHandler ()
@@ -45,8 +55,8 @@ func Run() (err error) {
4555
4656 plugins := GetPlugins ()
4757 if len (plugins ) == 0 {
48- logger .Error ("no requested plugins were found in " + viper .GetString ("binaries-path" ))
49- return
58+ logger .Error (fmt . Sprintf ( "no plugins were requested in config: %s" , viper .GetString ("binaries-path" ) ))
59+ return NoTests
5060 }
5161
5262 // Run all plugins
@@ -55,39 +65,40 @@ func Run() (err error) {
5565 for _ , pluginPkg := range plugins {
5666 if pluginPkg .Name == servicePluginName {
5767 if ! pluginPkg .Available {
58- logger .Error ("Requested plugin that is not installed: " + pluginPkg .Name )
59- continue
68+ logger .Error (fmt . Sprintf ( "requested plugin that is not installed: " + pluginPkg .Name ) )
69+ return BadUsage
6070 }
6171 client := newClient (pluginPkg .Command )
6272 defer closeClient (pluginPkg , client )
6373
6474 // Connect via RPC
6575 var rpcClient hcplugin.ClientProtocol
66- rpcClient , err = client .Client ()
76+ rpcClient , err : = client .Client ()
6777 if err != nil {
68- return err
78+ logger .Error (fmt .Sprintf ("internal error while initializing RPC client: %s" , err ))
79+ return InternalError
6980 }
7081 // Request the plugin
7182 var rawPlugin interface {}
7283 rawPlugin , err = rpcClient .Dispense (shared .PluginName )
7384 if err != nil {
74- logger .Error (err .Error ())
85+ logger .Error (fmt .Sprintf ("internal error while dispensing RPC client: %s" , err .Error ()))
86+ return InternalError
7587 }
7688 // Execute plugin
7789 plugin := rawPlugin .(shared.Pluginer )
78-
79- // Execute
8090 logger .Trace ("Starting Plugin: " + pluginPkg .Name )
8191 response := plugin .Start ()
8292 if response != nil {
83- pluginPkg .Error = fmt .Errorf ("Error running plugin for %s: %v" , serviceName , response )
93+ pluginPkg .Error = fmt .Errorf ("tests failed in plugin %s: %v" , serviceName , response )
94+ exitCode = TestFail
8495 } else {
8596 pluginPkg .Successful = true
8697 }
8798 }
8899 }
89100 }
90- return
101+ return exitCode
91102}
92103
93104func closeClient (pluginPkg * PluginPkg , client * hcplugin.Client ) {
@@ -110,8 +121,8 @@ func setupCloseHandler() {
110121 signal .Notify (c , os .Interrupt , syscall .SIGTERM )
111122 go func () {
112123 <- c
113- logger .Error ("Execution aborted - SIGTERM " )
114- os .Exit (0 )
124+ logger .Error ("Test execution was aborted by user " )
125+ os .Exit (int ( Aborted ) )
115126 }()
116127}
117128
0 commit comments