Skip to content

Commit

Permalink
debug3
Browse files Browse the repository at this point in the history
  • Loading branch information
moduli committed Nov 18, 2024
1 parent 54e31e8 commit 7d094a7
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
133 changes: 133 additions & 0 deletions testing/internal/e2e/tests/base/search_again_test.go
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)
}
1 change: 1 addition & 0 deletions testing/internal/e2e/tests/base/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestCliSearch(t *testing.T) {
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 errors.New(strings.TrimSpace(string(output.Stderr)))
}
Expand Down

0 comments on commit 7d094a7

Please sign in to comment.