Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions acls_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ func TestACLs_GrantReadFails(t *testing.T) {
if changed != nil || !errors.Is(err, ErrNotFound) {
t.Fatalf("Grant = %v, %v; want nil, ErrNotFound", changed, err)
}
var ce *ACLChangeError
if errors.As(err, &ce) {
if _, ok := errors.AsType[*ACLChangeError](err); ok {
t.Errorf("a failed read should not be an ACLChangeError: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion chefignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func readChefignore(p string) (found bool, ci *Chefignore, err error) {
// "#"). Surrounding whitespace is trimmed from each pattern.
func parseChefignore(data []byte) []string {
var patterns []string
for _, line := range strings.Split(string(data), "\n") {
for line := range strings.SplitSeq(string(data), "\n") {
line = strings.TrimSpace(line)
if line == "" || strings.HasPrefix(line, "#") {
continue
Expand Down
6 changes: 3 additions & 3 deletions cookbooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,9 @@ func TestAllFiles_DedupesByPath(t *testing.T) {
// Download must fetch and write each cookbook file exactly once, even when the
// manifest lists it in both shapes.
func TestDownload_FetchesEachFileOnce(t *testing.T) {
var fetches int64
var fetches atomic.Int64
files := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
atomic.AddInt64(&fetches, 1)
fetches.Add(1)
w.Write([]byte("# default recipe\n"))
}))
defer files.Close()
Expand All @@ -1077,7 +1077,7 @@ func TestDownload_FetchesEachFileOnce(t *testing.T) {
if err := c.Cookbooks.Download(context.Background(), "nginx", "1.0.0", dest); err != nil {
t.Fatalf("Download: %v", err)
}
if got := atomic.LoadInt64(&fetches); got != 1 {
if got := fetches.Load(); got != 1 {
t.Errorf("bookshelf fetches = %d, want 1", got)
}
}
Expand Down
5 changes: 2 additions & 3 deletions integration/suite/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package suite
import (
"bytes"
"io"
"maps"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -34,9 +35,7 @@ func rawRequest(t *testing.T, tgt Target, method, path, apiVersion string, body
if err != nil {
t.Fatalf("build %s %s: %v", method, path, err)
}
for k, v := range hdrs {
req.Header[k] = v
}
maps.Copy(req.Header, hdrs)
req.Header.Set("X-Chef-Version", "16.0.0")
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
Expand Down
5 changes: 1 addition & 4 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ func TestSearch_AllWithStart(t *testing.T) {
requestStarts = append(requestStarts, start)

// Build a page of rows beginning at 'start'.
end := start + pageSize
if end > totalRows {
end = totalRows
}
end := min(start+pageSize, totalRows)
var rows []string
for i := start; i < end; i++ {
rows = append(rows, fmt.Sprintf(`{"idx":%d}`, i))
Expand Down
12 changes: 5 additions & 7 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -161,8 +162,7 @@ func (e *transportErr) Unwrap() error { return e.err }
// Context cancellation and deadlines never retry: the caller is done waiting.
// Neither does a failed TLS handshake that will fail the same way next time.
func isRetriable(err error) bool {
var te *transportErr
if !errors.As(err, &te) {
if _, ok := errors.AsType[*transportErr](err); !ok {
return false
}
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
Expand Down Expand Up @@ -218,8 +218,8 @@ func (c *Client) doOnce(ctx context.Context, method, path string, body []byte) (
// Strip the query string from the path used for signing only; the v1.3
// signing spec requires the canonical path to exclude the query string.
signPath := path
if i := strings.IndexByte(path, '?'); i >= 0 {
signPath = path[:i]
if before, _, ok := strings.Cut(path, "?"); ok {
signPath = before
}
apiVersion, _ := ctx.Value(apiVersionKey{}).(string)
hdrs, err := signing.SignHeaders(signing.Request{
Expand All @@ -230,9 +230,7 @@ func (c *Client) doOnce(ctx context.Context, method, path string, body []byte) (
if err != nil {
return nil, nil, err
}
for k, v := range hdrs {
req.Header[k] = v
}
maps.Copy(req.Header, hdrs)
req.Header.Set("X-Chef-Version", c.opts.chefVersion)
req.Header.Set("User-Agent", c.opts.userAgent)
req.Header.Set("Accept", "application/json")
Expand Down
6 changes: 3 additions & 3 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ func recordSleeps(c *Client) *[]time.Duration {
// A 5xx is retried, and the client waits longer before each attempt rather
// than firing every attempt inside the same microsecond.
func TestRetry_BacksOffBetweenAttempts(t *testing.T) {
var attempts int32
var attempts atomic.Int32
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
atomic.AddInt32(&attempts, 1)
attempts.Add(1)
w.WriteHeader(500)
}))
defer srv.Close()
Expand All @@ -583,7 +583,7 @@ func TestRetry_BacksOffBetweenAttempts(t *testing.T) {
if _, _, err := do[map[string]any](context.Background(), c, "GET", "/nodes/x", nil); err == nil {
t.Fatal("want an error from a persistent 500")
}
if got := atomic.LoadInt32(&attempts); got != 3 {
if got := attempts.Load(); got != 3 {
t.Errorf("attempts = %d, want 3 (initial + 2 retries)", got)
}
if len(*sleeps) != 2 {
Expand Down
Loading