From 3cae4933c07bc9fd4f77958bd85b2b2672874bd4 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Thu, 30 Nov 2023 09:38:07 -0500 Subject: [PATCH] test(e2e): Update migration test with additional resources (#4069) * test(e2e): Add descriptions to resources * test(e2e): Add more resources to migration test --- testing/internal/e2e/boundary/account.go | 2 +- testing/internal/e2e/boundary/credential.go | 5 +++ testing/internal/e2e/boundary/group.go | 1 + testing/internal/e2e/boundary/host.go | 5 +++ testing/internal/e2e/boundary/role.go | 1 + testing/internal/e2e/boundary/scope.go | 2 ++ testing/internal/e2e/boundary/target.go | 1 + testing/internal/e2e/boundary/user.go | 2 +- .../e2e/tests/database/migration_test.go | 33 +++++++++++++++++-- 9 files changed, 48 insertions(+), 4 deletions(-) diff --git a/testing/internal/e2e/boundary/account.go b/testing/internal/e2e/boundary/account.go index 38eef60a9f..097da8d7a8 100644 --- a/testing/internal/e2e/boundary/account.go +++ b/testing/internal/e2e/boundary/account.go @@ -47,7 +47,7 @@ func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string, "-login-name", loginName, "-password", "env://E2E_TEST_ACCOUNT_PASSWORD", "-name", "e2e Account "+loginName, - "-description", "e2e Account", + "-description", "e2e", "-format", "json", ), e2e.WithEnv("E2E_TEST_ACCOUNT_PASSWORD", password), diff --git a/testing/internal/e2e/boundary/credential.go b/testing/internal/e2e/boundary/credential.go index f65787cd4b..3cd2edfda4 100644 --- a/testing/internal/e2e/boundary/credential.go +++ b/testing/internal/e2e/boundary/credential.go @@ -36,6 +36,7 @@ func CreateNewCredentialStoreVaultCli(t testing.TB, ctx context.Context, project "-scope-id", projectId, "-vault-address", vaultAddr, "-vault-token", vaultToken, + "-description", "e2e", "-format", "json", ), ) @@ -56,6 +57,7 @@ func CreateNewCredentialStoreStaticCli(t testing.TB, ctx context.Context, projec e2e.WithArgs( "credential-stores", "create", "static", "-scope-id", projectId, + "-description", "e2e", "-format", "json", ), ) @@ -79,6 +81,7 @@ func CreateNewStaticCredentialPrivateKeyCli(t testing.TB, ctx context.Context, c "-credential-store-id", credentialStoreId, "-username", user, "-private-key", "file://"+filePath, + "-description", "e2e", "-format", "json", ), ) @@ -102,6 +105,7 @@ func CreateNewStaticCredentialPasswordCli(t testing.TB, ctx context.Context, cre "-credential-store-id", credentialStoreId, "-username", user, "-password", "env://E2E_CREDENTIALS_PASSWORD", + "-description", "e2e", "-format", "json", ), e2e.WithEnv("E2E_CREDENTIALS_PASSWORD", password), @@ -125,6 +129,7 @@ func CreateNewStaticCredentialJsonCli(t testing.TB, ctx context.Context, credent "credentials", "create", "json", "-credential-store-id", credentialStoreId, "-object", "file://"+jsonFilePath, + "-description", "e2e", "-format", "json", ), ) diff --git a/testing/internal/e2e/boundary/group.go b/testing/internal/e2e/boundary/group.go index 23b04b0642..d4116c3efc 100644 --- a/testing/internal/e2e/boundary/group.go +++ b/testing/internal/e2e/boundary/group.go @@ -20,6 +20,7 @@ func CreateNewGroupCli(t testing.TB, ctx context.Context, scopeId string) string e2e.WithArgs( "groups", "create", "-scope-id", "global", + "-description", "e2e", "-format", "json", ), ) diff --git a/testing/internal/e2e/boundary/host.go b/testing/internal/e2e/boundary/host.go index c5fb196271..a90339a55b 100644 --- a/testing/internal/e2e/boundary/host.go +++ b/testing/internal/e2e/boundary/host.go @@ -74,6 +74,7 @@ func CreateNewHostCatalogCli(t testing.TB, ctx context.Context, projectId string "host-catalogs", "create", "static", "-scope-id", projectId, "-name", "e2e Host Catalog", + "-description", "e2e", "-format", "json", ), ) @@ -95,6 +96,7 @@ func CreateNewHostSetCli(t testing.TB, ctx context.Context, hostCatalogId string "host-sets", "create", "static", "-host-catalog-id", hostCatalogId, "-name", "e2e Host Set", + "-description", "e2e", "-format", "json", ), ) @@ -116,6 +118,7 @@ func CreateNewHostCli(t testing.TB, ctx context.Context, hostCatalogId string, a "hosts", "create", "static", "-host-catalog-id", hostCatalogId, "-name", address, + "-description", "e2e", "-address", address, "-format", "json", ), @@ -150,6 +153,7 @@ func CreateNewAwsHostCatalogCli(t testing.TB, ctx context.Context, projectId str "-attr", "region=us-east-1", "-secret", "access_key_id=env://E2E_AWS_ACCESS_KEY_ID", "-secret", "secret_access_key=env://E2E_AWS_SECRET_ACCESS_KEY", + "-description", "e2e", "-format", "json", ), e2e.WithEnv("E2E_AWS_ACCESS_KEY_ID", accessKeyId), @@ -173,6 +177,7 @@ func CreateNewAwsHostSetCli(t testing.TB, ctx context.Context, hostCatalogId str "host-sets", "create", "plugin", "-host-catalog-id", hostCatalogId, "-attr", "filters="+filter, + "-description", "e2e", "-format", "json", ), ) diff --git a/testing/internal/e2e/boundary/role.go b/testing/internal/e2e/boundary/role.go index 55f6de3166..eb4bc42190 100644 --- a/testing/internal/e2e/boundary/role.go +++ b/testing/internal/e2e/boundary/role.go @@ -21,6 +21,7 @@ func CreateNewRoleCli(t testing.TB, ctx context.Context, scopeId string) string "roles", "create", "-scope-id", scopeId, "-name", "e2e Role", + "-description", "e2e", "-format", "json", ), ) diff --git a/testing/internal/e2e/boundary/scope.go b/testing/internal/e2e/boundary/scope.go index 1e07121eeb..5ca3509f50 100644 --- a/testing/internal/e2e/boundary/scope.go +++ b/testing/internal/e2e/boundary/scope.go @@ -46,6 +46,7 @@ func CreateNewOrgCli(t testing.TB, ctx context.Context) string { e2e.WithArgs( "scopes", "create", "-name", "e2e Org", + "-description", "e2e", "-scope-id", "global", "-format", "json", ), @@ -71,6 +72,7 @@ func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string, opt .. args = append(args, "scopes", "create", "-scope-id", orgId, + "-description", "e2e", "-format", "json", ) diff --git a/testing/internal/e2e/boundary/target.go b/testing/internal/e2e/boundary/target.go index c05240cfbe..64473326b4 100644 --- a/testing/internal/e2e/boundary/target.go +++ b/testing/internal/e2e/boundary/target.go @@ -60,6 +60,7 @@ func CreateNewTargetCli(t testing.TB, ctx context.Context, projectId string, def args = append(args, "-scope-id", projectId, "-default-port", defaultPort, + "-description", "e2e", "-format", "json", ) diff --git a/testing/internal/e2e/boundary/user.go b/testing/internal/e2e/boundary/user.go index ac66c60a64..a213dedc11 100644 --- a/testing/internal/e2e/boundary/user.go +++ b/testing/internal/e2e/boundary/user.go @@ -34,7 +34,7 @@ func CreateNewUserCli(t testing.TB, ctx context.Context, scopeId string) string "users", "create", "-scope-id", scopeId, "-name", "e2e User", - "-description", "e2e User", + "-description", "e2e", "-format", "json", ), ) diff --git a/testing/internal/e2e/tests/database/migration_test.go b/testing/internal/e2e/tests/database/migration_test.go index 91486dc7ea..a8f11538a5 100644 --- a/testing/internal/e2e/tests/database/migration_test.go +++ b/testing/internal/e2e/tests/database/migration_test.go @@ -16,6 +16,8 @@ import ( "time" "github.com/hashicorp/boundary/api/credentiallibraries" + "github.com/hashicorp/boundary/api/workers" + "github.com/hashicorp/boundary/internal/target" "github.com/hashicorp/boundary/testing/internal/e2e" "github.com/hashicorp/boundary/testing/internal/e2e/boundary" "github.com/hashicorp/boundary/testing/internal/e2e/infra" @@ -48,7 +50,6 @@ func TestDatabaseMigration(t *testing.T) { boundaryRepo := "hashicorp/boundary" boundaryTag := "latest" - te := setupEnvironment(t, ctx, c, boundaryRepo, boundaryTag) populateBoundaryDatabase(t, ctx, c, te, boundaryRepo, boundaryTag) @@ -201,7 +202,7 @@ func setupEnvironment(t testing.TB, ctx context.Context, c *config, boundaryRepo func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te TestEnvironment, boundaryRepo, boundaryTag string) { // Create resources for target. Uses the local CLI so that these methods can be reused. // While the CLI version used won't necessarily match the controller version, it should be (and is - // supposed to be) backwards ompatible + // supposed to be) backwards compatible boundary.AuthenticateCli(t, ctx, te.DbInitInfo.AuthMethod.AuthMethodId, te.DbInitInfo.AuthMethod.LoginName, te.DbInitInfo.AuthMethod.Password) newOrgId := boundary.CreateNewOrgCli(t, ctx) newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId) @@ -212,6 +213,16 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, "2222") // openssh-server uses port 2222 boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId) + // Create a target with an address attached + _ = boundary.CreateNewTargetCli( + t, + ctx, + newProjectId, + "2222", + target.WithName("e2e target with address"), + target.WithAddress(te.Target.UriNetwork), + ) + // Create AWS dynamic host catalog newAwsHostCatalogId := boundary.CreateNewAwsHostCatalogCli(t, ctx, newProjectId, c.AwsAccessKeyId, c.AwsSecretAccessKey) newAwsHostSetId := boundary.CreateNewAwsHostSetCli(t, ctx, newAwsHostCatalogId, c.AwsHostSetFilter) @@ -275,6 +286,7 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T "-vault-path", c.VaultSecretPath+"/data/"+privateKeySecretName, "-name", "e2e Automated Test Vault Credential Library", "-credential-type", "ssh_private_key", + "-description", "e2e", "-format", "json", ), ) @@ -293,6 +305,7 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T "-vault-path", c.VaultSecretPath+"/data/"+passwordSecretName, "-name", "e2e Automated Test Vault Credential Library - Password", "-credential-type", "username_password", + "-description", "e2e", "-format", "json", ), ) @@ -302,6 +315,22 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T newPasswordCredentialLibraryId := newCredentialLibraryResult.Item.Id t.Logf("Created Credential Library: %s", newPasswordCredentialLibraryId) + // Create a worker + output = e2e.RunCommand(ctx, "boundary", + e2e.WithArgs( + "workers", "create", "controller-led", + "-name", "e2e worker", + "-description", "e2e", + "-format", "json", + ), + ) + require.NoError(t, output.Err, string(output.Stderr)) + var newWorkerResult workers.WorkerCreateResult + err = json.Unmarshal(output.Stdout, &newWorkerResult) + require.NoError(t, err) + newWorkerId := newWorkerResult.Item.Id + t.Logf("Created Worker: %s", newWorkerId) + // Create a session. Uses Boundary in a docker container to do the connect in order to avoid // modifying the runner's /etc/hosts file. Otherwise, you would need to add a `127.0.0.1 // localhost boundary` entry into /etc/hosts.