refact(e2e): Update RunCommand to have context argument

This commit is contained in:
Michael Li committed 2022-10-19 10:46:57 -04:00
1 parent 84aa65ccc5
commit a4e27d877d
12 files changed
+64 -76

No files matched your search

@@ -1,6 +1,7 @@
package static_test
import (
"context"
"encoding/json"
"fmt"
"os"
@@ -34,7 +35,8 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
// Create a credential store
output := e2e.RunCommand("boundary", "credential-stores", "create", "static",
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "credential-stores", "create", "static",
"-scope-id", newProjectId,
"-format", "json",
)
@@ -46,7 +48,7 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
t.Logf("Created Credential Store: %s", newCredentialStoreId)
// Create credentials
output = e2e.RunCommand("boundary", "credentials", "create", "ssh-private-key",
output = e2e.RunCommand(ctx, "boundary", "credentials", "create", "ssh-private-key",
"-credential-store-id", newCredentialStoreId,
"-username", c.TargetSshUser,
"-private-key", "file://"+c.TargetSshKeyPath,
@@ -60,14 +62,14 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
t.Logf("Created Credentials: %s", newCredentialsId)
// Add credentials to target
output = e2e.RunCommand("boundary", "targets", "add-credential-sources",
output = e2e.RunCommand(ctx, "boundary", "targets", "add-credential-sources",
"-id", newTargetId,
"-brokered-credential-source", newCredentialsId,
)
require.NoError(t, output.Err, string(output.Stderr))
// Get credentials for target
output = e2e.RunCommand("boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
output = e2e.RunCommand(ctx, "boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
@@ -96,7 +98,7 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
require.NoError(t, err)
// Connect to target and print host's IP address using retrieved credentials
output = e2e.RunCommand("boundary", "connect",
output = e2e.RunCommand(ctx, "boundary", "connect",
"-authz-token", newAuthToken,
"-exec", "/usr/bin/ssh", "--",
"-l", retrievedUser,
@@ -35,7 +35,8 @@ func TestConnectTargetWithSshCli(t *testing.T) {
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
// Create a credential store
output := e2e.RunCommand("boundary", "credential-stores", "create", "static",
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "credential-stores", "create", "static",
"-scope-id", newProjectId,
"-format", "json",
)
@@ -47,7 +48,7 @@ func TestConnectTargetWithSshCli(t *testing.T) {
t.Logf("Created Credential Store: %s", newCredentialStoreId)
// Create credentials
output = e2e.RunCommand("boundary", "credentials", "create", "ssh-private-key",
output = e2e.RunCommand(ctx, "boundary", "credentials", "create", "ssh-private-key",
"-credential-store-id", newCredentialStoreId,
"-username", c.TargetSshUser,
"-private-key", "file://"+c.TargetSshKeyPath,
@@ -61,14 +62,14 @@ func TestConnectTargetWithSshCli(t *testing.T) {
t.Logf("Created Credentials: %s", newCredentialsId)
// Add credentials to target
output = e2e.RunCommand("boundary", "targets", "add-credential-sources",
output = e2e.RunCommand(ctx, "boundary", "targets", "add-credential-sources",
"-id", newTargetId,
"-brokered-credential-source", newCredentialsId,
)
require.NoError(t, output.Err, string(output.Stderr))
// Get credentials for target
output = e2e.RunCommand("boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
output = e2e.RunCommand(ctx, "boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
@@ -85,7 +86,7 @@ func TestConnectTargetWithSshCli(t *testing.T) {
t.Log("Successfully retrieved credentials for target")
// Connect to target and print host's IP address using retrieved credentials
output = e2e.RunCommand("boundary", "connect", "ssh",
output = e2e.RunCommand(ctx, "boundary", "connect", "ssh",
"-target-id", newTargetId, "--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
@@ -29,7 +29,8 @@ func TestConnectTargetCli(t *testing.T) {
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
// Connect to target and print host's IP address
output := e2e.RunCommand("boundary", "connect",
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "connect",
"-target-id", newTargetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
@@ -31,10 +31,10 @@ func TestSessionCancelingCli(t *testing.T) {
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
// Connect to target to create a session
ctx, cancel := context.WithCancel(context.Background())
ctxCancel, cancel := context.WithCancel(context.Background())
errChan := make(chan *e2e.CommandResult)
go func() {
errChan <- e2e.RunCommandContext(ctx, "boundary", "connect",
errChan <- e2e.RunCommand(ctxCancel, "boundary", "connect",
"-target-id", newTargetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
@@ -50,10 +50,11 @@ func TestSessionCancelingCli(t *testing.T) {
t.Cleanup(cancel)
// Get list of sessions
ctx := context.Background()
var session *sessions.Session
err = backoff.RetryNotify(
func() error {
output := e2e.RunCommand("boundary", "sessions", "list", "-scope-id", newProjectId, "-format", "json")
output := e2e.RunCommand(ctx, "boundary", "sessions", "list", "-scope-id", newProjectId, "-format", "json")
if output.Err != nil {
return backoff.Permanent(errors.New(string(output.Stderr)))
}
@@ -88,10 +89,10 @@ func TestSessionCancelingCli(t *testing.T) {
require.Equal(t, "active", session.Status)
// Cancel session
output := e2e.RunCommand("boundary", "sessions", "cancel", "-id", session.Id)
output := e2e.RunCommand(ctx, "boundary", "sessions", "cancel", "-id", session.Id)
require.NoError(t, output.Err, string(output.Stderr))
output = e2e.RunCommand("boundary", "sessions", "read", "-id", session.Id, "-format", "json")
output = e2e.RunCommand(ctx, "boundary", "sessions", "read", "-id", session.Id, "-format", "json")
require.NoError(t, output.Err, string(output.Stderr))
var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult)