test(e2e): Add test to connect to target via its name and scope (#3387)

This commit is contained in:
Stan Ryzhov authored and GitHub committed 2023-07-06 16:41:39 -04:00
1 parent a8e363888a
commit 732973c7b8
3 files changed
+125 -8

No files matched your search

+43 -7
View File
@@ -64,14 +64,24 @@ func CreateNewOrgCli(t testing.TB, ctx context.Context) string {
// CreateNewProjectCli creates a new project in boundary using the cli. The project will be created
// under the provided org id.
// Returns the id of the new project.
func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string) string {
func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string, opt ...ScopeOption) string {
opts := getScopeOpts(opt...)
var args []string
args = append(args,
"scopes", "create",
"-scope-id", orgId,
"-format", "json",
)
if opts.WithName != "" {
args = append(args, "-name", opts.WithName)
} else {
args = append(args, "-name", "e2e Project")
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "create",
"-name", "e2e Project",
"-scope-id", orgId,
"-format", "json",
),
e2e.WithArgs(args...),
)
require.NoError(t, output.Err, string(output.Stderr))
@@ -83,3 +93,29 @@ func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string) string
t.Logf("Created Project Id: %s", newProjectId)
return newProjectId
}
// getScopeOpts iterates the inbound ScopeOptions and returns a struct
func getScopeOpts(opt ...ScopeOption) scopeOptions {
opts := scopeOptions{
WithName: "",
}
for _, o := range opt {
o(&opts)
}
return opts
}
// ScopeOption represents how Options are passed as arguments
type ScopeOption func(*scopeOptions)
// scopeOptions is a struct representing available options for scopes
type scopeOptions struct {
WithName string
}
// WithName provides an option to search by a friendly name
func WithName(name string) ScopeOption {
return func(o *scopeOptions) {
o.WithName = name
}
}
+5 -1
View File
@@ -60,10 +60,14 @@ func CreateNewTargetCli(t testing.TB, ctx context.Context, projectId string, def
args = append(args,
"-scope-id", projectId,
"-default-port", defaultPort,
"-name", "e2e Target",
"-format", "json",
)
if opts.WithName != "" {
args = append(args, "-name", opts.WithName)
} else {
args = append(args, "-name", "e2e Target")
}
if opts.WithAddress != "" {
args = append(args, "-address", opts.WithAddress)
}