github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/cmd/bacalhau/base_test.go (about)

     1  package bacalhau
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"net/url"
     7  	"time"
     8  
     9  	"github.com/filecoin-project/bacalhau/pkg/logger"
    10  	"github.com/filecoin-project/bacalhau/pkg/model"
    11  	"github.com/filecoin-project/bacalhau/pkg/node"
    12  	"github.com/filecoin-project/bacalhau/pkg/requester/publicapi"
    13  	testutils "github.com/filecoin-project/bacalhau/pkg/test/utils"
    14  	"github.com/stretchr/testify/require"
    15  	"github.com/stretchr/testify/suite"
    16  )
    17  
    18  type BaseSuite struct {
    19  	suite.Suite
    20  	node   *node.Node
    21  	client *publicapi.RequesterAPIClient
    22  	host   string
    23  	port   string
    24  }
    25  
    26  // before each test
    27  func (s *BaseSuite) SetupTest() {
    28  	logger.ConfigureTestLogging(s.T())
    29  	Fatal = FakeFatalErrorHandler
    30  
    31  	ctx := context.Background()
    32  	stack, _ := testutils.SetupTest(ctx, s.T(), 1, 0, false,
    33  		node.NewComputeConfigWith(node.ComputeConfigParams{
    34  			JobSelectionPolicy: model.JobSelectionPolicy{
    35  				Locality: model.Anywhere,
    36  			},
    37  		}),
    38  		node.NewRequesterConfigWith(node.RequesterConfigParams{
    39  			HousekeepingBackgroundTaskInterval: 1 * time.Second,
    40  		}),
    41  	)
    42  	s.node = stack.Nodes[0]
    43  	s.client = publicapi.NewRequesterAPIClient(s.node.APIServer.GetURI())
    44  	parsedBasedURI, err := url.Parse(s.client.BaseURI)
    45  	require.NoError(s.T(), err)
    46  	host, port, _ := net.SplitHostPort(parsedBasedURI.Host)
    47  	s.host = host
    48  	s.port = port
    49  }
    50  
    51  // After each test
    52  func (s *BaseSuite) TearDownTest() {
    53  	Fatal = FatalErrorHandler
    54  	if s.node != nil {
    55  		s.node.CleanupManager.Cleanup(context.Background())
    56  	}
    57  }