This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure FieldValidator methods act on the object we pass in.
Added a unit test for FieldValidator
- Loading branch information
Showing
2 changed files
with
35 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package router | ||
|
||
import ( | ||
wt "github.com/weaveworks/weave/testing" | ||
"testing" | ||
) | ||
|
||
func TestFieldValidator(t *testing.T) { | ||
testMap := map[string]string{"a": "a"} | ||
|
||
fv := NewFieldValidator(testMap) | ||
val, err := fv.Value("a") | ||
wt.AssertNoErr(t, err) | ||
wt.AssertNoErr(t, fv.Err()) | ||
wt.AssertEqualString(t, val, "a", "a") | ||
_, err = fv.Value("x") | ||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Expected error") | ||
_, err = fv.Value("a") | ||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Previous error should be retained") | ||
|
||
fv = NewFieldValidator(testMap) | ||
err = fv.CheckEqual("a", "a") | ||
wt.AssertNoErr(t, err) | ||
wt.AssertNoErr(t, fv.Err()) | ||
err = fv.CheckEqual("a", "b") | ||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Expected error") | ||
err = fv.CheckEqual("a", "a") | ||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Previous error should be retained") | ||
} |