From 19148eba44d6597363fcfd74596f4de02a63a3b0 Mon Sep 17 00:00:00 2001 From: Dipen Patel Date: Sat, 31 Oct 2015 10:48:25 -0400 Subject: [PATCH 1/2] wrote startupshutdown tests and added OncePerServerBlock value in the NewTestController function of the controller.go file --- config/setup/controller.go | 3 ++ config/setup/startupshutdown_test.go | 58 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 config/setup/startupshutdown_test.go diff --git a/config/setup/controller.go b/config/setup/controller.go index 04873082..3890ab44 100644 --- a/config/setup/controller.go +++ b/config/setup/controller.go @@ -58,6 +58,9 @@ func NewTestController(input string) *Controller { Root: ".", }, Dispenser: parse.NewDispenser("Testfile", strings.NewReader(input)), + OncePerServerBlock: func(f func() error) error { + return f() + }, } } diff --git a/config/setup/startupshutdown_test.go b/config/setup/startupshutdown_test.go new file mode 100644 index 00000000..d79a000d --- /dev/null +++ b/config/setup/startupshutdown_test.go @@ -0,0 +1,58 @@ +package setup + +import ( + "os" + "os/exec" + "path/filepath" + "strconv" + "testing" + "time" +) + +// The Startup function's tests are symmetrical to Shutdown tests, +// because the Startup and Shutdown functions share virtually the +// same functionality +func TestStartup(t *testing.T) { + + tempDirPath, err := getTempDirPath() + if err != nil { + t.Fatalf("BeforeTest: Failed to find an existing directory for testing! Error was: %v", err) + } + + testDir := filepath.Join(tempDirPath, "temp_dir_for_testing_startupshutdown.go") + osSenitiveTestDir := filepath.FromSlash(testDir) + + exec.Command("rm", "-r", osSenitiveTestDir).Start() // removes osSenitiveTestDir from the OS's temp directory, if the osSenitiveTestDir already exists + + tests := []struct { + input string + shouldExecutionErr bool + shouldRemoveErr bool + }{ + // test case #0 tests proper functionality blocking commands + {"startup mkdir " + osSenitiveTestDir, false, false}, + + // test case #1 tests proper functionality of non-blocking commands + {"startup mkdir " + osSenitiveTestDir, false, true}, + + // test case #2 tests handling of non-existant commands + {"startup " + strconv.Itoa(int(time.Now().UnixNano())), true, true}, + } + + for i, test := range tests { + c := NewTestController(test.input) + _, err = Startup(c) + if err != nil { + t.Errorf("Expected no errors, got: %v", err) + } + err = c.Startup[0]() + if err != nil && !test.shouldExecutionErr { + t.Errorf("Test %d recieved an error of:\n%v", i, err) + } + err = os.Remove(osSenitiveTestDir) + if err != nil && !test.shouldRemoveErr { + t.Errorf("Test %d recieved an error of:\n%v", i, err) + } + + } +} From 78d857a374350edc275bcf47df040a24b3ec53ff Mon Sep 17 00:00:00 2001 From: Dipen Patel Date: Sat, 31 Oct 2015 12:33:50 -0400 Subject: [PATCH 2/2] debugged startupshutdown.go --- config/setup/startupshutdown_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/setup/startupshutdown_test.go b/config/setup/startupshutdown_test.go index d79a000d..cf07a7e8 100644 --- a/config/setup/startupshutdown_test.go +++ b/config/setup/startupshutdown_test.go @@ -22,7 +22,7 @@ func TestStartup(t *testing.T) { testDir := filepath.Join(tempDirPath, "temp_dir_for_testing_startupshutdown.go") osSenitiveTestDir := filepath.FromSlash(testDir) - exec.Command("rm", "-r", osSenitiveTestDir).Start() // removes osSenitiveTestDir from the OS's temp directory, if the osSenitiveTestDir already exists + exec.Command("rm", "-r", osSenitiveTestDir).Run() // removes osSenitiveTestDir from the OS's temp directory, if the osSenitiveTestDir already exists tests := []struct { input string @@ -33,7 +33,7 @@ func TestStartup(t *testing.T) { {"startup mkdir " + osSenitiveTestDir, false, false}, // test case #1 tests proper functionality of non-blocking commands - {"startup mkdir " + osSenitiveTestDir, false, true}, + {"startup mkdir " + osSenitiveTestDir + " &", false, true}, // test case #2 tests handling of non-existant commands {"startup " + strconv.Itoa(int(time.Now().UnixNano())), true, true},