-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for peerlog config parsing
- Loading branch information
Showing
2 changed files
with
70 additions
and
17 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,49 @@ | ||
package peerlog | ||
|
||
import "testing" | ||
|
||
func TestExtractEnabled(t *testing.T) { | ||
for _, c := range []struct { | ||
name string | ||
config interface{} | ||
expected bool | ||
}{ | ||
{ | ||
name: "nil config returns false", | ||
config: nil, | ||
expected: false, | ||
}, | ||
{ | ||
name: "returns false when config is not a string map", | ||
config: 1, | ||
expected: false, | ||
}, | ||
{ | ||
name: "returns false when config has no Enabled field", | ||
config: map[string]interface{}{}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "returns false when config has a null Enabled field", | ||
config: map[string]interface{}{"Enabled": nil}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "returns false when config has a non-boolean Enabled field", | ||
config: map[string]interface{}{"Enabled": 1}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "returns the vlaue of the Enabled field", | ||
config: map[string]interface{}{"Enabled": true}, | ||
expected: true, | ||
}, | ||
} { | ||
t.Run(c.name, func(t *testing.T) { | ||
isEnabled := extractEnabled(c.config) | ||
if isEnabled != c.expected { | ||
t.Fatalf("expected %v, got %v", c.expected, isEnabled) | ||
} | ||
}) | ||
} | ||
} |