chore(e2e): fix linting errors for e2e files (#6307)

pull/6311/head
Tony 4 months ago committed by GitHub
parent f56158b7df
commit 5560121c3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -373,11 +373,10 @@ func WaitForNumberOfHostsInHostSetCli(t testing.TB, ctx context.Context, hostSet
actualHostSetCount = len(hostSetsReadResult.Item.HostIds)
if actualHostSetCount != expectedHostCount {
return errors.New(
fmt.Sprintf("Number of hosts in host set do not match expected. EXPECTED: %d, ACTUAL: %d",
expectedHostCount,
actualHostSetCount,
))
return fmt.Errorf("Number of hosts in host set do not match expected. EXPECTED: %d, ACTUAL: %d",
expectedHostCount,
actualHostSetCount,
)
}
t.Logf("Found %d host(s)", actualHostSetCount)

@ -95,10 +95,10 @@ func WaitForSessionStatusCli(t testing.TB, ctx context.Context, sessionId string
s := sessionReadResult.Item
if s.Status != status {
return errors.New(fmt.Sprintf("Waiting for session status... Expected: %s, Actual: %s",
return fmt.Errorf("Waiting for session status... Expected: %s, Actual: %s",
status,
sessionReadResult.Item.Status,
))
)
}
return nil

@ -145,7 +145,7 @@ func CreateTargetCli(t testing.TB, ctx context.Context, projectId string, defaul
if opts.WithDefaultClientPort != 0 {
args = append(args, e2e.WithArgs("-default-client-port", fmt.Sprintf("%d", opts.WithDefaultClientPort)))
}
if opts.WithEnableSessionRecording != false {
if opts.WithEnableSessionRecording {
args = append(args, e2e.WithArgs("-enable-session-recording", fmt.Sprintf("%v", opts.WithEnableSessionRecording)))
}
if opts.WithStorageBucketId != "" {
@ -212,7 +212,7 @@ func UpdateTargetCli(t testing.TB, ctx context.Context, targetId string, opt ...
if opts.WithDefaultClientPort != 0 {
args = append(args, "-default-client-port", fmt.Sprintf("%d", opts.WithDefaultClientPort))
}
if opts.WithEnableSessionRecording != false {
if opts.WithEnableSessionRecording {
args = append(args, "-enable-session-recording", fmt.Sprintf("%v", opts.WithEnableSessionRecording))
}
if opts.WithStorageBucketId != "" {

@ -97,7 +97,7 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
if !(bytesUp > 0 && bytesDown > 0) {
if bytesUp <= 0 || bytesDown <= 0 {
return fmt.Errorf(
"bytes_up: %d, bytes_down: %d, bytes_up or bytes_down is not greater than 0",
bytesUp,

@ -101,7 +101,7 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
if !(bytesUp > 0 && bytesDown > 0) {
if bytesUp <= 0 || bytesDown <= 0 {
return fmt.Errorf(
"bytes_up: %d, bytes_down: %d, bytes_up or bytes_down is not greater than 0",
bytesUp,
@ -143,7 +143,7 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
newBytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
newBytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
if !(newBytesDown > bytesDown) {
if newBytesDown <= bytesDown {
return fmt.Errorf(
"bytes_up: %d, bytes_down: %d, bytes_up/bytes_down is not greater than previous value",
newBytesUp,

@ -226,12 +226,10 @@ func TestCliSearch(t *testing.T) {
}
if statusResult.Item.Users[0].Resources[idx].Count != currentCount+c.MaxPageSize+1 {
return errors.New(
fmt.Sprintf(
"Did not see expected number of targets in status, EXPECTED: %d, ACTUAL: %d",
currentCount+c.MaxPageSize+1,
statusResult.Item.Users[0].Resources[idx].Count,
),
return fmt.Errorf(
"Did not see expected number of targets in status, EXPECTED: %d, ACTUAL: %d",
currentCount+c.MaxPageSize+1,
statusResult.Item.Users[0].Resources[idx].Count,
)
}
@ -353,12 +351,10 @@ func TestCliSearch(t *testing.T) {
}
if len(searchResult.Item.Targets) != len(targetIds) {
return errors.New(
fmt.Sprintf(
"Search did not return expected number of targets, EXPECTED: %d, ACTUAL: %d",
len(targetIds),
len(searchResult.Item.Targets),
),
return fmt.Errorf(
"Search did not return expected number of targets, EXPECTED: %d, ACTUAL: %d",
len(targetIds),
len(searchResult.Item.Targets),
)
}

@ -109,7 +109,7 @@ func TestCliTcpTargetConnectCassandra(t *testing.T) {
_, err = f.Write([]byte("DESCRIBE KEYSPACES;\n"))
require.NoError(t, err)
_, err = f.Write([]byte(fmt.Sprintf("SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = '%s';\n", keyspace)))
_, err = fmt.Fprintf(f, "SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = '%s';\n", keyspace)
require.NoError(t, err)
_, err = f.Write([]byte("exit\n"))
require.NoError(t, err)

@ -48,8 +48,7 @@ func TestCliTcpTargetConnectHttp(t *testing.T) {
// Connect to a target and enable port forwarding
localPort := "8080"
destPort := "8000"
var cmd *exec.Cmd
cmd = exec.CommandContext(ctx,
cmd := exec.CommandContext(ctx,
"boundary",
"connect", "ssh",
"-target-id", targetId, "--",
@ -72,9 +71,9 @@ Server: netcat-can-you-believe-it
<html>Hello World!</html>
`
go func() {
_, err = f.Write([]byte(fmt.Sprintf("echo '%s' > somepage.html\n", htmlPage)))
_, err = fmt.Fprintf(f, "echo '%s' > somepage.html\n", htmlPage)
require.NoError(t, err)
_, err = f.Write([]byte(fmt.Sprintf("while true; do nc -l -p %s -q 1 < somepage.html; done\n", destPort)))
_, err = fmt.Fprintf(f, "while true; do nc -l -p %s -q 1 < somepage.html; done\n", destPort)
require.NoError(t, err)
_, _ = io.Copy(io.Discard, f) // Not checking error here since it will return an error on session close
}()

@ -6,7 +6,6 @@ package base_plus_test
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@ -453,18 +452,18 @@ func getRateLimitStat(rateLimitHeader, stat string) (int, error) {
if strings.Contains(s, stat) {
parts := strings.Split(s, "=")
if len(parts) != 2 {
return 0, errors.New(fmt.Sprintf("Expected length of 2: VALUE: %s", parts))
return 0, fmt.Errorf("Expected length of 2: VALUE: %s", parts)
}
count, err := strconv.Atoi(parts[1])
if err != nil {
return 0, errors.New(fmt.Sprintf("Expected a number: VALUE: %s", parts[1]))
return 0, fmt.Errorf("Expected a number: VALUE: %s", parts[1])
}
return count, nil
}
}
return 0, errors.New(fmt.Sprintf("Could not parse header, STAT: %s, HEADER: %s", stat, rateLimitHeader))
return 0, fmt.Errorf("Could not parse header, STAT: %s, HEADER: %s", stat, rateLimitHeader)
}
func getRateLimitPolicyStat(rateLimitPolicyHeader, stat string) (limit int, period int, err error) {
@ -473,23 +472,23 @@ func getRateLimitPolicyStat(rateLimitPolicyHeader, stat string) (limit int, peri
if strings.Contains(s, stat) {
parts := strings.Split(s, ";")
if len(parts) != 3 {
return 0, 0, errors.New(fmt.Sprintf("Expected length of 3: VALUE: %s", parts))
return 0, 0, fmt.Errorf("Expected length of 3: VALUE: %s", parts)
}
limit, err := strconv.Atoi(parts[0])
if err != nil {
return 0, 0, errors.New(fmt.Sprintf("Expected a number: VALUE: %s", parts[0]))
return 0, 0, fmt.Errorf("Expected a number: VALUE: %s", parts[0])
}
policyParts := strings.Split(parts[1], "=")
if len(policyParts) != 2 {
return 0, 0, errors.New(fmt.Sprintf("Expected length of 2: VALUE: %s", policyParts))
return 0, 0, fmt.Errorf("Expected length of 2: VALUE: %s", policyParts)
}
period, err := strconv.Atoi(policyParts[1])
if err != nil {
return 0, 0, errors.New(fmt.Sprintf("Expected a number: VALUE: %d", period))
return 0, 0, fmt.Errorf("Expected a number: VALUE: %d", period)
}
return limit, period, nil
}
}
return 0, 0, errors.New(fmt.Sprintf("Could not parse header, STAT: %s, HEADER: %s", stat, rateLimitPolicyHeader))
return 0, 0, fmt.Errorf("Could not parse header, STAT: %s, HEADER: %s", stat, rateLimitPolicyHeader)
}

@ -58,8 +58,7 @@ func TestCliTcpTargetConnectPostgres(t *testing.T) {
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialId)
require.NoError(t, err)
var cmd *exec.Cmd
cmd = exec.CommandContext(ctx,
cmd := exec.CommandContext(ctx,
"boundary",
"connect", "postgres",
"-target-id", targetId,

@ -49,10 +49,10 @@ func TestAuthMethodOidcVault(t *testing.T) {
require.NoError(t, err)
authPolicyFile, err := os.OpenFile(authPolicyPath, os.O_APPEND|os.O_WRONLY, 0o644)
require.NoError(t, err)
_, err = authPolicyFile.WriteString(fmt.Sprintf(
`path "identity/oidc/provider/my-provider/authorize" { capabilities = [ "read" ] }%s`,
"\n",
))
_, err = fmt.Fprintf(authPolicyFile,
"path \"identity/oidc/provider/my-provider/authorize\" { capabilities = [ \"read\" ] }\n",
)
require.NoError(t, err)
require.NoError(t, err)
authPolicyName := vault.WritePolicy(t, ctx, authPolicyPath)
t.Cleanup(func() {
@ -359,9 +359,7 @@ func TestAuthMethodOidcVault(t *testing.T) {
res, err := http.Post(
fmt.Sprintf("%s/v1/auth-methods/%s:authenticate", boundary.GetAddr(t), authMethodId),
"application/json",
strings.NewReader(
fmt.Sprintf(`{"command": "start"}`),
),
strings.NewReader(`{"command": "start"}`),
)
require.NoError(t, err)
t.Cleanup(func() {

@ -104,6 +104,7 @@ func setupEnvironment(t testing.TB, c *config, boundaryRepo, boundaryTag string)
t.Logf("Could not access Vault URL: %s. Retrying...", err.Error())
return err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return fmt.Errorf("Could not connect to %s. Status Code: %d", v.UriLocalhost, response.StatusCode)
@ -165,7 +166,9 @@ func setupEnvironment(t testing.TB, c *config, boundaryRepo, boundaryTag string)
// Start a Boundary server and wait until Boundary has finished loading
b := infra.StartBoundary(t, pool, network, boundaryRepo, boundaryTag, db.UriNetwork)
t.Cleanup(func() {
pool.Purge(b.Resource)
if err := pool.Purge(b.Resource); err != nil {
t.Logf("error purging pool: %v", err)
}
})
os.Setenv("BOUNDARY_ADDR", b.UriLocalhost)

Loading…
Cancel
Save