Fix runsvdir + test

This commit is contained in:
Neale Pickett 2015-02-11 15:54:23 -07:00
parent 20e7ce8f8a
commit 892e737b80
3 changed files with 18 additions and 9 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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)