github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/integration_test/itest/connected.go (about)

     1  package itest
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  type connected struct {
    12  	NamespacePair
    13  }
    14  
    15  func WithConnected(np NamespacePair, f func(ctx context.Context, ch NamespacePair)) {
    16  	np.HarnessT().Run("Test_Connected", func(t *testing.T) {
    17  		ctx := WithT(np.HarnessContext(), t)
    18  		require.NoError(t, np.GeneralError())
    19  		ch := &connected{NamespacePair: np}
    20  		ch.PushHarness(ctx, ch.setup, ch.tearDown)
    21  		defer ch.PopHarness()
    22  		f(ctx, ch)
    23  	})
    24  }
    25  
    26  func (ch *connected) setup(ctx context.Context) bool {
    27  	t := getT(ctx)
    28  	// Connect using telepresence-test-developer user
    29  	stdout, _, err := Telepresence(ctx, "connect", "--namespace", ch.AppNamespace(), "--manager-namespace", ch.ManagerNamespace())
    30  	assert.NoError(t, err)
    31  	assert.Contains(t, stdout, "Connected to context")
    32  	if t.Failed() {
    33  		return false
    34  	}
    35  	_, _, err = Telepresence(ctx, "loglevel", "-d30m", "debug")
    36  	assert.NoError(t, err)
    37  	return !t.Failed()
    38  }
    39  
    40  func (ch *connected) tearDown(ctx context.Context) {
    41  	TelepresenceQuitOk(ctx)
    42  }