Skip to content

Commit

Permalink
Fix random unrelated linter errors to get CI to run: revert later?
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Stucki committed Jun 7, 2023
1 parent d4cdb45 commit fdeccab
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 52 deletions.
6 changes: 1 addition & 5 deletions acceptance/framework/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ package cli
import (
"fmt"
"os/exec"
"strings"
"testing"

"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/hashicorp/consul-k8s/acceptance/framework/logger"
)

const (
Expand All @@ -28,7 +25,7 @@ func NewCLI() (*CLI, error) {
}

// Run runs the CLI with the given args.
func (c *CLI) Run(t *testing.T, options *k8s.KubectlOptions, args ...string) ([]byte, error) {
func (c *CLI) Run(options *k8s.KubectlOptions, args ...string) ([]byte, error) {
if !c.initialized {
return nil, fmt.Errorf("CLI must be initialized before calling Run, use `cli.NewCLI()` to initialize.")
}
Expand All @@ -41,7 +38,6 @@ func (c *CLI) Run(t *testing.T, options *k8s.KubectlOptions, args ...string) ([]
args = append(args, "-context", options.ContextName)
}

logger.Logf(t, "Running `consul-k8s %s`", strings.Join(args, " "))
cmd := exec.Command(cliBinaryName, args...)
return cmd.Output()
}
6 changes: 3 additions & 3 deletions acceptance/framework/consul/cli_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (c *CLICluster) Create(t *testing.T) {
args = append(args, "-timeout", "15m")
args = append(args, "-auto-approve")

out, err := c.cli.Run(t, c.kubectlOptions, args...)
out, err := c.cli.Run(c.kubectlOptions, args...)
if err != nil {
c.logger.Logf(t, "error running command `consul-k8s %s`: %s", strings.Join(args, " "), err.Error())
c.logger.Logf(t, "command stdout: %s", string(out))
Expand Down Expand Up @@ -169,7 +169,7 @@ func (c *CLICluster) Upgrade(t *testing.T, helmValues map[string]string) {
args = append(args, "-timeout", "15m")
args = append(args, "-auto-approve")

out, err := c.cli.Run(t, c.kubectlOptions, args...)
out, err := c.cli.Run(c.kubectlOptions, args...)
if err != nil {
c.logger.Logf(t, "error running command `consul-k8s %s`: %s", strings.Join(args, " "), err.Error())
c.logger.Logf(t, "command stdout: %s", string(out))
Expand All @@ -192,7 +192,7 @@ func (c *CLICluster) Destroy(t *testing.T) {
// Use `go run` so that the CLI is recompiled and therefore uses the local
// charts directory rather than the directory from whenever it was last
// compiled.
out, err := c.cli.Run(t, c.kubectlOptions, args...)
out, err := c.cli.Run(c.kubectlOptions, args...)
if err != nil {
c.logger.Logf(t, "error running command `consul-k8s %s`: %s", strings.Join(args, " "), err.Error())
c.logger.Logf(t, "command stdout: %s", string(out))
Expand Down
15 changes: 8 additions & 7 deletions acceptance/tests/cli/cli_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestInstall(t *testing.T) {
}

// Run proxy list and get the two results.
listOut, err := cli.Run(t, ctx.KubectlOptions(t), "proxy", "list")
listOut, err := cli.Run(ctx.KubectlOptions(t), "proxy", "list")
require.NoError(t, err)
logger.Log(t, string(listOut))
list := translateListOutput(listOut)
Expand All @@ -69,15 +69,16 @@ func TestInstall(t *testing.T) {
require.Equal(t, "Sidecar", proxyType)
}

kubeOpts := ctx.KubectlOptions(t)

// Run proxy read and check that the connection is present in the output.
retrier := &retry.Timer{Timeout: 160 * time.Second, Wait: 2 * time.Second}
retry.RunWith(retrier, t, func(r *retry.R) {
for podName := range list {
out, err := cli.Run(t, ctx.KubectlOptions(t), "proxy", "read", podName)
require.NoError(t, err)
out, err := cli.Run(kubeOpts, "proxy", "read", podName)
require.NoError(r, err)

output := string(out)
logger.Log(t, output)

// Both proxies must see their own local agent and app as clusters.
require.Regexp(r, "consul-dataplane.*STATIC", output)
Expand All @@ -98,7 +99,7 @@ func TestInstall(t *testing.T) {
require.NoError(t, err)

clientPodName := clientPod.Items[0].Name
upstreamsOut, err := cli.Run(t, ctx.KubectlOptions(t), "troubleshoot", "upstreams", "-pod", clientPodName)
upstreamsOut, err := cli.Run(ctx.KubectlOptions(t), "troubleshoot", "upstreams", "-pod", clientPodName)
logger.Log(t, string(upstreamsOut))
require.NoError(t, err)

Expand All @@ -110,15 +111,15 @@ func TestInstall(t *testing.T) {
require.NoError(t, err)
serverIP := serverService.Items[0].Spec.ClusterIP

proxyOut, err := cli.Run(t, ctx.KubectlOptions(t), "troubleshoot", "proxy", "-pod", clientPodName, "-upstream-ip", serverIP)
proxyOut, err := cli.Run(ctx.KubectlOptions(t), "troubleshoot", "proxy", "-pod", clientPodName, "-upstream-ip", serverIP)
require.NoError(t, err)
require.Regexp(t, "Upstream resources are valid", string(proxyOut))
logger.Log(t, string(proxyOut))
} else {
// With tproxy disabled and explicit upstreams we need the envoy-id of the server
require.Regexp(t, "static-server", string(upstreamsOut))

proxyOut, err := cli.Run(t, ctx.KubectlOptions(t), "troubleshoot", "proxy", "-pod", clientPodName, "-upstream-envoy-id", "static-server")
proxyOut, err := cli.Run(ctx.KubectlOptions(t), "troubleshoot", "proxy", "-pod", clientPodName, "-upstream-envoy-id", "static-server")
require.NoError(t, err)
require.Regexp(t, "Upstream resources are valid", string(proxyOut))
logger.Log(t, string(proxyOut))
Expand Down
58 changes: 29 additions & 29 deletions acceptance/tests/config-entries/config_entries_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,35 +242,35 @@ func TestControllerNamespaces(t *testing.T) {
require.NoError(r, err)
rateLimitIPConfigEntry, ok := entry.(*api.RateLimitIPConfigEntry)
require.True(r, ok, "could not cast to RateLimitIPConfigEntry")
require.Equal(t, "permissive", rateLimitIPConfigEntry.Mode)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ACL.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ACL.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Catalog.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Catalog.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConfigEntry.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConfigEntry.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConnectCA.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.ConnectCA.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Coordinate.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Coordinate.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.DiscoveryChain.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.DiscoveryChain.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Health.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Health.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Intention.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Intention.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.KV.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.KV.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Tenancy.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Tenancy.WriteRate)
//require.Equal(t, 100.0, rateLimitIPConfigEntry.PreparedQuery.ReadRate)
//require.Equal(t, 100.0, rateLimitIPConfigEntry.PreparedQuery.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Session.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Session.WriteRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.ReadRate)
require.Equal(t, 100.0, rateLimitIPConfigEntry.Txn.WriteRate)
require.Equal(r, "permissive", rateLimitIPConfigEntry.Mode)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ACL.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ACL.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Catalog.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Catalog.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ConfigEntry.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ConfigEntry.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ConnectCA.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.ConnectCA.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Coordinate.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Coordinate.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.DiscoveryChain.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.DiscoveryChain.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Health.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Health.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Intention.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Intention.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.KV.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.KV.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Tenancy.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Tenancy.WriteRate)
//require.Equal(r, 100.0, rateLimitIPConfigEntry.PreparedQuery.ReadRate)
//require.Equal(r, 100.0, rateLimitIPConfigEntry.PreparedQuery.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Session.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Session.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Txn.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Txn.WriteRate)
})
}

Expand Down
10 changes: 5 additions & 5 deletions acceptance/tests/config-entries/config_entries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func TestController(t *testing.T) {
// endpoint fails initially.
out, err := k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), "apply", "-k", "../fixtures/bases/crds-oss")
require.NoError(r, err, out)
helpers.Cleanup(t, cfg.NoCleanupOnFailure, func() {
// Ignore errors here because if the test ran as expected
// the custom resources will have been deleted.
k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), "delete", "-k", "../fixtures/bases/crds-oss")
})
})
helpers.Cleanup(t, cfg.NoCleanupOnFailure, func() {
// Ignore errors here because if the test ran as expected
// the custom resources will have been deleted.
k8s.RunKubectlAndGetOutputE(t, ctx.KubectlOptions(t), "delete", "-k", "../fixtures/bases/crds-oss")
})

// On startup, the controller can take upwards of 1m to perform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func TestRun_WaitsForMeshGatewayInstances(t *testing.T) {
CAFile: caFile,
},
})
require.NoError(t, err)
require.NoError(r, err)
})

err = client.Agent().ServiceRegister(&api.AgentServiceRegistration{
Expand Down Expand Up @@ -825,7 +825,7 @@ func TestRun_ReplicationSecretDelay(t *testing.T) {
},
},
metav1.CreateOptions{})
require.NoError(t, err)
require.NoError(r, err)
})
}()

Expand Down Expand Up @@ -1005,7 +1005,7 @@ func TestRun_ConsulClientDelay(t *testing.T) {
Server: randomPorts[5],
}
})
require.NoError(t, err)
require.NoError(r, err)
})

// Construct Consul client.
Expand Down

0 comments on commit fdeccab

Please sign in to comment.