aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2024-06-21 12:06:46 +0200
committerMartin Polden <mpolden@mpolden.no>2024-06-21 12:06:46 +0200
commit871064993d6d5a061e101a775b666a57285d4277 (patch)
treebde993e699626b707d690ac8c97956e1cd2ecc6f
parenta304d1dfe372801209390b451e9693775bec5887 (diff)
Use range over integers
-rw-r--r--client/go/internal/admin/jvm/mem_options_test.go2
-rw-r--r--client/go/internal/admin/vespa-wrapper/logfmt/tail_unix.go2
-rw-r--r--client/go/internal/cli/cmd/feed.go2
-rw-r--r--client/go/internal/cli/cmd/feed_test.go4
-rw-r--r--client/go/internal/cli/cmd/query.go2
-rw-r--r--client/go/internal/cli/cmd/status_test.go4
-rw-r--r--client/go/internal/cli/cmd/test_test.go6
-rw-r--r--client/go/internal/cli/cmd/visit_test.go2
-rw-r--r--client/go/internal/vespa/document/document_test.go2
-rw-r--r--client/go/internal/vespa/document/http.go2
-rw-r--r--client/go/internal/vespa/document/http_test.go2
-rw-r--r--client/go/internal/vespa/document/throttler_test.go2
-rw-r--r--client/go/internal/vespa/load_env.go2
-rw-r--r--client/go/internal/vespa/target_test.go8
14 files changed, 21 insertions, 21 deletions
diff --git a/client/go/internal/admin/jvm/mem_options_test.go b/client/go/internal/admin/jvm/mem_options_test.go
index 3db10153086..60cffc824e9 100644
--- a/client/go/internal/admin/jvm/mem_options_test.go
+++ b/client/go/internal/admin/jvm/mem_options_test.go
@@ -9,7 +9,7 @@ import (
func TestAdjustment(t *testing.T) {
lastAdj := 64
- for i := 0; i < 4096; i++ {
+ for i := range 4096 {
adj := adjustAvailableMemory(MegaBytesOfMemory(i)).ToMB()
assert.True(t, int(adj) >= lastAdj)
lastAdj = int(adj)
diff --git a/client/go/internal/admin/vespa-wrapper/logfmt/tail_unix.go b/client/go/internal/admin/vespa-wrapper/logfmt/tail_unix.go
index ec2c53487be..180f7c84859 100644
--- a/client/go/internal/admin/vespa-wrapper/logfmt/tail_unix.go
+++ b/client/go/internal/admin/vespa-wrapper/logfmt/tail_unix.go
@@ -85,7 +85,7 @@ func (t *unixTail) openTail() {
if err != nil {
return
}
- for i := 0; i < n; i++ {
+ for i := range n {
if t.lineBuf[i] == '\n' {
sz, err = file.Seek(sz+int64(i+1), os.SEEK_SET)
if err == nil {
diff --git a/client/go/internal/cli/cmd/feed.go b/client/go/internal/cli/cmd/feed.go
index 6c5df8b3e84..d6bc59f5b4f 100644
--- a/client/go/internal/cli/cmd/feed.go
+++ b/client/go/internal/cli/cmd/feed.go
@@ -136,7 +136,7 @@ func createServices(n int, timeout time.Duration, cli *CLI, waiter *Waiter) ([]h
}
services := make([]httputil.Client, 0, n)
baseURL := ""
- for i := 0; i < n; i++ {
+ for range n {
service, err := waiter.Service(target, cli.config.cluster())
if err != nil {
return nil, "", err
diff --git a/client/go/internal/cli/cmd/feed_test.go b/client/go/internal/cli/cmd/feed_test.go
index 200a0be7c5d..fc25f8e872c 100644
--- a/client/go/internal/cli/cmd/feed_test.go
+++ b/client/go/internal/cli/cmd/feed_test.go
@@ -82,13 +82,13 @@ func TestFeed(t *testing.T) {
require.Nil(t, cli.Run("feed", "-"))
assert.Equal(t, want, stdout.String())
- for i := 0; i < 10; i++ {
+ for range 10 {
httpClient.NextResponseString(503, `{"message":"it's broken yo"}`)
}
require.Nil(t, cli.Run("feed", jsonFile1))
assert.Equal(t, "feed: got status 503 ({\"message\":\"it's broken yo\"}) for put id:ns:type::doc1: giving up after 10 attempts\n", stderr.String())
stderr.Reset()
- for i := 0; i < 10; i++ {
+ for range 10 {
httpClient.NextResponseError(fmt.Errorf("something else is broken"))
}
require.Nil(t, cli.Run("feed", jsonFile1))
diff --git a/client/go/internal/cli/cmd/query.go b/client/go/internal/cli/cmd/query.go
index 4d5941943ca..5fa225777f0 100644
--- a/client/go/internal/cli/cmd/query.go
+++ b/client/go/internal/cli/cmd/query.go
@@ -84,7 +84,7 @@ func query(cli *CLI, arguments []string, timeoutSecs int, curl bool, format stri
}
url, _ := url.Parse(service.BaseURL + "/search/")
urlQuery := url.Query()
- for i := 0; i < len(arguments); i++ {
+ for i := range len(arguments) {
key, value := splitArg(arguments[i])
urlQuery.Set(key, value)
}
diff --git a/client/go/internal/cli/cmd/status_test.go b/client/go/internal/cli/cmd/status_test.go
index bf9b4f3493e..6db27fd2778 100644
--- a/client/go/internal/cli/cmd/status_test.go
+++ b/client/go/internal/cli/cmd/status_test.go
@@ -168,7 +168,7 @@ func TestStatusCloudDeployment(t *testing.T) {
}
func isLocalTarget(args []string) bool {
- for i := 0; i < len(args)-1; i++ {
+ for i := range len(args) - 1 {
if args[i] == "-t" {
return args[i+1] == "local"
}
@@ -197,7 +197,7 @@ func assertStatus(expectedTarget string, args []string, t *testing.T) {
t.Helper()
client := &mock.HTTPClient{}
clusterName := ""
- for i := 0; i < 3; i++ {
+ for range 3 {
if isLocalTarget(args) {
clusterName = "foo"
mockServiceStatus(client, clusterName)
diff --git a/client/go/internal/cli/cmd/test_test.go b/client/go/internal/cli/cmd/test_test.go
index 728e8c29691..3479e057e45 100644
--- a/client/go/internal/cli/cmd/test_test.go
+++ b/client/go/internal/cli/cmd/test_test.go
@@ -26,11 +26,11 @@ func TestSuite(t *testing.T) {
mockServiceStatus(client, "container")
client.NextStatus(200)
client.NextStatus(200)
- for i := 0; i < 2; i++ {
+ for range 2 {
client.NextResponseString(200, string(searchResponse))
}
mockServiceStatus(client, "container") // Some tests do not specify cluster, which is fine since we only have one, but this causes a cache miss
- for i := 0; i < 9; i++ {
+ for range 9 {
client.NextResponseString(200, string(searchResponse))
}
expectedBytes, _ := os.ReadFile("testdata/tests/expected-suite.out")
@@ -45,7 +45,7 @@ func TestSuite(t *testing.T) {
requests = append(requests, discoveryRequest)
requests = append(requests, createSearchRequest(baseUrl+"/search/"))
requests = append(requests, createSearchRequest(baseUrl+"/search/?foo=%2F"))
- for i := 0; i < 7; i++ {
+ for range 7 {
requests = append(requests, createSearchRequest(baseUrl+"/search/"))
}
assertRequests(requests, client, t)
diff --git a/client/go/internal/cli/cmd/visit_test.go b/client/go/internal/cli/cmd/visit_test.go
index ae494059691..85594912da2 100644
--- a/client/go/internal/cli/cmd/visit_test.go
+++ b/client/go/internal/cli/cmd/visit_test.go
@@ -41,7 +41,7 @@ func TestQuoteFunc(t *testing.T) {
var buf []byte = make([]byte, 3)
buf[0] = 'a'
buf[2] = 'z'
- for i := 0; i < 256; i++ {
+ for i := range 256 {
buf[1] = byte(i)
s := string(buf)
res := quoteArgForUrl(s)
diff --git a/client/go/internal/vespa/document/document_test.go b/client/go/internal/vespa/document/document_test.go
index 50698e3f8a3..8875ad83291 100644
--- a/client/go/internal/vespa/document/document_test.go
+++ b/client/go/internal/vespa/document/document_test.go
@@ -176,7 +176,7 @@ func testDocumentDecoder(t *testing.T, jsonLike string) {
if len(docs) != len(result) {
t.Errorf("len(result) = %d, want %d", len(result), len(docs))
}
- for i := 0; i < len(docs); i++ {
+ for i := range len(docs) {
got := result[i]
want := docs[i]
if !got.Equal(want) {
diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go
index 800ac0a3887..df4d97e2a82 100644
--- a/client/go/internal/vespa/document/http.go
+++ b/client/go/internal/vespa/document/http.go
@@ -95,7 +95,7 @@ func NewClient(options ClientOptions, httpClients []httputil.Client) (*Client, e
}
c.gzippers.New = func() any { return gzip.NewWriter(io.Discard) }
c.buffers.New = func() any { return &bytes.Buffer{} }
- for i := 0; i < runtime.NumCPU(); i++ {
+ for range runtime.NumCPU() {
go c.preparePending()
}
return c, nil
diff --git a/client/go/internal/vespa/document/http_test.go b/client/go/internal/vespa/document/http_test.go
index 74133fc73d8..878b7a98be3 100644
--- a/client/go/internal/vespa/document/http_test.go
+++ b/client/go/internal/vespa/document/http_test.go
@@ -34,7 +34,7 @@ type mockHTTPClient struct {
func TestLeastBusyClient(t *testing.T) {
httpClient := mock.HTTPClient{}
var httpClients []httputil.Client
- for i := 0; i < 4; i++ {
+ for i := range 4 {
httpClients = append(httpClients, &mockHTTPClient{i, &httpClient})
}
client, _ := NewClient(ClientOptions{}, httpClients)
diff --git a/client/go/internal/vespa/document/throttler_test.go b/client/go/internal/vespa/document/throttler_test.go
index eba8cbd2972..3cdecb22be4 100644
--- a/client/go/internal/vespa/document/throttler_test.go
+++ b/client/go/internal/vespa/document/throttler_test.go
@@ -13,7 +13,7 @@ func TestThrottler(t *testing.T) {
if got, want := tr.TargetInflight(), int64(16); got != want {
t.Errorf("got TargetInflight() = %d, but want %d", got, want)
}
- for i := 0; i < 65; i++ {
+ for range 65 {
tr.Sent()
tr.Success()
}
diff --git a/client/go/internal/vespa/load_env.go b/client/go/internal/vespa/load_env.go
index 5cae03694bc..4eb1297e711 100644
--- a/client/go/internal/vespa/load_env.go
+++ b/client/go/internal/vespa/load_env.go
@@ -151,7 +151,7 @@ func nSpacedFields(s string, n int) []string {
// pretty strict for now, can be more lenient if needed
func isValidShellVariableName(s string) bool {
- for i := 0; i < len(s); i++ {
+ for i := range len(s) {
b := s[i]
switch {
case (b >= 'A' && b <= 'Z'): // ok
diff --git a/client/go/internal/vespa/target_test.go b/client/go/internal/vespa/target_test.go
index f886c9117a9..2b4cf485b83 100644
--- a/client/go/internal/vespa/target_test.go
+++ b/client/go/internal/vespa/target_test.go
@@ -20,7 +20,7 @@ func TestLocalTarget(t *testing.T) {
client := &mock.HTTPClient{}
lt := LocalTarget(client, TLSOptions{}, 0)
assertServiceURL(t, "http://127.0.0.1:19071", lt, "deploy")
- for i := 0; i < 2; i++ {
+ for range 2 {
response := `
{
"services": [
@@ -83,7 +83,7 @@ func TestCustomTargetWait(t *testing.T) {
client.NextStatus(500)
assertService(t, true, target, "", 0)
// Fails multiple times
- for i := 0; i < 3; i++ {
+ for range 3 {
client.NextStatus(500)
client.NextResponseError(io.EOF)
}
@@ -120,7 +120,7 @@ func TestCustomTargetAwaitDeployment(t *testing.T) {
func TestCustomTargetCompatibleWith(t *testing.T) {
client := &mock.HTTPClient{}
target := CustomTarget(client, "http://192.0.2.42", TLSOptions{}, 0)
- for i := 0; i < 3; i++ {
+ for range 3 {
client.NextResponse(mock.HTTPResponse{
URI: "/state/v1/version",
Status: 200,
@@ -249,7 +249,7 @@ func TestLog(t *testing.T) {
func TestCloudCompatibleWith(t *testing.T) {
target, client := createCloudTarget(t, io.Discard)
- for i := 0; i < 3; i++ {
+ for range 3 {
client.NextResponse(mock.HTTPResponse{URI: "/cli/v1/", Status: 200, Body: []byte(`{"minVersion":"8.0.0"}`)})
}
assert.Nil(t, target.CompatibleWith(version.MustParse("8.0.0")))