Skip to content

Commit

Permalink
add getBoolParam func into plugin to support bollean config
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Zhang <[email protected]>
  • Loading branch information
DrewZhang13 committed Mar 5, 2021
1 parent a8d4217 commit b9411fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,14 @@ func contains(s []string, e string) bool {
}
return false
}

func getBoolParam(param string, defaultVal bool) bool {
val := strings.ToLower(param)
if val == "true" {
return true
} else if val == "false" {
return false
} else {
return defaultVal
}
}
9 changes: 9 additions & 0 deletions plugins/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ func TestDataKeys(t *testing.T) {
assert.Equal(t, record["pudding"], "is a dog", "Expected data key to have correct value")
assert.Equal(t, record["dumpling"], "is a dog", "Expected data key to have correct value")
}

func TestGetBoolParam(t *testing.T) {
value1 := getBoolParam("true", false)
assert.Equal(t, value1, true, "Expected option value is true")
value2 := getBoolParam("false", false)
assert.Equal(t, value2, false, "Expected option value is false")
value3 := getBoolParam("fakeString", false)
assert.Equal(t, value3, false, "Expected option value is false")
}

0 comments on commit b9411fc

Please sign in to comment.