Skip to content

Commit

Permalink
Parallelize tests and do not retry
Browse files Browse the repository at this point in the history
This xommit updates the http tests to avoid retries to speed them up.

Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
  • Loading branch information
puerco committed Jul 23, 2024
1 parent 18dab2e commit b6576e7
Showing 1 changed file with 47 additions and 20 deletions.
67 changes: 47 additions & 20 deletions http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func NewTestAgent() *khttp.Agent {
}

func TestAgentPost(t *testing.T) {
agent := NewTestAgent()
t.Parallel()
agent := NewTestAgent().WithRetries(0)
resp := getTestResponse()
defer resp.Body.Close()

Expand All @@ -114,25 +115,50 @@ func TestAgentPost(t *testing.T) {
}

func TestAgentGet(t *testing.T) {
agent := NewTestAgent()

resp := getTestResponse()
defer resp.Body.Close()

// First simulate a successful request
fake := &httpfakes.FakeAgentImplementation{}
fake.SendGetRequestReturns(resp, nil)

agent.SetImplementation(fake)
b, err := agent.Get("http://www.example.com/")
require.NoError(t, err)
require.Equal(t, b, []byte("hello sig-release!"))
t.Parallel()
agent := NewTestAgent().WithRetries(0)

// Now check error is handled
fake.SendGetRequestReturns(resp, errors.New("HTTP Post error"))
agent.SetImplementation(fake)
_, err = agent.Get("http://www.example.com/")
require.Error(t, err)
for _, tc := range []struct {
name string
mustErr bool
expected []byte
prepare func(*httpfakes.FakeAgentImplementation)
}{
{
"no-error",
false,
[]byte("hello sig-release!"),
func(fai *httpfakes.FakeAgentImplementation) {
t.Helper()
resp := getTestResponse()
defer resp.Body.Close()
fai.SendGetRequestReturns(resp, nil)
},
}, {
"error",
true,
nil,
func(fai *httpfakes.FakeAgentImplementation) {
t.Helper()
fai.SendGetRequestReturns(nil, errors.New("HTTP Post error"))
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fake := &httpfakes.FakeAgentImplementation{}
tc.prepare(fake)
agent.SetImplementation(fake)
b, err := agent.Get("http://www.example.com/")
if tc.mustErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tc.expected, b)
})
}
}

func TestAgentGetToWriter(t *testing.T) {
Expand Down Expand Up @@ -177,7 +203,8 @@ func TestAgentGetToWriter(t *testing.T) {
}

func TestAgentHead(t *testing.T) {
agent := NewTestAgent()
t.Parallel()
agent := NewTestAgent().WithRetries(0)

resp := getTestResponse()
defer resp.Body.Close()
Expand Down

0 comments on commit b6576e7

Please sign in to comment.