Skip to content

Commit

Permalink
revamp test util method to offer more feedback (#5770)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Jan 10, 2025
1 parent 9badcfe commit fcab6fc
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tests/testutils/collector_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
dockerContainer "github.com/docker/docker/api/types/container"
dockerMount "github.com/docker/docker/api/types/mount"
docker "github.com/docker/docker/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"go.opentelemetry.io/collector/confmap"
Expand Down Expand Up @@ -282,24 +283,20 @@ func (collector *CollectorContainer) execConfigRequest(t testing.TB, uri string)
// Wait until the splunk-otel-collector is up: relying on the entrypoint of the image
// can have the request happening before the collector is ready.
var initial string
require.Eventually(t, func() bool {
require.EventuallyWithT(t, func(tt *assert.CollectT) {
httpClient := &http.Client{}
req, err := http.NewRequest("GET", uri, nil)
require.NoError(t, err)
resp, err := httpClient.Do(req)
if err != nil {
return false
}
require.NoError(tt, err)

defer resp.Body.Close()
arr, err := io.ReadAll(resp.Body)
if err != nil {
return false
}
require.NoError(tt, err)

initial = string(arr)

return resp.StatusCode == http.StatusOK
require.Equal(t, http.StatusOK, resp.StatusCode)
}, 30*time.Second, 100*time.Millisecond)

actual := map[string]any{}
Expand Down

0 comments on commit fcab6fc

Please sign in to comment.