feat: make TLS optional in Barkfile schema
This commit is contained in:
@@ -81,13 +81,59 @@ func TestValidateMissingFieldsAndDuplicateHostname(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Fatal("Validate() error = nil")
|
||||
}
|
||||
for _, want := range []string{"TLS private key is required", "upstream or postgres is required", "duplicate hostname"} {
|
||||
for _, want := range []string{"tls requires both cert and key", "upstream or postgres is required", "duplicate hostname"} {
|
||||
if !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("Validate() error = %q, missing %q", err, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAllowsConfigurationWithoutTLS(t *testing.T) {
|
||||
cfg := Config{
|
||||
Listen: ":5432",
|
||||
Databases: []DatabaseConfig{{
|
||||
Name: "analytics",
|
||||
Upstream: "postgres-foo:5432",
|
||||
}},
|
||||
}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAndValidateWithoutTLSBlock(t *testing.T) {
|
||||
cfg, err := Parse([]byte(`pawsql {
|
||||
listen :5432
|
||||
database analytics {
|
||||
upstream postgres-foo:5432
|
||||
}
|
||||
}`))
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() error = %v", err)
|
||||
}
|
||||
if cfg.TLS.CertFile != "" || cfg.TLS.KeyFile != "" {
|
||||
t.Errorf("TLS = %#v, want unset", cfg.TLS)
|
||||
}
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsHalfConfiguredTLS(t *testing.T) {
|
||||
cfg := Config{
|
||||
Listen: ":5432",
|
||||
TLS: TLSConfig{CertFile: "cert.pem"},
|
||||
Databases: []DatabaseConfig{{
|
||||
Name: "analytics",
|
||||
Upstream: "postgres-foo:5432",
|
||||
}},
|
||||
}
|
||||
err := cfg.Validate()
|
||||
if err == nil || !strings.Contains(err.Error(), "tls requires both cert and key") {
|
||||
t.Fatalf("Validate() error = %v, want tls requires both cert and key", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsMalformedUpstreamAddress(t *testing.T) {
|
||||
cfg := Config{
|
||||
Listen: ":5432",
|
||||
|
||||
Reference in New Issue
Block a user