mirror of https://github.com/nealey/spongy
Fix runsvdir + test
This commit is contained in:
parent
20e7ce8f8a
commit
892e737b80
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue