| 1 |
package chaos |
| 2 |
|
| 3 |
import ( |
| 4 |
"slices" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/dnsserver" |
| 8 |
) |
| 9 |
|
| 10 |
func TestSetup(t *testing.T) { |
| 11 |
testcases := []struct { |
| 12 |
input string |
| 13 |
exp *Chaos |
| 14 |
}{ |
| 15 |
{`chaos bla`, &Chaos{Version: "bla"}}, |
| 16 |
{`chaos { |
| 17 |
authors { |
| 18 |
aaa |
| 19 |
bbb |
| 20 |
} |
| 21 |
}`, &Chaos{Version: Version, Authors: []string{"aaa", "bbb"}}}, |
| 22 |
{`chaos { |
| 23 |
authors { |
| 24 |
} |
| 25 |
}`, &Chaos{Version: Version, Authors: []string{}}}, |
| 26 |
} |
| 27 |
for i, tc := range testcases { |
| 28 |
chaos := new(Chaos) |
| 29 |
co := dnsserver.NewTestController(tc.input) |
| 30 |
err := chaos.Setup(co) |
| 31 |
if err != nil { |
| 32 |
t.Fatal(err) |
| 33 |
} |
| 34 |
|
| 35 |
if tc.exp.Version != chaos.Version { |
| 36 |
t.Errorf("test %d: expected %s, got %s", i, tc.exp.Version, chaos.Version) |
| 37 |
} |
| 38 |
if slices.Compare(tc.exp.Authors, chaos.Authors) != 0 { |
| 39 |
t.Errorf("test %d: expected %v, got %v", i, tc.exp.Authors, chaos.Authors) |
| 40 |
} |
| 41 |
} |
| 42 |
} |