Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions clicommand/meta_data_set_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -94,8 +95,6 @@ func TestSetMetaDataBatch(t *testing.T) {
t.Parallel()

t.Run("success", func(t *testing.T) {
t.Parallel()

var receivedBatch api.MetaDataBatch
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
if req.Method != "POST" {
Expand Down Expand Up @@ -134,8 +133,6 @@ func TestSetMetaDataBatch(t *testing.T) {
})

t.Run("server error gives up when context is cancelled", func(t *testing.T) {
t.Parallel()

server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)
}))
Expand Down Expand Up @@ -165,11 +162,9 @@ func TestSetMetaDataBatch(t *testing.T) {
})

t.Run("401 does not retry", func(t *testing.T) {
t.Parallel()

callCount := 0
var callCount atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
callCount++
callCount.Add(1)
rw.WriteHeader(http.StatusUnauthorized)
}))
defer server.Close()
Expand All @@ -188,17 +183,15 @@ func TestSetMetaDataBatch(t *testing.T) {
if err := setMetaDataBatch(t.Context(), cfg, l, items); err == nil {
t.Fatal("setMetaDataBatch error = nil, want error")
}
if callCount != 1 {
t.Errorf("callCount = %d, want 1", callCount)
if callCount.Load() != 1 {
t.Errorf("callCount.Load() = %d, want 1", callCount.Load())
}
})

t.Run("404 does not retry", func(t *testing.T) {
t.Parallel()

callCount := 0
var callCount atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
callCount++
callCount.Add(1)
rw.WriteHeader(http.StatusNotFound)
}))
defer server.Close()
Expand All @@ -217,8 +210,8 @@ func TestSetMetaDataBatch(t *testing.T) {
if err := setMetaDataBatch(t.Context(), cfg, l, items); err == nil {
t.Fatal("setMetaDataBatch error = nil, want error")
}
if callCount != 1 {
t.Errorf("callCount = %d, want 1", callCount)
if callCount.Load() != 1 {
t.Errorf("callCount.Load() = %d, want 1", callCount.Load())
}
})
}