mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-05 07:37:12 +00:00
Bump golangci-lint to 2.3.0 and fix issues
This commit is contained in:
@@ -23,7 +23,7 @@ func runTestKubectlCommand(t *testing.T, args ...string) (string, string) {
|
||||
testlib.RequireEventually(t, func(requireEventually *require.Assertions) {
|
||||
stdOut.Reset()
|
||||
stdErr.Reset()
|
||||
cmd := exec.Command("kubectl", args...)
|
||||
cmd := exec.CommandContext(t.Context(), "kubectl", args...)
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
requireEventually.NoError(cmd.Run())
|
||||
|
||||
@@ -110,13 +110,14 @@ type testingT interface {
|
||||
Errorf(format string, args ...any)
|
||||
FailNow()
|
||||
Logf(format string, args ...any)
|
||||
Context() context.Context
|
||||
}
|
||||
|
||||
func runPinnipedCLI(t testingT, envVars []string, pinnipedExe string, args ...string) (string, string) {
|
||||
t.Helper()
|
||||
start := time.Now()
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd := exec.Command(pinnipedExe, args...)
|
||||
cmd := exec.CommandContext(t.Context(), pinnipedExe, args...)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
cmd.Env = envVars
|
||||
|
||||
@@ -701,8 +701,7 @@ func performKubectlApply(t *testing.T, resourceName string, yamlBytes []byte) (s
|
||||
|
||||
t.Cleanup(func() {
|
||||
t.Helper()
|
||||
//nolint:gosec // this is test code.
|
||||
require.NoError(t, exec.Command("kubectl", []string{"delete", "--ignore-not-found", "-f", yamlFilepath}...).Run())
|
||||
require.NoError(t, exec.CommandContext(t.Context(), "kubectl", "delete", "--ignore-not-found", "-f", yamlFilepath).Run())
|
||||
})
|
||||
|
||||
return stdOut.String(), stdErr.String(), err
|
||||
|
||||
@@ -729,7 +729,7 @@ func requireKubectlExplainShowsDescriptionForResource(t *testing.T, resourceName
|
||||
func runKubectlVersion(t *testing.T) {
|
||||
t.Helper()
|
||||
t.Log("Running: kubectl version")
|
||||
out, err := exec.Command("kubectl", "version").CombinedOutput()
|
||||
out, err := exec.CommandContext(t.Context(), "kubectl", "version").CombinedOutput()
|
||||
require.NoError(t, err)
|
||||
t.Log(string(out))
|
||||
}
|
||||
@@ -737,7 +737,7 @@ func runKubectlVersion(t *testing.T) {
|
||||
func runKubectlExplain(t *testing.T, resourceName string, apiVersion string) string {
|
||||
t.Helper()
|
||||
var stdOut, stdErr bytes.Buffer
|
||||
cmd := exec.Command("kubectl", "explain", resourceName, "--api-version", apiVersion, "--output", "plaintext-openapiv2")
|
||||
cmd := exec.CommandContext(t.Context(), "kubectl", "explain", resourceName, "--api-version", apiVersion, "--output", "plaintext-openapiv2")
|
||||
t.Log("Running:", cmd.String())
|
||||
cmd.Stdout = &stdOut
|
||||
cmd.Stderr = &stdErr
|
||||
|
||||
@@ -856,7 +856,8 @@ func findRecentlyUnusedLocalhostPorts(t *testing.T, howManyPorts int) []string {
|
||||
listeners := make([]net.Listener, howManyPorts)
|
||||
for i := range howManyPorts {
|
||||
var err error
|
||||
listeners[i], err = net.Listen("tcp", "127.0.0.1:0")
|
||||
listenConfig := net.ListenConfig{}
|
||||
listeners[i], err = listenConfig.Listen(t.Context(), "tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// Smoke test to see if the kubeconfig works and the cluster is reachable.
|
||||
func TestGetNodes(t *testing.T) {
|
||||
_ = testlib.IntegrationEnv(t)
|
||||
cmd := exec.Command("kubectl", "get", "nodes")
|
||||
cmd := exec.CommandContext(t.Context(), "kubectl", "get", "nodes")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
|
||||
@@ -670,10 +670,6 @@ func requireJWKSEndpointIsWorking(t *testing.T, supervisorScheme, supervisorAddr
|
||||
}
|
||||
|
||||
func printServerCert(t *testing.T, address string, dnsOverrides map[string]string) {
|
||||
conf := &tls.Config{
|
||||
InsecureSkipVerify: true, //nolint:gosec // this is for testing purposes
|
||||
}
|
||||
|
||||
addressURL, err := url.Parse(address)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -691,10 +687,16 @@ func printServerCert(t *testing.T, address string, dnsOverrides map[string]strin
|
||||
host = dnsOverrides[host]
|
||||
}
|
||||
|
||||
conn, err := tls.Dial("tcp", host, conf)
|
||||
dialer := tls.Dialer{
|
||||
Config: &tls.Config{
|
||||
InsecureSkipVerify: true, //nolint:gosec // this is for testing purposes
|
||||
},
|
||||
}
|
||||
netConn, err := dialer.DialContext(t.Context(), "tcp", host)
|
||||
tlsConn := tls.Client(netConn, dialer.Config)
|
||||
require.NoError(t, err)
|
||||
defer func() { _ = conn.Close() }()
|
||||
certs := conn.ConnectionState().PeerCertificates
|
||||
defer func() { _ = netConn.Close() }()
|
||||
certs := tlsConn.ConnectionState().PeerCertificates
|
||||
for i, cert := range certs {
|
||||
t.Logf("found cert %d of %d for host=%q with dns=%+v and ips=%+v",
|
||||
i+1,
|
||||
|
||||
@@ -154,7 +154,8 @@ func runKubectlGetNamespaces(t *testing.T, kubeConfigYAML string) (string, error
|
||||
f := writeStringToTempFile(t, "pinniped-generated-kubeconfig-*", kubeConfigYAML)
|
||||
|
||||
//nolint:gosec // It's okay that we are passing f.Name() to an exec command here. It was created above.
|
||||
output, err := exec.Command(
|
||||
output, err := exec.CommandContext(
|
||||
t.Context(),
|
||||
"kubectl", "get", "namespace", "--kubeconfig", f.Name(),
|
||||
).CombinedOutput()
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ func PinnipedCLIPath(t *testing.T) string {
|
||||
|
||||
t.Log("building pinniped CLI binary")
|
||||
start := time.Now()
|
||||
output, err := exec.Command("go", "build", "-o", path, "go.pinniped.dev/cmd/pinniped").CombinedOutput()
|
||||
output, err := exec.CommandContext(t.Context(), "go", "build", "-o", path, "go.pinniped.dev/cmd/pinniped").CombinedOutput()
|
||||
require.NoError(t, err, string(output))
|
||||
t.Logf("built CLI binary in %s", time.Since(start).Round(time.Millisecond))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user