From 96414a56319e23b88d80a7f694b901ed04a278ed Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 27 Jul 2020 13:23:58 +0200 Subject: [PATCH 1/3] Updated sources --- smart_proxy.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/smart_proxy.go b/smart_proxy.go index 39f3a9da..3a176615 100644 --- a/smart_proxy.go +++ b/smart_proxy.go @@ -37,6 +37,10 @@ import ( proxy_content "github.com/RedHatInsights/insights-results-smart-proxy/content" ) +// ExitCode represents numeric value returned to parent process when the +// current process finishes +type ExitCode int + const ( // ExitStatusOK means that the service have finished with success ExitStatusOK = iota @@ -68,13 +72,13 @@ The commands are: var serverInstance *server.HTTPServer // printHelp function displays help on the standard output. -func printHelp() int { +func printHelp() ExitCode { fmt.Printf(helpMessageTemplate, os.Args[0]) return ExitStatusOK } // printConfig function displays loaded configuration on the standard output. -func printConfig() int { +func printConfig() ExitCode { configBytes, err := json.MarshalIndent(conf.Config, "", " ") if err != nil { @@ -89,7 +93,7 @@ func printConfig() int { } // printEnv function prints all environment variables to standard output. -func printEnv() int { +func printEnv() ExitCode { for _, keyVal := range os.Environ() { fmt.Println(keyVal) } @@ -98,7 +102,7 @@ func printEnv() int { } // startService function starts service and returns error code. -func startServer() int { +func startServer() ExitCode { _ = conf.GetSetupConfiguration() serverCfg := conf.GetServerConfiguration() metricsCfg := conf.GetMetricsConfiguration() @@ -153,7 +157,7 @@ func updateGroupInfo(servicesConf services.Configuration, groupsChannel chan []g } // handleCommand select the function to be called depending on command argument -func handleCommand(command string) int { +func handleCommand(command string) ExitCode { switch command { case "start-service": return startServer() @@ -195,7 +199,7 @@ func main() { flag.Parse() if showHelp { - os.Exit(printHelp()) + os.Exit(int(printHelp())) } if showVersion { @@ -210,5 +214,5 @@ func main() { command = strings.ToLower(strings.TrimSpace(args[0])) } - os.Exit(handleCommand(command)) + os.Exit(int(handleCommand(command))) } From c025af2e130c1d193ff63a8f2ab637876827703d Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 27 Jul 2020 13:24:06 +0200 Subject: [PATCH 2/3] Updated unit tests as well --- smart_proxy_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smart_proxy_test.go b/smart_proxy_test.go index 0ad75d18..6df31505 100644 --- a/smart_proxy_test.go +++ b/smart_proxy_test.go @@ -72,15 +72,15 @@ func TestPrintVersionInfo(t *testing.T) { // TestPrintHelp checks that printing help returns OK exit code. func TestPrintHelp(t *testing.T) { - assert.Equal(t, main.ExitStatusOK, main.PrintHelp()) + assert.Equal(t, main.ExitStatusOK, int(main.PrintHelp())) } // TestPrintConfig checks that printing configuration info returns OK exit code. func TestPrintConfig(t *testing.T) { - assert.Equal(t, main.ExitStatusOK, main.PrintConfig()) + assert.Equal(t, main.ExitStatusOK, int(main.PrintConfig())) } // TestPrintEnv checks that printing environment variables returns OK exit code. func TestPrintEnv(t *testing.T) { - assert.Equal(t, main.ExitStatusOK, main.PrintEnv()) + assert.Equal(t, main.ExitStatusOK, int(main.PrintEnv())) } From 91b06ebde00c4702d9ba689f3ec4c62b8ae9dfca Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 27 Jul 2020 13:24:56 +0200 Subject: [PATCH 3/3] Updated generated documentation --- docs/packages/smart_proxy.html | 23 ++++++++++++++++------- docs/packages/smart_proxy_test.html | 6 +++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docs/packages/smart_proxy.html b/docs/packages/smart_proxy.html index bd68d8d6..61714c07 100644 --- a/docs/packages/smart_proxy.html +++ b/docs/packages/smart_proxy.html @@ -161,6 +161,15 @@
proxy_content
"github.com/RedHatInsights/insights-results-smart-proxy/content"
)
+ + + + +

