From 8deec17f734a2211eef9318dabeb3db9e522c310 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 1 Feb 2016 16:42:04 -0800 Subject: [PATCH 1/4] Use panic instead of returning a sentinel UUID values in unit tests --- command/agent/remote_exec_test.go | 3 ++- consul/fsm_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/command/agent/remote_exec_test.go b/command/agent/remote_exec_test.go index 3b61550b86..c72748de0d 100644 --- a/command/agent/remote_exec_test.go +++ b/command/agent/remote_exec_test.go @@ -3,6 +3,7 @@ package agent import ( "bytes" "encoding/json" + "fmt" "os" "reflect" "testing" @@ -16,7 +17,7 @@ import ( func generateUUID() (ret string) { var err error if ret, err = uuid.GenerateUUID(); err != nil { - return "DEADC0DE-BADD-CAFE-D00D-FEEDFACECAFE" + panic(fmt.Sprintf("Unable to generate a UUID, %v", err)) } return ret } diff --git a/consul/fsm_test.go b/consul/fsm_test.go index 97f5baf231..e9ba05e151 100644 --- a/consul/fsm_test.go +++ b/consul/fsm_test.go @@ -2,6 +2,7 @@ package consul import ( "bytes" + "fmt" "os" "reflect" "testing" @@ -43,7 +44,7 @@ func makeLog(buf []byte) *raft.Log { func generateUUID() (ret string) { var err error if ret, err = uuid.GenerateUUID(); err != nil { - return "DEADC0DE-BADD-CAFE-D00D-FEEDFACECAFE" + panic(fmt.Sprintf("Unable to generate a UUID, %v", err)) } return ret } From 6c1bb78d06ac395730aff0ec708e476f95fef79e Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 1 Feb 2016 22:26:57 -0800 Subject: [PATCH 2/4] Cull unused function and its unit test. Pointed out by: @slackpad --- lib/string.go | 8 -------- lib/string_test.go | 9 --------- 2 files changed, 17 deletions(-) diff --git a/lib/string.go b/lib/string.go index f37296b76a..e9f1280c7c 100644 --- a/lib/string.go +++ b/lib/string.go @@ -13,11 +13,3 @@ func StrContains(l []string, s string) bool { } return false } - -func ToLowerList(l []string) []string { - var out []string - for _, value := range l { - out = append(out, strings.ToLower(value)) - } - return out -} diff --git a/lib/string_test.go b/lib/string_test.go index f17bd90d11..e03541011b 100644 --- a/lib/string_test.go +++ b/lib/string_test.go @@ -13,12 +13,3 @@ func TestStrContains(t *testing.T) { t.Fatalf("should not contain") } } - -func TestToLowerList(t *testing.T) { - l := []string{"ABC", "Abc", "abc"} - for _, value := range ToLowerList(l) { - if value != "abc" { - t.Fatalf("failed lowercasing") - } - } -} From 81e1e1c05d622dd2e019066fbde9d4a86b1cb652 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 1 Feb 2016 22:26:57 -0800 Subject: [PATCH 3/4] Cull unused function and its unit test. Pointed out by: @slackpad --- lib/string.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/string.go b/lib/string.go index e9f1280c7c..0780abb632 100644 --- a/lib/string.go +++ b/lib/string.go @@ -1,9 +1,5 @@ package lib -import ( - "strings" -) - // StrContains checks if a list contains a string func StrContains(l []string, s string) bool { for _, v := range l { From 8cb5b4dbeb663fa2bf6c6a9dd61d3cc929fdd0ed Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 1 Feb 2016 22:48:59 -0800 Subject: [PATCH 4/4] Chase case change in the function name now that GenerateUUID is an exported function. --- scripts/verify_no_uuid.sh | 4 ++-- scripts/windows/verify_no_uuid.bat | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/verify_no_uuid.sh b/scripts/verify_no_uuid.sh index 5f67ef14d6..72ad7daf7a 100755 --- a/scripts/verify_no_uuid.sh +++ b/scripts/verify_no_uuid.sh @@ -1,12 +1,12 @@ #!/bin/bash -grep generateUUID consul/state/state_store.go +grep GenerateUUID consul/state/state_store.go RESULT=$? if [ $RESULT -eq 0 ]; then exit 1 fi -grep generateUUID consul/fsm.go +grep GenerateUUID consul/fsm.go RESULT=$? if [ $RESULT -eq 0 ]; then exit 1 diff --git a/scripts/windows/verify_no_uuid.bat b/scripts/windows/verify_no_uuid.bat index a1d5b8ec4a..c778a19d01 100644 --- a/scripts/windows/verify_no_uuid.bat +++ b/scripts/windows/verify_no_uuid.bat @@ -5,10 +5,10 @@ setlocal if not exist %1\consul\state\state_store.go exit /B 1 if not exist %1\consul\fsm.go exit /B 1 -findstr /R generateUUID %1\consul\state\state_store.go 1>nul +findstr /R GenerateUUID %1\consul\state\state_store.go 1>nul if not %ERRORLEVEL% EQU 1 exit /B 1 -findstr generateUUID %1\consul\fsm.go 1>nul +findstr GenerateUUID %1\consul\fsm.go 1>nul if not %ERRORLEVEL% EQU 1 exit /B 1 exit /B 0