Skip to content

Commit

Permalink
test for uniqueness check
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Koch committed Mar 30, 2022
1 parent 6a1b98e commit 842ce3e
Showing 1 changed file with 219 additions and 0 deletions.
219 changes: 219 additions & 0 deletions config/configload/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,222 @@ func TestLabels(t *testing.T) {
})
}
}

func TestAttributeObjectKeys(t *testing.T) {
tests := []struct {
name string
hcl string
error string
}{
{
"add_request_headers",
`server {
api {
endpoint "/a" {
add_request_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:6,9-10: key must be unique: 'a' was previously defined at: couper.hcl:5,9-10; Key must be unique for a.",
},
{
"add_response_headers",
`server {
api {
endpoint "/a" {
add_response_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:6,9-10: key must be unique: 'a' was previously defined at: couper.hcl:5,9-10; Key must be unique for a.",
},
{
"beta_scope",
`server {
api {
endpoint "/a" {
beta_scope = {
get = "a"
GeT = "A"
}
}
}
}`,
"couper.hcl:6,9-12: key must be unique: 'get' was previously defined at: couper.hcl:5,9-12; Key must be unique for get.",
},
{
"headers",
`server {
api {
endpoint "/a" {
request {
headers = {
a = "a"
A = "A"
}
}
}
}
}`,
"couper.hcl:7,11-12: key must be unique: 'a' was previously defined at: couper.hcl:6,11-12; Key must be unique for a.",
},
{
"set_request_headers",
`server {
api {
endpoint "/a" {
set_request_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:6,9-10: key must be unique: 'a' was previously defined at: couper.hcl:5,9-10; Key must be unique for a.",
},
{
"set_response_headers",
`server {
api {
endpoint "/a" {
set_response_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:6,9-10: key must be unique: 'a' was previously defined at: couper.hcl:5,9-10; Key must be unique for a.",
},
{
"json_body",
`server {
api {
endpoint "/a" {
request {
json_body = {
a = "a"
A = "A"
}
}
}
}
}`,
"",
},
{
"form_body",
`server {
api {
endpoint "/a" {
request {
form_body = {
a = "a"
A = "A"
}
}
}
}
}`,
"",
},
{
"beta_roles_map",
`server {}
definitions {
jwt "a" {
signature_algorithm = "HS256"
key = "asdf"
beta_roles_map = {
a = []
A = []
}
}
}`,
"",
},
{
"beta_scope_map",
`server {}
definitions {
jwt "a" {
signature_algorithm = "HS256"
key = "asdf"
beta_scope_map = {
a = []
A = []
}
}
}`,
"",
},
{
"claims",
`server {}
definitions {
jwt "a" {
signature_algorithm = "HS256"
key = "asdf"
claims = {
a = "a"
A = "A"
}
}
}`,
"",
},
{
"custom_log_fields",
`server {}
definitions {
jwt "a" {
signature_algorithm = "HS256"
key = "asdf"
custom_log_fields = {
a = "a"
A = "A"
}
}
}`,
"",
},
{
"environment_variables",
`server {}
defaults {
environment_variables = {
a = "a"
A = "A"
}
}`,
"",
},
}

logger, _ := logrustest.NewNullLogger()
log := logger.WithContext(context.TODO())

for _, tt := range tests {
t.Run(tt.name, func(subT *testing.T) {
conf, err := LoadBytes([]byte(tt.hcl), "couper.hcl")
if conf != nil {
_, err = runtime.NewServerConfiguration(conf, log, nil)
}

var errMsg string
if err != nil {
errMsg = err.Error()
}

if tt.error != errMsg {
subT.Errorf("%q: Unexpected configuration error:\n\tWant: %q\n\tGot: %q", tt.name, tt.error, errMsg)
}
})
}
}

0 comments on commit 842ce3e

Please sign in to comment.