Skip to content

Commit

Permalink
tests default_value config item
Browse files Browse the repository at this point in the history
  • Loading branch information
f7o committed Sep 8, 2024
1 parent 6a43e15 commit 87cbf6b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions extension/headerssetterextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func TestLoadConfig(t *testing.T) {
Action: INSERT,
FromContext: stringp("tenant_id"),
Value: nil,
}, {
Key: stringp("X-Scope-OrgID"),
Action: INSERT,
FromContext: stringp("tenant_id"),
DefaultValue: stringp("some_id"),
Value: nil,
},
{
Key: stringp("User-ID"),
Expand Down Expand Up @@ -148,6 +154,18 @@ func TestValidateConfig(t *testing.T) {
},
errMissingSource,
},
{
"header value source is missing snd default value set",
[]HeaderConfig{
{
Key: stringp("name"),
Action: INSERT,
FromContext: stringp("from context"),
DefaultValue: stringp("default"),
},
},
nil,
},
{
"delete header action",
[]HeaderConfig{
Expand Down
36 changes: 36 additions & 0 deletions extension/headerssetterextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,42 @@ var (
"header_name": "",
},
},
{
cfg: &Config{
HeadersConfig: []HeaderConfig{
{
Key: &header,
Action: INSERT,
FromContext: stringp("tenant"),
DefaultValue: stringp("default_tenant"),
},
},
},
metadata: client.NewMetadata(
map[string][]string{},
),
expectedHeaders: map[string]string{
"header_name": "default_tenant",
},
},
{
cfg: &Config{
HeadersConfig: []HeaderConfig{
{
Key: &header,
Action: INSERT,
FromContext: stringp("tenant"),
DefaultValue: stringp("default_tenant"),
},
},
},
metadata: client.NewMetadata(
map[string][]string{"tenant": {"acme"}},
),
expectedHeaders: map[string]string{
"header_name": "acme",
},
},
}
)

Expand Down
4 changes: 4 additions & 0 deletions extension/headerssetterextension/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ headers_setter/1:
- key: X-Scope-OrgID
action: insert
from_context: "tenant_id"
- key: X-Scope-OrgID
action: insert
from_context: "tenant_id"
default_value: "some_id"
- key: User-ID
action: update
from_context: "user_id"
Expand Down

0 comments on commit 87cbf6b

Please sign in to comment.