Skip to content

Commit

Permalink
datasource/http: change Outputs->ExpectedOutputs
Browse files Browse the repository at this point in the history
The acceptance tests for the HTTP datasource had a `Outputs` attribute
for checking the output of the command for a specific regexp pattern.
As pointed out, given the expectative nature of the attribute, naming it
`Outputs` did not make the intent clear, so we rename it to
`ExpectedOutputs` with this commit.
  • Loading branch information
lbajolet-hashicorp committed Nov 4, 2024
1 parent c470395 commit 35d1490
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 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,15 +48,15 @@ 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{
ExpectedOutputs: map[string]string{
"error": "the `method` must be one of \\[HEAD GET POST PUT DELETE OPTIONS PATCH\\]",
},
},
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

0 comments on commit 35d1490

Please sign in to comment.