Tested FlagsWithParams.GetBool

This commit is contained in:
adragusin
2019-11-26 12:46:32 +02:00
parent 1e79739911
commit 0c287d09df
6 changed files with 43 additions and 1 deletions

View File

@@ -35,6 +35,9 @@
"cdrs": {
"enabled": true, // start the CDR Server service: <true|false>
"chargers_conns":[
{"address": "*internal"}
],
"rals_conns": [
{"address": "*internal"} // address where to reach the Rater <""|*internal|127.0.0.1:2013>
],

View File

@@ -22,6 +22,12 @@
"cdrs": {
"enabled": true, // start the CDR Server service: <true|false>
"store_cdrs": false, // store cdrs in storDb
"chargers_conns":[
{"address": "*internal"}
],
"rals_conns": [
{"address": "*internal"}
],
"online_cdr_exports": ["http_localhost", "amqp_localhost", "http_test_file", "amqp_test_file","aws_test_file","sqs_test_file","kafka_localhost","s3_test_file"],
},

View File

@@ -20,6 +20,12 @@
"cdrs": {
"enabled": true, // start the CDR Server service: <true|false>
"chargers_conns":[
{"address": "*internal"}
],
"rals_conns": [
{"address": "*internal"}
],
},
"chargers": {

View File

@@ -36,6 +36,9 @@
"chargers_conns":[
{"address": "*internal"}
],
"rals_conns": [
{"address": "*internal"}
],
},

View File

@@ -299,7 +299,7 @@ func (fWp FlagsWithParams) GetBool(key string) (b bool) {
if v, b = fWp[key]; !b {
return // not present means false
}
if v != nil && len(v) != 0 {
if v == nil || len(v) == 0 {
return false // empty slice
}
return v[0] == "true" // check only the first element

View File

@@ -213,3 +213,27 @@ func TestFlagsToSlice(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sls, flgSls)
}
}
func TestFlagsWithParamsGetBool(t *testing.T) {
flagsWithParams := &FlagsWithParams{
"test": []string{"string1", "string2"},
"test2": []string{"true", "string2"},
"empty": []string{},
}
key := "notpresent"
if rcv := flagsWithParams.GetBool(key); rcv != false {
t.Errorf("Expecting: false, received: %+v", ToJSON(rcv))
}
key = "empty"
if rcv := flagsWithParams.GetBool(key); rcv != false {
t.Errorf("Expecting: false, received: %+v", ToJSON(rcv))
}
key = "test"
if rcv := flagsWithParams.GetBool(key); rcv != false {
t.Errorf("Expecting: false, received: %+v", ToJSON(rcv))
}
key = "test2"
if rcv := flagsWithParams.GetBool(key); rcv != true {
t.Errorf("Expecting: true, received: %+v", ToJSON(rcv))
}
}