Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datasource: fix test for invalid method #13199

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions datasource/http/data_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ var testDatasourceInvalidMethod string

func TestHttpDataSource(t *testing.T) {
tests := []struct {
Name string
Path string
Error bool
Outputs map[string]string
Name string
Path string
Error bool
ExpectedOutputs map[string]string
}{
{
Name: "basic_test",
Path: testDatasourceBasic,
Error: false,
Outputs: map[string]string{
ExpectedOutputs: map[string]string{
"url": "url is https://www.packer.io/",
// Check that body is not empty
"body": "body is true",
Expand All @@ -48,16 +48,16 @@ func TestHttpDataSource(t *testing.T) {
Name: "url_is_empty",
Path: testDatasourceEmptyUrl,
Error: true,
Outputs: map[string]string{
ExpectedOutputs: map[string]string{
"error": "the `url` must be specified",
},
},
{
Name: "method_is_invalid",
Path: testDatasourceInvalidMethod,
Error: true,
Outputs: map[string]string{
"error": "the `method` must be one of [HEAD GET POST PUT DELETE OPTIONS PATCH]",
ExpectedOutputs: map[string]string{
"error": "the `method` must be one of \\[HEAD GET POST PUT DELETE OPTIONS PATCH\\]",
lbajolet-hashicorp marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestHttpDataSource(t *testing.T) {
}
}

if tt.Outputs != nil {
if tt.ExpectedOutputs != nil {
logs, err := os.Open(logfile)
if err != nil {
return fmt.Errorf("Unable find %s", logfile)
Expand All @@ -101,7 +101,7 @@ func TestHttpDataSource(t *testing.T) {
}
logsString := string(logsBytes)

for key, val := range tt.Outputs {
for key, val := range tt.ExpectedOutputs {
if matched, _ := regexp.MatchString(val+".*", logsString); !matched {
t.Fatalf(
"logs doesn't contain expected log %v with value %v in %q",
Expand Down