ExitCode represents numeric value returned to parent process when the +current process finishes

+ +
type
ExitCode
int
+
const
(
@@ -212,7 +221,7 @@

printHelp function displays help on the standard output.

-
func
printHelp
(
)
int
{
+
func
printHelp
(
)
ExitCode
{
fmt
.
Printf
(
helpMessageTemplate
,
os
.
Args
[
0
]
)
return
ExitStatusOK
}
@@ -223,7 +232,7 @@

printConfig function displays loaded configuration on the standard output.

-
func
printConfig
(
)
int
{
+
func
printConfig
(
)
ExitCode
{
configBytes
,
err
:=
json
.
MarshalIndent
(
conf
.
Config
,
""
,
" "
)
if
err
!=
nil
{
@@ -248,7 +257,7 @@

printEnv function prints all environment variables to standard output.

-
func
printEnv
(
)
int
{
+
func
printEnv
(
)
ExitCode
{
for
_
,
keyVal
:=
range
os
.
Environ
(
)
{
fmt
.
Println
(
keyVal
)
}
@@ -262,7 +271,7 @@

startService function starts service and returns error code.

-
func
startServer
(
)
int
{
+
func
startServer
(
)
ExitCode
{
_
=
conf
.
GetSetupConfiguration
(
)
serverCfg
:=
conf
.
GetServerConfiguration
(
)
metricsCfg
:=
conf
.
GetMetricsConfiguration
(
)
@@ -327,7 +336,7 @@

handleCommand select the function to be called depending on command argument

-
func
handleCommand
(
command
string
)
int
{
+
func
handleCommand
(
command
string
)
ExitCode
{
switch
command
{
case
"start-service"
:
return
startServer
(
)
@@ -374,7 +383,7 @@
flag
.
Parse
(
)
if
showHelp
{
-
os
.
Exit
(
printHelp
(
)
)
+
os
.
Exit
(
int
(
printHelp
(
)
)
)
}
if
showVersion
{
@@ -389,7 +398,7 @@
command
=
strings
.
ToLower
(
strings
.
TrimSpace
(
args
[
0
]
)
)
}
-
os
.
Exit
(
handleCommand
(
command
)
)
+
os
.
Exit
(
int
(
handleCommand
(
command
)
)
)
}
diff --git a/docs/packages/smart_proxy_test.html b/docs/packages/smart_proxy_test.html index 8f091e04..fa635a66 100644 --- a/docs/packages/smart_proxy_test.html +++ b/docs/packages/smart_proxy_test.html @@ -206,7 +206,7 @@

TestPrintHelp checks that printing help returns OK exit code.

func
TestPrintHelp
(
t
*
testing
.
T
)
{
-
assert
.
Equal
(
t
,
main
.
ExitStatusOK
,
main
.
PrintHelp
(
)
)
+
assert
.
Equal
(
t
,
main
.
ExitStatusOK
,
int
(
main
.
PrintHelp
(
)
)
)
}
@@ -216,7 +216,7 @@

TestPrintConfig checks that printing configuration info returns OK exit code.

func
TestPrintConfig
(
t
*
testing
.
T
)
{
-
assert
.
Equal
(
t
,
main
.
ExitStatusOK
,
main
.
PrintConfig
(
)
)
+
assert
.
Equal
(
t
,
main
.
ExitStatusOK
,
int
(
main
.
PrintConfig
(
)
)
)
}
@@ -226,7 +226,7 @@

TestPrintEnv checks that printing environment variables returns OK exit code.

func
TestPrintEnv
(
t
*
testing
.
T
)
{
-
assert
.
Equal
(
t
,
main
.
ExitStatusOK
,
main
.
PrintEnv
(
)
)
+
assert
.
Equal
(
t
,
main
.
ExitStatusOK
,
int
(
main
.
PrintEnv
(
)
)
)
}