@@ -26,18 +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- errCode := Run ()
30- os .Exit (errCode )
29+ exitCode := Run ()
30+ os .Exit (int ( exitCode ) )
3131 }
3232 },
3333}
3434
35+ const (
36+ TestPass = iota
37+ TestFail
38+ Aborted
39+ InternalError
40+ BadUsage
41+ NoTests
42+ )
43+
3544func init () {
3645 rootCmd .AddCommand (runCmd )
3746}
3847
3948// Run executes all plugins with handling for the command line
40- func Run () (errCode int ) {
49+ func Run () (exitCode int ) {
4150
4251 // Setup for handling SIGTERM (Ctrl+C)
4352 setupCloseHandler ()
@@ -47,7 +56,7 @@ func Run() (errCode int) {
4756 plugins := GetPlugins ()
4857 if len (plugins ) == 0 {
4958 logger .Error (fmt .Sprintf ("no plugins were requested in config: %s" , viper .GetString ("binaries-path" )))
50- return 5
59+ return NoTests
5160 }
5261
5362 // Run all plugins
@@ -56,8 +65,8 @@ func Run() (errCode int) {
5665 for _ , pluginPkg := range plugins {
5766 if pluginPkg .Name == servicePluginName {
5867 if ! pluginPkg .Available {
59- logger .Error (fmt .Sprintf ("Requested plugin that is not installed: " + pluginPkg .Name ))
60- return 4
68+ logger .Error (fmt .Sprintf ("requested plugin that is not installed: " + pluginPkg .Name ))
69+ return BadUsage
6170 }
6271 client := newClient (pluginPkg .Command )
6372 defer closeClient (pluginPkg , client )
@@ -67,31 +76,29 @@ func Run() (errCode int) {
6776 rpcClient , err := client .Client ()
6877 if err != nil {
6978 logger .Error (fmt .Sprintf ("internal error while initializing RPC client: %s" , err ))
70- return 3
79+ return InternalError
7180 }
7281 // Request the plugin
7382 var rawPlugin interface {}
7483 rawPlugin , err = rpcClient .Dispense (shared .PluginName )
7584 if err != nil {
7685 logger .Error (fmt .Sprintf ("internal error while dispensing RPC client: %s" , err .Error ()))
77- return 3
86+ return InternalError
7887 }
7988 // Execute plugin
8089 plugin := rawPlugin .(shared.Pluginer )
81-
82- // Execute
8390 logger .Trace ("Starting Plugin: " + pluginPkg .Name )
8491 response := plugin .Start ()
8592 if response != nil {
86- pluginPkg .Error = fmt .Errorf ("Error running plugin for %s: %v" , serviceName , response )
87- errCode = 1
93+ pluginPkg .Error = fmt .Errorf ("tests failed in plugin %s: %v" , serviceName , response )
94+ exitCode = TestFail
8895 } else {
8996 pluginPkg .Successful = true
9097 }
9198 }
9299 }
93100 }
94- return
101+ return exitCode
95102}
96103
97104func closeClient (pluginPkg * PluginPkg , client * hcplugin.Client ) {
@@ -115,7 +122,7 @@ func setupCloseHandler() {
115122 go func () {
116123 <- c
117124 logger .Error ("Test execution was aborted by user" )
118- os .Exit (2 )
125+ os .Exit (int ( Aborted ) )
119126 }()
120127}
121128
0 commit comments