Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PapaCharlie committed Oct 2, 2024
1 parent 8aa8b4b commit 0653daf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ads/ads_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ExampleParseRemainingChunksFromNonce() {
}
responses = append(responses, res)

if ads.ParseRemainingChunksFromNonce(res.Nonce) == 0 {
if remaining, _ := ads.ParseRemainingChunksFromNonce(res.Nonce); remaining == 0 {
break
}
}
Expand Down
4 changes: 3 additions & 1 deletion internal/server/handlers_delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func TestDeltaHandlerChunking(t *testing.T) {
require.Len(t, responses, expectedChunks)
expectedRemainingChunks := 0
for _, res := range slices.Backward(responses) {
require.Equal(t, expectedRemainingChunks, ads.ParseRemainingChunksFromNonce(res.Nonce))
remaining, err := ads.ParseRemainingChunksFromNonce(res.Nonce)
require.NoError(t, err)
require.Equal(t, expectedRemainingChunks, remaining)
expectedRemainingChunks++
}
return responses
Expand Down
11 changes: 8 additions & 3 deletions internal/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,19 @@ func TestNewNonce(t *testing.T) {
for _, expected := range []int{0, 42} {
nonce := newNonce(now, expected)
require.Equal(t, fmt.Sprintf("%x%08x", now.UnixNano(), expected), nonce)
actualRemainingChunks := ads.ParseRemainingChunksFromNonce(nonce)
actualRemainingChunks, err := ads.ParseRemainingChunksFromNonce(nonce)
require.NoError(t, err)
require.Equal(t, expected, actualRemainingChunks)
}
})
t.Run("badNonce", func(t *testing.T) {
require.Zero(t, ads.ParseRemainingChunksFromNonce("foo"))
remaining, err := ads.ParseRemainingChunksFromNonce("foo")
require.Error(t, err)
require.Zero(t, remaining)
})
t.Run("oldNonce", func(t *testing.T) {
require.Zero(t, ads.ParseRemainingChunksFromNonce(fmt.Sprintf("%x", now.UnixNano())))
remaining, err := ads.ParseRemainingChunksFromNonce(fmt.Sprintf("%x", now.UnixNano()))
require.Error(t, err)
require.Zero(t, remaining)
})
}

0 comments on commit 0653daf

Please sign in to comment.