Skip to content
Prev Previous commit
Next Next commit
Test default values for the HTTPConfig struct
  • Loading branch information
antonio committed May 14, 2019
commit d6e1ab7294342a408ebfc8bad494cc7a02f04d4a
49 changes: 42 additions & 7 deletions pkg/objstore/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,48 @@ import (
"github.com/improbable-eng/thanos/pkg/testutil"
)

func TestParseConfig_DefaultHTTPOpts(t *testing.T) {
func TestParseConfig(t *testing.T) {
input := []byte(`bucket: abcd
insecure: false`)
cfg, err := parseConfig(input)
testutil.Ok(t, err)

if cfg.Bucket != "abcd" {
t.Errorf("parsing of bucket failed: got %v, expected %v", cfg.Bucket, "abcd")
}
if cfg.Insecure {
t.Errorf("parsing of insecure failed: got %v, expected %v", cfg.Insecure, false)
}
}

func TestParseConfig_DefaultHTTPConfig(t *testing.T) {
input := []byte(`bucket: abcd
insecure: false`)
cfg, err := parseConfig(input)
testutil.Ok(t, err)

if time.Duration(cfg.HTTPConfig.IdleConnTimeout) != time.Duration(90*time.Second) {
t.Errorf("parsing of idle_conn_timeout failed: got %v, expected %v",
time.Duration(cfg.HTTPConfig.IdleConnTimeout), time.Duration(90*time.Second))
}

if time.Duration(cfg.HTTPConfig.ResponseHeaderTimeout) != time.Duration(2*time.Minute) {
t.Errorf("parsing of response_header_timeout failed: got %v, expected %v",
time.Duration(cfg.HTTPConfig.IdleConnTimeout), time.Duration(2*time.Minute))
}

if cfg.HTTPConfig.InsecureSkipVerify {
t.Errorf("parsing of insecure_skip_verify failed: got %v, expected %v", cfg.HTTPConfig.InsecureSkipVerify, false)
}
}

func TestParseConfig_CustomHTTPConfig(t *testing.T) {
input := []byte(`bucket: abcd
insecure: false
http_config:
insecure_skip_verify: true
idle_conn_timeout: 50s`)
idle_conn_timeout: 50s
response_header_timeout: 1m`)
cfg, err := parseConfig(input)
testutil.Ok(t, err)

Expand All @@ -21,12 +57,11 @@ http_config:
time.Duration(cfg.HTTPConfig.IdleConnTimeout), time.Duration(50*time.Second))
}

if cfg.Bucket != "abcd" {
t.Errorf("parsing of bucket failed: got %v, expected %v", cfg.Bucket, "abcd")
}
if cfg.Insecure {
t.Errorf("parsing of insecure failed: got %v, expected %v", cfg.Insecure, false)
if time.Duration(cfg.HTTPConfig.ResponseHeaderTimeout) != time.Duration(1*time.Minute) {
t.Errorf("parsing of response_header_timeout failed: got %v, expected %v",
time.Duration(cfg.HTTPConfig.IdleConnTimeout), time.Duration(1*time.Minute))
}

if !cfg.HTTPConfig.InsecureSkipVerify {
t.Errorf("parsing of insecure_skip_verify failed: got %v, expected %v", cfg.HTTPConfig.InsecureSkipVerify, false)
}
Expand Down