-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package base_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff/v4" | ||
"github.com/hashicorp/boundary/internal/clientcache" | ||
"github.com/hashicorp/boundary/testing/internal/e2e" | ||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary" | ||
"github.com/hashicorp/boundary/version" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
// TestCliSearch asserts that the CLI can search for targets | ||
func TestCliSearchAgain(t *testing.T) { | ||
e2e.MaybeSkipTest(t) | ||
// c, err := loadTestConfig() | ||
//require.NoError(t, err) | ||
|
||
ctx := context.Background() | ||
|
||
// If daemon is already running, stop it so that we can start it with a | ||
// shorter refresh interval | ||
t.Log("First Status") | ||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("cache", "status", "-format", "json")) | ||
t.Log(string(output.Stdout)) | ||
if output.Err == nil { | ||
t.Log("Stopping daemon...") | ||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("cache", "stop")) | ||
require.NoError(t, output.Err, string(output.Stderr)) | ||
} | ||
output = e2e.RunCommand(ctx, "boundary", | ||
e2e.WithArgs( | ||
"cache", "start", | ||
"-refresh-interval", "5s", | ||
"-background", | ||
), | ||
) | ||
require.NoError(t, output.Err, string(output.Stderr)) | ||
t.Cleanup(func() { | ||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("cache", "stop")) | ||
require.NoError(t, output.Err, string(output.Stderr)) | ||
}) | ||
|
||
// Wait for daemon to be up and running | ||
t.Log("Waiting for daemon to start...") | ||
var statusResult clientcache.StatusResult | ||
err := backoff.RetryNotify( | ||
func() error { | ||
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("cache", "status", "-format", "json")) | ||
if output.Err != nil { | ||
return errors.New(strings.TrimSpace(string(output.Stderr))) | ||
} | ||
t.Log(string(output.Stdout)) | ||
|
||
err := json.Unmarshal(output.Stdout, &statusResult) | ||
if err != nil { | ||
return backoff.Permanent(err) | ||
} | ||
|
||
return nil | ||
}, | ||
backoff.WithMaxRetries(backoff.NewConstantBackOff(1*time.Second), 5), | ||
func(err error, td time.Duration) { | ||
t.Logf("%s. Retrying...", err.Error()) | ||
}, | ||
) | ||
require.NoError(t, err) | ||
require.Equal(t, statusResult.StatusCode, 200) | ||
require.GreaterOrEqual(t, statusResult.Item.Uptime, 0*time.Second) | ||
|
||
// Confirm daemon version matches CLI version | ||
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("version", "-format", "json")) | ||
require.NoError(t, output.Err, string(output.Stderr)) | ||
var versionResult version.Info | ||
err = json.Unmarshal(output.Stdout, &versionResult) | ||
require.NoError(t, err) | ||
require.Contains(t, statusResult.Item.Version, versionResult.Revision) | ||
|
||
t.Log("Logging in again...") | ||
|
||
// Set up a new org and project | ||
boundary.AuthenticateAdminCli(t, ctx) | ||
|
||
t.Log("Getting status...") | ||
|
||
// Get current number of targets | ||
err = backoff.RetryNotify( | ||
func() error { | ||
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("cache", "status", "-format", "json")) | ||
t.Log(string(output.Stdout)) | ||
|
||
if output.Err != nil { | ||
return backoff.Permanent(errors.New(string(output.Stderr))) | ||
} | ||
|
||
statusResult = clientcache.StatusResult{} | ||
err = json.Unmarshal(output.Stdout, &statusResult) | ||
if err != nil { | ||
return errors.New("Failed to unmarshal status result") | ||
} | ||
|
||
if len(statusResult.Item.Users) == 0 { | ||
return errors.New("No users are appearing in the status") | ||
} | ||
idx := slices.IndexFunc( | ||
statusResult.Item.Users[0].Resources, | ||
func(r clientcache.ResourceStatus) bool { | ||
return r.Name == "target" | ||
}, | ||
) | ||
if idx == -1 { | ||
return errors.New("Targest not found in cache") | ||
} | ||
|
||
return nil | ||
}, | ||
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5), | ||
func(err error, td time.Duration) { | ||
t.Logf("%s. Retrying...", err.Error()) | ||
}, | ||
) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters