Files

38 lines
811 B
Go
Raw Permalink Normal View History

package test_test
import (
"io"
"net/http"
"strings"
"testing"
"queryorchestration/internal/test"
"github.com/stretchr/testify/assert"
)
func TestAssertStatus(t *testing.T) {
t.Run("pass", func(t *testing.T) {
mockT := &testing.T{}
test.AssertStatus(mockT, http.StatusOK, &http.Response{
StatusCode: 200,
})
assert.False(t, mockT.Failed())
})
t.Run("fail with nil body", func(t *testing.T) {
mockT := &testing.T{}
test.AssertStatus(mockT, http.StatusOK, &http.Response{
StatusCode: 500,
})
assert.True(t, mockT.Failed())
})
t.Run("fail with body", func(t *testing.T) {
mockT := &testing.T{}
test.AssertStatus(mockT, http.StatusOK, &http.Response{
StatusCode: 500,
Body: io.NopCloser(strings.NewReader("my body")),
})
assert.True(t, mockT.Failed())
})
}