Skip to content

Commit

Permalink
More robust test for ParseConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnugget committed Mar 27, 2013
1 parent 9a8836d commit 62ba917
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ import (
"testing"
)

var parseTests = []struct {
index int
expectedPath string
expectedRun string
}{
{
0,
"/tmp/foo",
"/usr/local/bar/foobar",
type expectedRule map[string]string

var expectedRules = map[string]expectedRule{
"/tmp/foo": map[string]string{
"run": "/usr/local/bar/foobar",
},
{
1,
"/tmp/bar",
"/usr/local/bar/barfoo",
"/tmp/bar": map[string]string{
"run": "/usr/local/bar/barfoo",
},
}

Expand All @@ -26,17 +20,16 @@ func TestParseConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(rules) != 2 {
t.Fatal("Did not include all rules")
}

for _, pt := range parseTests {
actualPath := rules[pt.index].Path
actualRun := rules[pt.index].Run

if actualPath != pt.expectedPath && actualRun != pt.expectedRun {
t.Errorf("ACTUALPATH %v - EXPECTEDPATH %v, ACTUALRUN %v - EXPECTEDRUN %v", actualPath, pt.expectedPath, actualRun, pt.expectedRun)
for _, rule := range rules {
expected, ok := expectedRules[rule.Path]
if !ok {
t.Error("Rule not found")
continue
}
if rule.Run != expected["run"] {
t.Error("Wrong Run. Expected: %v Actual: %v", expected["run"],
rule.Run)
}
}
}

0 comments on commit 62ba917

Please sign in to comment.