diff options
Diffstat (limited to 'config_test.go')
-rw-r--r-- | config_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..bcb9e5f --- /dev/null +++ b/config_test.go @@ -0,0 +1,51 @@ +package main + +import ( + "bytes" + "testing" +) + +func TestConfig(t *testing.T) { + cases := []struct { + Config string + Tests map[string]string + }{ + { + Config: ` +# Comment +go.universe.tf 1.2.3.4 +*.universe.tf 2.3.4.5 +# Comment +google.* 3.4.5.6 +/gooo+gle\.com/ 4.5.6.7 +`, + Tests: map[string]string{ + "go.universe.tf": "1.2.3.4", + "foo.universe.tf": "2.3.4.5", + "bar.universe.tf": "2.3.4.5", + "google.com": "3.4.5.6", + "google.fr": "3.4.5.6", + "goooooooooogle.com": "4.5.6.7", + + "blah.com": "", + "google.com.br": "", + "foo.bar.universe.tf": "", + "goooooglexcom": "", + }, + }, + } + + for _, test := range cases { + var cfg Config + if err := cfg.Read(bytes.NewBufferString(test.Config)); err != nil { + t.Fatalf("Failed to read config (%s):\n%q", err, test.Config) + } + + for hostname, expected := range test.Tests { + actual := cfg.Match(hostname) + if expected != actual { + t.Errorf("cfg.Match(%q) is %q, want %q", hostname, actual, expected) + } + } + } +} |