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

     1  package itest
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  )
     8  
     9  type SingleService interface {
    10  	NamespacePair
    11  	ServiceName() string
    12  }
    13  
    14  type singleService struct {
    15  	NamespacePair
    16  	serviceName string
    17  }
    18  
    19  func WithSingleService(h NamespacePair, serviceName string, f func(SingleService)) {
    20  	h.HarnessT().Run(fmt.Sprintf("Test_Service_%s", serviceName), func(t *testing.T) {
    21  		ctx := WithT(h.HarnessContext(), t)
    22  		s := &singleService{NamespacePair: h, serviceName: serviceName}
    23  		s.PushHarness(ctx, s.setup, s.tearDown)
    24  		defer h.PopHarness()
    25  		f(s)
    26  	})
    27  }
    28  
    29  func (h *singleService) setup(ctx context.Context) bool {
    30  	h.ApplyEchoService(ctx, h.serviceName, 80)
    31  	return true
    32  }
    33  
    34  func (h *singleService) tearDown(ctx context.Context) {
    35  	h.DeleteSvcAndWorkload(ctx, "deploy", h.serviceName)
    36  }
    37  
    38  func (h *singleService) ServiceName() string {
    39  	return h.serviceName
    40  }