-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add headers to http processor (#1552)
* add headers to http processor * Update pkg/plugin/processor/builtin/impl/webhook/http.go Co-authored-by: Lovro Mažgon <[email protected]> * Update pkg/plugin/processor/builtin/impl/webhook/http.go Co-authored-by: Lovro Mažgon <[email protected]> * add tests, handle lower case header name, re-generate * fix tests and code * Update pkg/plugin/processor/builtin/impl/webhook/http.go Co-authored-by: Lovro Mažgon <[email protected]> --------- Co-authored-by: Haris Osmanagić <[email protected]> Co-authored-by: Lovro Mažgon <[email protected]>
- Loading branch information
1 parent
57b29be
commit 734fa82
Showing
4 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
pkg/plugin/processor/builtin/impl/webhook/http_config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright © 2024 Meroxa, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package webhook | ||
|
||
import ( | ||
"github.com/matryer/is" | ||
"testing" | ||
) | ||
|
||
func TestHTTPConfig_ValidateHeaders(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input httpConfig | ||
wantConfig httpConfig | ||
wantErr string | ||
}{ | ||
{ | ||
name: "ContentType field present, header present", | ||
input: httpConfig{ | ||
ContentType: "application/json", | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
wantErr: `Configuration error, cannot provide both "request.contentType" and "headers.Content-Type", use "headers.Content-Type" only.`, | ||
}, | ||
{ | ||
name: "ContentType field present, header present, different case", | ||
input: httpConfig{ | ||
ContentType: "application/json", | ||
Headers: map[string]string{ | ||
"content-type": "application/json", | ||
}, | ||
}, | ||
wantErr: `Configuration error, cannot provide both "request.contentType" and "headers.Content-Type", use "headers.Content-Type" only.`, | ||
}, | ||
{ | ||
name: "ContentType field presents, header not present", | ||
input: httpConfig{ | ||
ContentType: "application/json", | ||
}, | ||
wantConfig: httpConfig{ | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "ContentType field not present, header present", | ||
input: httpConfig{ | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
wantConfig: httpConfig{ | ||
Headers: map[string]string{ | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "ContentType field not present, header present, different case", | ||
input: httpConfig{ | ||
Headers: map[string]string{ | ||
"content-type": "application/json", | ||
}, | ||
}, | ||
wantConfig: httpConfig{ | ||
Headers: map[string]string{ | ||
"content-type": "application/json", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
is := is.New(t) | ||
err := tc.input.parseHeaders() | ||
|
||
if tc.wantErr == "" { | ||
is.Equal(tc.wantConfig, tc.input) | ||
} else { | ||
is.True(err != nil) | ||
is.Equal(tc.wantErr, err.Error()) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters