Address (some) PR comments

This commit is contained in:
gkze 2024-01-10 00:06:35 -08:00
parent 2cdd62208d
commit dec74e86df
No known key found for this signature in database
GPG Key ID: 3A7266FAC0D2F08D
3 changed files with 51 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
type Probe struct {
Exec *ExecProbe `yaml:"exec,omitempty"`
HttpGet *HttpProbe `yaml:"http_get,omitempty"`
Http *HttpProbe `yaml:"http,omitempty"`
InitialDelay int `yaml:"initial_delay_seconds,omitempty"`
PeriodSeconds int `yaml:"period_seconds,omitempty"`

View File

@ -1,6 +1,7 @@
package health
import (
"net/http"
"net/url"
"reflect"
"testing"
@ -98,6 +99,54 @@ func TestProbe_validateAndSetDefaults(t *testing.T) {
}
}
func TestHttpProbe_fields(t *testing.T) {
type fields struct {
Host string
Path string
Scheme string
Port int
Method string
StatusCode int
}
tests := []struct {
name string
fields fields
want fields
}{
{
name: "Method and expected status code not set",
fields: fields{
Host: "google.com",
Path: "/isAlive",
Scheme: "https",
Port: 0,
},
want: fields{
Host: "google.com",
Path: "/isAlive",
Scheme: "https",
Port: 0,
Method: http.MethodGet,
StatusCode: http.StatusOK,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
hp := HttpProbe(tt.fields)
p := Probe{Http: &hp}
p.validateAndSetHttpDefaults()
if p.Http.Method != http.MethodGet {
t.Error("HTTP method was not GET when not set in config file")
}
if p.Http.StatusCode != http.StatusOK {
t.Errorf("HTTP expected status code was not OK (200)")
}
})
}
}
func TestHttpProbe_getUrl(t *testing.T) {
type fields struct {
Host string

View File

@ -143,5 +143,6 @@ func renderProbe(probe *health.Probe, tpl *templater.Templater, vars types.Vars)
probe.Http.Path = tpl.RenderWithExtraVars(probe.Http.Path, vars)
probe.Http.Host = tpl.RenderWithExtraVars(probe.Http.Host, vars)
probe.Http.Scheme = tpl.RenderWithExtraVars(probe.Http.Scheme, vars)
probe.Http.Method = tpl.RenderWithExtraVars(probe.Http.Method, vars)
}
}