Skip to content

Commit

Permalink
Address intrange linter violations
Browse files Browse the repository at this point in the history
Fix "for loop can be changed to use an integer range"

Signed-off-by: Tom Pantelis <[email protected]>
  • Loading branch information
tpantelis committed Jan 7, 2025
1 parent 0e9fc02 commit 072420b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions coredns/loadbalancer/smooth_weighted_round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = Describe("Smooth Weighted RR", func() {

// Validations
validateServerAdded := func(s server) {
for i := 0; i < 100; i++ {
for range 100 {
if lb.Next() == s.name {
return
}
Expand All @@ -75,15 +75,15 @@ var _ = Describe("Smooth Weighted RR", func() {

validateEmptyLBState := func() {
Expect(lb.ItemCount()).To(Equal(0))
for i := 0; i < 100; i++ {
for range 100 {
Expect(lb.Next()).To(BeNil())
}
}

validateLoadBalancingByCount := func(rounds int, servers []server) {
totalServersWeight := getTotalServesWeight(servers)
results := make(map[string]int64)
for i := 0; i < rounds; i++ {
for range rounds {
s := lb.Next().(string)
results[s]++
}
Expand Down Expand Up @@ -170,7 +170,7 @@ var _ = Describe("Smooth Weighted RR", func() {
It("Next() should return it all the time", func() {
s := servers[0]
addServer(s)
for i := 0; i < 10; i++ {
for range 10 {
Expect(lb.Next()).To(Equal(s.name))
}
})
Expand All @@ -192,7 +192,7 @@ var _ = Describe("Smooth Weighted RR", func() {
err := lb.Add(s.name, s.weight)
Expect(err).ToNot(HaveOccurred())
}
for i := 0; i < 100; i++ {
for range 100 {
for _, s := range roundRobinServers {
Expect(lb.Next().(string)).To(Equal(s.name))
}
Expand Down
18 changes: 9 additions & 9 deletions coredns/resolver/clusterip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func testClusterIPServiceInOneCluster() {

Context("and no specific cluster is requested", func() {
It("should consistently return its DNS record", func() {
for i := 0; i < 5; i++ {
for range 5 {
t.assertDNSRecordsFound(namespace1, service1, "", "", false, expDNSRecord)
}
})
})

Context("and the cluster is requested", func() {
It("should consistently return its DNS record", func() {
for i := 0; i < 5; i++ {
for range 5 {
t.assertDNSRecordsFound(namespace1, service1, clusterID1, "", false, expDNSRecord)
}
})
Expand Down Expand Up @@ -145,7 +145,7 @@ func testClusterIPServiceInTwoClusters() {
})

It("should consistently return its DNS record", func() {
for i := 0; i < 10; i++ {
for range 10 {
Expect(t.getNonHeadlessDNSRecord(namespace1, service1, "").IP).To(Equal(serviceIP1))
}
})
Expand All @@ -164,7 +164,7 @@ func testClusterIPServiceInTwoClusters() {

Context("and no specific cluster is requested", func() {
It("should consistently return the DNS record of the connected cluster", func() {
for i := 0; i < 10; i++ {
for range 10 {
t.assertDNSRecordsFound(namespace1, service1, "", "", false, expDNSRecord)
}
})
Expand Down Expand Up @@ -210,7 +210,7 @@ func testClusterIPServiceInTwoClusters() {

Context("and no specific cluster is requested", func() {
It("should consistently return the DNS record of the healthy cluster", func() {
for i := 0; i < 10; i++ {
for range 10 {
t.assertDNSRecordsFound(namespace1, service1, "", "", false, expDNSRecord)
}
})
Expand Down Expand Up @@ -245,7 +245,7 @@ func testClusterIPServiceInTwoClusters() {
})

It("should consistently return the DNS record of the remaining cluster", func() {
for i := 0; i < 10; i++ {
for range 10 {
t.assertDNSRecordsFound(namespace1, service1, "", "", false, expDNSRecord)
}
})
Expand Down Expand Up @@ -279,7 +279,7 @@ func testClusterIPServiceInThreeClusters() {
})

It("should consistently return the merged service ports", func() {
for i := 0; i < 10; i++ {
for range 10 {
Expect(t.getNonHeadlessDNSRecord(namespace1, service1, "").Ports).To(Equal([]mcsv1a1.ServicePort{port1}))
}
})
Expand All @@ -293,7 +293,7 @@ func testClusterIPServiceInThreeClusters() {
}

It("should consistently return its DNS record", func() {
for i := 0; i < 10; i++ {
for range 10 {
t.assertDNSRecordsFound(namespace1, service1, clusterID2, "", false, expDNSRecord)
}
})
Expand All @@ -320,7 +320,7 @@ func testClusterIPServiceInThreeClusters() {

Context("and subsequently healthy again", func() {
It("should consistently return the all DNS records round-robin", func() {
for i := 0; i < 5; i++ {
for range 5 {
Expect(t.getNonHeadlessDNSRecord(namespace1, service1, "").IP).To(Or(Equal(serviceIP1), Equal(serviceIP3)))
}

Expand Down
4 changes: 2 additions & 2 deletions coredns/resolver/resolver_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ func (t *testDriver) testRoundRobin(ns, service string, serviceIPs ...string) {
ipsCount := len(serviceIPs)
rrIPs := make([]string, 0)

for i := 0; i < ipsCount; i++ {
for i := range ipsCount {
r := t.getNonHeadlessDNSRecord(ns, service, "")
rrIPs = append(rrIPs, r.IP)
slice := rrIPs[0:i]
Expect(slice).ToNot(ContainElement(r.IP))
Expect(serviceIPs).To(ContainElement(r.IP))
}

for i := 0; i < 5; i++ {
for range 5 {
for _, ip := range rrIPs {
testIP := t.getNonHeadlessDNSRecord(ns, service, "").IP
Expect(testIP).To(Equal(ip))
Expand Down
2 changes: 1 addition & 1 deletion coredns/resolver/service_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (si *serviceInfo) newRecordFrom(from *DNSRecord) *DNSRecord {

func (si *serviceInfo) selectIP(checkCluster func(string) bool) *DNSRecord {
queueLength := si.balancer.ItemCount()
for i := 0; i < queueLength; i++ {
for range queueLength {
clusterID := si.balancer.Next().(string)
clusterInfo := si.clusters[clusterID]

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/controller/controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (c *cluster) awaitServiceExportCondition(expected ...*mcsv1a1.ServiceExport
actual := make([]*mcsv1a1.ServiceExportCondition, len(expected))
lastIndex := -1

for i := 0; i < len(expected)-1; i++ {
for i := range len(expected) - 1 {
j := lastIndex + 1

Eventually(func() interface{} {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/discovery/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func verifyRoundRobinWithDig(f *framework.Framework, srcCluster framework.Cluste

var retIPs []string

for count := 0; count < 10; count++ {
for range 10 {
framework.AwaitUntil("verify if service IP is discoverable", func() (interface{}, error) {
stdout, _, err := f.ExecWithOptions(context.TODO(), &framework.ExecOptions{
Command: cmd,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (f *Framework) AwaitPodIngressIPs(targetCluster framework.ClusterIndex, svc
hostNameList = make([]string, 0)
ipList = make([]string, 0)

for i := 0; i < len(podList.Items); i++ {
for i := range len(podList.Items) {
ingressIPName := fmt.Sprintf("pod-%s", podList.Items[i].Name)
ingressIP := f.Framework.AwaitGlobalIngressIP(targetCluster, ingressIPName, svc.Namespace)

Expand Down

0 comments on commit 072420b

Please sign in to comment.