Feature complete. I may change the names, and error-handling needs to be more robust. I feel pretty good about resisting bad input, but not so good about saving to or writing from complex data structures, or maps with interface{} elements.

This commit is contained in:
David Arroyo
2013-07-15 10:16:10 -04:00
parent a19bd721cd
commit 10567f459b
6 changed files with 375 additions and 181 deletions

View File

@@ -0,0 +1,53 @@
package ndb
import (
"testing"
)
var structWriteTests = []struct {
in netCfg
out string
}{
{
netCfg{"p2-jbs239", []int{64, 52, 100}, 666},
"host-name=p2-jbs239 vlan=64 vlan=52 vlan=100 native-vlan=666",
},
{
netCfg{"p2-cass304", []int{55, 10}, 1},
"host-name=p2-cass304 vlan=55 vlan=10 native-vlan=1",
},
}
var mapWriteTests = []struct {
in map[string] string
out string
}{
{
map[string] string {"user": "jenkins", "group": "jenkins"},
"user=jenkins group=jenkins",
},
}
func TestStructWrite(t *testing.T) {
for _, tt := range structWriteTests {
if b, err := Emit(tt.in); err != nil {
t.Error(err)
} else if string(b) != tt.out {
t.Errorf("Wanted %s, got %s", tt.out, string(b))
} else {
t.Logf("%v => %s", tt.in, string(b))
}
}
}
func TestMapWrite(t *testing.T) {
for _, tt := range mapWriteTests {
if b, err := Emit(tt.in); err != nil {
t.Error(err)
} else if string(b) != tt.out {
t.Errorf("Wanted %s, got %s", tt.out, string(b))
} else {
t.Logf("%v => %s", tt.in, string(b))
}
}
}