From 892e737b8052cd2b518be73259b957d88ffec332 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 11 Feb 2015 15:54:23 -0700 Subject: [PATCH] Fix runsvdir + test --- spongy/network_test.go | 8 ++++---- spongy/spongy.go | 3 ++- spongy/spongy_test.go | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/spongy/network_test.go b/spongy/network_test.go index a0ce822..b45d23f 100644 --- a/spongy/network_test.go +++ b/spongy/network_test.go @@ -13,8 +13,8 @@ func writeFile(fn string, data string) { ioutil.WriteFile(fn, []byte(data), os.ModePerm) } -func createNetwork (t *testing.T) (base string, current string) { - base, err := ioutil.TempDir("", "spongy-test") +func createNetwork (t *testing.T, parent string) (base string, current string) { + base, err := ioutil.TempDir(parent, "spongy-test") if err != nil { t.Fatal(err) } @@ -51,7 +51,7 @@ func expect(t *testing.T, fpath string, needle string) { } func TestCreateNetwork(t *testing.T) { - base, _ := createNetwork(t) + base, _ := createNetwork(t, "") if fi, err := os.Stat(path.Join(base, "nick")); err != nil { t.Error(err) @@ -66,7 +66,7 @@ func TestCreateNetwork(t *testing.T) { } func TestConnect(t *testing.T) { - base, current := createNetwork(t) + base, current := createNetwork(t, "") defer os.RemoveAll(base) n := NewNetwork(base) diff --git a/spongy/spongy.go b/spongy/spongy.go index 54593cf..c3fb86d 100644 --- a/spongy/spongy.go +++ b/spongy/spongy.go @@ -38,11 +38,12 @@ func runsvdir(dirname string) { found := make(map[string]bool) for _, fn := range dn { fpath := path.Join(dirname, fn) + log.Print("Considering", fpath) if exists(path.Join(fpath, "down")) { continue } if _, ok := services[fpath]; ! ok { - if ! exists(path.Join(fpath, "servers")) { + if ! exists(path.Join(fpath, "server")) { continue } diff --git a/spongy/spongy_test.go b/spongy/spongy_test.go index a615f3f..e034259 100644 --- a/spongy/spongy_test.go +++ b/spongy/spongy_test.go @@ -1,22 +1,30 @@ package main import ( + "io/ioutil" "os" "path" "testing" ) -func setupRunSpongy(t *testing.T, baseChan chan<- string) { - base, _ := createNetwork(t) +func setupRunSpongy(t *testing.T, parent string, baseChan chan<- string) { + base, _ := createNetwork(t, parent) baseChan <- base close(baseChan) - runsvdir(base) + runsvdir(parent) os.RemoveAll(base) } func TestRunsvdir(t *testing.T) { + parent, err := ioutil.TempDir("", "spongy-test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(parent) + baseChan := make(chan string) - go setupRunSpongy(t, baseChan) + go setupRunSpongy(t, parent, baseChan) + base := <- baseChan expect(t, path.Join(base, "log", "current"), " 001 ") os.RemoveAll(base)