add test cases for h2ping_use_tls default behavior

This commit is contained in:
tarat44 2021-10-09 17:12:52 -04:00
parent f4c5672c79
commit e3a18e5203
2 changed files with 40 additions and 4 deletions

View File

@ -2375,6 +2375,42 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
rt.DataDir = dataDir
},
})
run(t, testCase{
desc: "h2ping check without h2ping_use_tls set",
args: []string{
`-data-dir=` + dataDir,
},
json: []string{
`{ "check": { "name": "a", "h2ping": "localhost:55555", "interval": "5s" } }`,
},
hcl: []string{
`check = { name = "a" h2ping = "localhost:55555" interval = "5s" }`,
},
expected: func(rt *RuntimeConfig) {
rt.Checks = []*structs.CheckDefinition{
{Name: "a", H2PING: "localhost:55555", H2PingUseTLS: true, OutputMaxSize: checks.DefaultBufSize, Interval: 5 * time.Second},
}
rt.DataDir = dataDir
},
})
run(t, testCase{
desc: "h2ping check with h2ping_use_tls set to false",
args: []string{
`-data-dir=` + dataDir,
},
json: []string{
`{ "check": { "name": "a", "h2ping": "localhost:55555", "h2ping_use_tls": false, "interval": "5s" } }`,
},
hcl: []string{
`check = { name = "a" h2ping = "localhost:55555" h2ping_use_tls = false interval = "5s" }`,
},
expected: func(rt *RuntimeConfig) {
rt.Checks = []*structs.CheckDefinition{
{Name: "a", H2PING: "localhost:55555", H2PingUseTLS: false, OutputMaxSize: checks.DefaultBufSize, Interval: 5 * time.Second},
}
rt.DataDir = dataDir
},
})
run(t, testCase{
desc: "alias check with no node",
args: []string{

View File

@ -702,7 +702,7 @@ func h2pingUseTLSEqFn(out interface{}, want interface{}) error {
return nil
}
var h2pingUseTLSFields = []string{`"H2PingUseTLS": %s`, `"h2ping_use_tls": %s`}
var h2pingUseTLSFields = []string{`"H2PING": "testing"`, `"H2PingUseTLS": %s`, `"h2ping_use_tls": %s`}
var translateH2PingUseTLS = []translateKeyTestCase{
{
desc: "H2PingUseTLS: both set",
@ -715,21 +715,21 @@ var translateH2PingUseTLS = []translateKeyTestCase{
desc: "H2PingUseTLS:: first set",
in: []interface{}{`false`},
want: false,
jsonFmtStr: "{" + h2pingUseTLSFields[0] + "}",
jsonFmtStr: "{" + strings.Join(h2pingUseTLSFields[0:2], ",") + "}",
equalityFn: h2pingUseTLSEqFn,
},
{
desc: "H2PingUseTLS: second set",
in: []interface{}{`false`},
want: false,
jsonFmtStr: "{" + h2pingUseTLSFields[1] + "}",
jsonFmtStr: "{" + h2pingUseTLSFields[0] + "," + h2pingUseTLSFields[2] + "}",
equalityFn: h2pingUseTLSEqFn,
},
{
desc: "H2PingUseTLS: neither set",
in: []interface{}{},
want: true, // zero value
jsonFmtStr: "{" + `"h2ping":"testing"` + "}",
jsonFmtStr: "{" + h2pingUseTLSFields[0] + "}",
equalityFn: h2pingUseTLSEqFn,
},
}