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 f3f78a7 commit 4a957d3
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:4,29-7,8: key in an attribute must be unique: 'a'; Key must be unique for a.",
},
{
"add_response_headers",
`server {
api {
endpoint "/a" {
add_response_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:4,30-7,8: key in an attribute must be unique: 'a'; Key must be unique for a.",
},
{
"beta_scope",
`server {
api {
endpoint "/a" {
beta_scope = {
get = "a"
GeT = "A"
}
}
}
}`,
"couper.hcl:4,20-7,8: key in an attribute must be unique: 'get'; Key must be unique for get.",
},
{
"headers",
`server {
api {
endpoint "/a" {
request {
headers = {
a = "a"
A = "A"
}
}
}
}
}`,
"couper.hcl:5,19-8,10: key in an attribute must be unique: 'a'; Key must be unique for a.",
},
{
"set_request_headers",
`server {
api {
endpoint "/a" {
set_request_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:4,29-7,8: key in an attribute must be unique: 'a'; Key must be unique for a.",
},
{
"set_response_headers",
`server {
api {
endpoint "/a" {
set_response_headers = {
a = "a"
A = "A"
}
}
}
}`,
"couper.hcl:4,30-7,8: key in an attribute must be unique: 'a'; 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 4a957d3

Please sign in to comment.