Looks like it might actually work

This commit is contained in:
Neale Pickett 2015-02-11 13:32:17 -07:00
parent 7c50d82b5e
commit e64bbb6aa2
2 changed files with 30 additions and 11 deletions

View File

@ -31,7 +31,6 @@ func ReadLines(fn string) ([]string, error) {
line := strings.TrimSpace(scanner.Text())
switch {
case line == "":
case line[0] == '#':
default:
lines = append(lines, line)
}

View File

@ -4,6 +4,7 @@ import (
"io/ioutil"
"os"
"path"
"strings"
"testing"
"time"
)
@ -12,22 +13,45 @@ func writeFile(fn string, data string) {
ioutil.WriteFile(fn, []byte(data), os.ModePerm)
}
func createNetwork(t *testing.T) (base string) {
func createNetwork (t *testing.T) (base string, current string) {
base, err := ioutil.TempDir("", "spongy-test")
if err != nil {
t.Fatal(err)
}
writeFile(path.Join(base, "nick"), "spongy_test")
writeFile(path.Join(base, "nick"), "SpongyTest")
writeFile(path.Join(base, "server"), "moo.slashnet.org:6697")
writeFile(path.Join(base, "channels"), "#SpongyTest")
os.Mkdir(path.Join(base, "outq"), os.ModePerm)
os.Mkdir(path.Join(base, "log"), os.ModePerm)
current = path.Join(base, "log", "current")
return
}
func expect(t *testing.T, fpath string, needle string) {
for i := 0; i < 8; i += 1 {
if i > 0 {
time.Sleep(1 * time.Second)
}
fpBytes, err := ioutil.ReadFile(fpath)
if err != nil {
t.Log(err)
time.Sleep(1 * time.Second)
continue
}
fpString := string(fpBytes)
if strings.Contains(fpString, needle) {
return
}
}
t.Errorf("Could not find %#v in %s", needle, fpath)
}
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)
@ -42,7 +66,7 @@ func TestCreateNetwork(t *testing.T) {
}
func TestConnect(t *testing.T) {
base := createNetwork(t)
base, current := createNetwork(t)
defer os.RemoveAll(base)
n := NewNetwork(base)
@ -50,12 +74,8 @@ func TestConnect(t *testing.T) {
time.Sleep(5 * time.Second)
logBytes, err := ioutil.ReadFile(path.Join(base, "log", "current"))
if err != nil {
n.Close()
t.Fatal(err)
}
t.Log("logBytes: ", logBytes)
expect(t, current, " 001 ")
expect(t, current, " JOIN " + n.Nick + " #SpongyTest")
n.Close()
return