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)
|
ioutil.WriteFile(fn, []byte(data), os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNetwork (t *testing.T) (base string, current string) {
|
func createNetwork (t *testing.T, parent string) (base string, current string) {
|
||||||
base, err := ioutil.TempDir("", "spongy-test")
|
base, err := ioutil.TempDir(parent, "spongy-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func expect(t *testing.T, fpath string, needle string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateNetwork(t *testing.T) {
|
func TestCreateNetwork(t *testing.T) {
|
||||||
base, _ := createNetwork(t)
|
base, _ := createNetwork(t, "")
|
||||||
|
|
||||||
if fi, err := os.Stat(path.Join(base, "nick")); err != nil {
|
if fi, err := os.Stat(path.Join(base, "nick")); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -66,7 +66,7 @@ func TestCreateNetwork(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnect(t *testing.T) {
|
func TestConnect(t *testing.T) {
|
||||||
base, current := createNetwork(t)
|
base, current := createNetwork(t, "")
|
||||||
defer os.RemoveAll(base)
|
defer os.RemoveAll(base)
|
||||||
|
|
||||||
n := NewNetwork(base)
|
n := NewNetwork(base)
|
||||||
|
|
|
@ -38,11 +38,12 @@ func runsvdir(dirname string) {
|
||||||
found := make(map[string]bool)
|
found := make(map[string]bool)
|
||||||
for _, fn := range dn {
|
for _, fn := range dn {
|
||||||
fpath := path.Join(dirname, fn)
|
fpath := path.Join(dirname, fn)
|
||||||
|
log.Print("Considering", fpath)
|
||||||
if exists(path.Join(fpath, "down")) {
|
if exists(path.Join(fpath, "down")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, ok := services[fpath]; ! ok {
|
if _, ok := services[fpath]; ! ok {
|
||||||
if ! exists(path.Join(fpath, "servers")) {
|
if ! exists(path.Join(fpath, "server")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,30 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupRunSpongy(t *testing.T, baseChan chan<- string) {
|
func setupRunSpongy(t *testing.T, parent string, baseChan chan<- string) {
|
||||||
base, _ := createNetwork(t)
|
base, _ := createNetwork(t, parent)
|
||||||
baseChan <- base
|
baseChan <- base
|
||||||
close(baseChan)
|
close(baseChan)
|
||||||
runsvdir(base)
|
runsvdir(parent)
|
||||||
os.RemoveAll(base)
|
os.RemoveAll(base)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunsvdir(t *testing.T) {
|
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)
|
baseChan := make(chan string)
|
||||||
go setupRunSpongy(t, baseChan)
|
go setupRunSpongy(t, parent, baseChan)
|
||||||
|
|
||||||
base := <- baseChan
|
base := <- baseChan
|
||||||
expect(t, path.Join(base, "log", "current"), " 001 ")
|
expect(t, path.Join(base, "log", "current"), " 001 ")
|
||||||
os.RemoveAll(base)
|
os.RemoveAll(base)
|
||||||
|
|
Loading…
Reference in New Issue