Skip to content

Commit

Permalink
wip: test compile, don't pass
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Apr 29, 2024
1 parent c5afdbe commit a430cfe
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 109 deletions.
7 changes: 1 addition & 6 deletions cmd/cli/serve/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type ServeSuite struct {
repoPath string
protocol string
config config.Context
signer system.Signer
}

func TestServeSuite(t *testing.T) {
Expand All @@ -68,10 +67,6 @@ func (s *ServeSuite) SetupTest() {
s.protocol = "http"
s.config = c

sk, err := config.GetClientPrivateKey(c)
s.Require().NoError(err)
s.signer = system.NewMessageSigner(sk)

var cancel context.CancelFunc
s.ctx, cancel = context.WithTimeout(context.Background(), maxTestTime)
s.T().Cleanup(func() {
Expand Down Expand Up @@ -218,7 +213,7 @@ func (s *ServeSuite) TestCanSubmitJob() {
docker.MustHaveDocker(s.T())
port, err := s.serve("--node-type", "requester,compute")
s.Require().NoError(err)
client, err := client.NewAPIClient(client.NoTLS, s.config, s.signer, "localhost", port)
client, err := client.NewAPIClient(client.NoTLS, s.config, "localhost", port)
s.Require().NoError(err)

clientV2 := clientv2.New(fmt.Sprintf("http://127.0.0.1:%d", port))
Expand Down
5 changes: 4 additions & 1 deletion cmd/cli/serve/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

"github.com/bacalhau-project/bacalhau/pkg/config"
"github.com/bacalhau-project/bacalhau/pkg/docker"
legacy_job "github.com/bacalhau-project/bacalhau/pkg/legacyjob"
"github.com/bacalhau-project/bacalhau/pkg/model"
Expand Down Expand Up @@ -53,7 +54,9 @@ func (s *ServeSuite) TestNoTimeoutSetOrApplied() {

port, err := s.serve(args...)
s.Require().NoError(err)
client := client.NewAPIClient(client.NoTLS, "localhost", port)
c := config.New()
client, err := client.NewAPIClient(client.NoTLS, c, "localhost", port)
s.Require().NoError(err)
clientV2 := clientv2.New(fmt.Sprintf("http://127.0.0.1:%d", port))
s.Require().NoError(apitest.WaitForAlive(s.ctx, clientV2))

Expand Down
6 changes: 1 addition & 5 deletions cmd/testing/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"
clientv2 "github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/setup"
"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/bacalhau-project/bacalhau/pkg/test/teststack"
)

Expand All @@ -45,9 +44,6 @@ func (s *BaseSuite) SetupTest() {

cfg := config.New(config.WithDefaultConfig(configenv.Local))
fsr := setup.SetupBacalhauRepoForTesting(s.T(), cfg)
sk, err := config.GetClientPrivateKey(cfg)
s.Require().NoError(err)
signer := system.NewMessageSigner(sk)

computeConfig, err := node.NewComputeConfigWith(cfg, node.ComputeConfigParams{
JobSelectionPolicy: node.JobSelectionPolicy{
Expand All @@ -74,7 +70,7 @@ func (s *BaseSuite) SetupTest() {
s.Node = stack.Nodes[0]
s.Host = s.Node.APIServer.Address
s.Port = s.Node.APIServer.Port
s.Client, err = client.NewAPIClient(client.NoTLS, cfg, signer, s.Host, s.Port)
s.Client, err = client.NewAPIClient(client.NoTLS, cfg, s.Host, s.Port)
s.Require().NoError(err)
s.ClientV2 = clientv2.New(fmt.Sprintf("http://%s:%d", s.Host, s.Port))
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/testing/basetls.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"
clientv2 "github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/setup"
"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/bacalhau-project/bacalhau/pkg/test/teststack"
"github.com/bacalhau-project/bacalhau/pkg/test/utils/certificates"
)
Expand All @@ -32,9 +31,6 @@ func (s *BaseTLSSuite) SetupTest() {

cfg := config.New(config.WithDefaultConfig(configenv.Local))
fsr := setup.SetupBacalhauRepoForTesting(s.T(), cfg)
sk, err := config.GetClientPrivateKey(cfg)
s.Require().NoError(err)
signer := system.NewMessageSigner(sk)

computeConfig, err := node.NewComputeConfigWith(cfg, node.ComputeConfigParams{
JobSelectionPolicy: node.JobSelectionPolicy{
Expand Down Expand Up @@ -74,7 +70,7 @@ func (s *BaseTLSSuite) SetupTest() {
s.Node = stack.Nodes[0]
s.Host = s.Node.APIServer.Address // NOTE: 0.0.0.0 will not work because we're testing TLS validation
s.Port = s.Node.APIServer.Port
s.Client, err = client.NewAPIClient(client.LegacyTLSSupport{UseTLS: true, Insecure: false}, cfg, signer, s.Host, s.Port)
s.Client, err = client.NewAPIClient(client.LegacyTLSSupport{UseTLS: true, Insecure: false}, cfg, s.Host, s.Port)
s.Require().NoError(err)
s.ClientV2 = clientv2.New(fmt.Sprintf("http://%s:%d", s.Host, s.Port), clientv2.WithTLS(true), clientv2.WithInsecureTLS(true))
}
Expand Down
9 changes: 1 addition & 8 deletions cmd/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"
clientv2 "github.com/bacalhau-project/bacalhau/pkg/publicapi/client/v2"
"github.com/bacalhau-project/bacalhau/pkg/setup"
"github.com/bacalhau-project/bacalhau/pkg/system"
"github.com/bacalhau-project/bacalhau/pkg/version"
)

Expand All @@ -33,12 +32,6 @@ func GetAPIClient(c config.Context) (*client.APIClient, error) {
return nil, err
}

sk, err := config.GetClientPrivateKey(c)
if err != nil {
return nil, err
}
signer := system.NewMessageSigner(sk)

var tlsCfg types.ClientTLSConfig
if err := c.ForKey(types.NodeClientAPITLS, &tlsCfg); err != nil {
return nil, err
Expand All @@ -52,7 +45,7 @@ func GetAPIClient(c config.Context) (*client.APIClient, error) {
return nil, err
}
legacyTLS := client.LegacyTLSSupport(tlsCfg)
apiClient, err := client.NewAPIClient(legacyTLS, c, signer, apiHost, apiPort)
apiClient, err := client.NewAPIClient(legacyTLS, c, apiHost, apiPort)
if err != nil {
return nil, err
}
Expand Down
9 changes: 1 addition & 8 deletions cmd/util/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/config"
"github.com/bacalhau-project/bacalhau/pkg/models"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"
"github.com/bacalhau-project/bacalhau/pkg/system"

"github.com/bacalhau-project/bacalhau/pkg/version"
)

Expand All @@ -28,12 +26,7 @@ func GetAllVersions(ctx context.Context, c config.Context) (Versions, error) {
versions := Versions{ClientVersion: version.Get()}

legacyTLS := client.LegacyTLSSupport(config.ClientTLSConfig(c))
sk, err := config.GetClientPrivateKey(c)
if err != nil {
return versions, err
}
signer := system.NewMessageSigner(sk)
client, err := client.NewAPIClient(legacyTLS, c, signer, config.ClientAPIHost(c), config.ClientAPIPort(c))
client, err := client.NewAPIClient(legacyTLS, c, config.ClientAPIHost(c), config.ClientAPIPort(c))
if err != nil {
return versions, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/publicapi/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type LegacyTLSSupport struct {
func NewAPIClient(
tlsinfo LegacyTLSSupport,
c config.Context,
s system.Signer,
host string,
port uint16,
path ...string,
Expand All @@ -61,6 +60,11 @@ func NewAPIClient(
scheme = "https"
}

sk, err := config.GetClientPrivateKey(c)
if err != nil {
return nil, err
}

baseURI := system.MustParseURL(fmt.Sprintf("%s://%s:%d", scheme, host, port)).JoinPath(path...)

tr := getTLSTransport(tlsinfo)
Expand All @@ -73,7 +77,7 @@ func NewAPIClient(
return &APIClient{
BaseURI: baseURI,
DefaultHeaders: map[string]string{},
Signer: s,
Signer: system.NewMessageSigner(sk),
ClientID: clientID,
Config: c,

Expand Down
11 changes: 8 additions & 3 deletions pkg/publicapi/test/requester_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"context"
"testing"

"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/bacalhau-project/bacalhau/pkg/config"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"

"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/model"
"github.com/bacalhau-project/bacalhau/pkg/node"
Expand All @@ -35,9 +37,12 @@ func TestRequesterSuite(t *testing.T) {
// Before each test
func (s *RequesterSuite) SetupTest() {
logger.ConfigureTestLogging(s.T())
n, _ := setupNodeForTest(s.T())
c := config.New()
n, _ := setupNodeForTest(s.T(), c)
s.node = n
s.client = client.NewAPIClient(client.NoTLS, n.APIServer.Address, n.APIServer.Port)
var err error
s.client, err = client.NewAPIClient(client.NoTLS, c, n.APIServer.Address, n.APIServer.Port)
s.Require().NoError(err)
}

// After each test
Expand Down
6 changes: 4 additions & 2 deletions pkg/publicapi/test/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stretchr/testify/suite"

"github.com/bacalhau-project/bacalhau/pkg/config"
"github.com/bacalhau-project/bacalhau/pkg/devstack"
"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/node"
Expand All @@ -29,11 +30,12 @@ type ServerSuite struct {

func (s *ServerSuite) SetupSuite() {
logger.ConfigureTestLogging(s.T())
setup.SetupBacalhauRepoForTesting(s.T())
c := config.New()
fsr := setup.SetupBacalhauRepoForTesting(s.T(), c)

ctx := context.Background()

stack := teststack.Setup(ctx, s.T(),
stack := teststack.Setup(ctx, s.T(), fsr,
devstack.WithNumberOfRequesterOnlyNodes(1),
devstack.WithNumberOfComputeOnlyNodes(1),
devstack.WithDependencyInjector(devstack.NewNoopNodeDependencyInjector()),
Expand Down
19 changes: 10 additions & 9 deletions pkg/publicapi/test/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"testing"
"time"

"github.com/bacalhau-project/bacalhau/pkg/compute/store/boltdb"
boltjobstore "github.com/bacalhau-project/bacalhau/pkg/jobstore/boltdb"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/require"

"github.com/bacalhau-project/bacalhau/pkg/compute/store/boltdb"
boltjobstore "github.com/bacalhau-project/bacalhau/pkg/jobstore/boltdb"

"github.com/bacalhau-project/bacalhau/pkg/lib/network"
"github.com/bacalhau-project/bacalhau/pkg/models"

Expand All @@ -26,13 +27,13 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/system"
)

func setupNodeForTest(t *testing.T) (*node.Node, client.API) {
func setupNodeForTest(t *testing.T, c config.Context) (*node.Node, client.API) {
// blank config should result in using defaults in node.Node constructor
return setupNodeForTestWithConfig(t, publicapi.Config{})
return setupNodeForTestWithConfig(t, c, publicapi.Config{})
}

func setupNodeForTestWithConfig(t *testing.T, apiCfg publicapi.Config) (*node.Node, client.API) {
repo := setup.SetupBacalhauRepoForTesting(t)
func setupNodeForTestWithConfig(t *testing.T, c config.Context, apiCfg publicapi.Config) (*node.Node, client.API) {
repo := setup.SetupBacalhauRepoForTesting(t, c)
ctx := context.Background()

repoPath, err := repo.Path()
Expand All @@ -44,7 +45,7 @@ func setupNodeForTestWithConfig(t *testing.T, apiCfg publicapi.Config) (*node.No
libp2pPort, err := network.GetFreePort()
require.NoError(t, err)

privKey, err := config.GetLibp2pPrivKey()
privKey, err := config.GetLibp2pPrivKey(c)
require.NoError(t, err)

peerID, err := peer.IDFromPrivateKey(privKey)
Expand Down Expand Up @@ -79,7 +80,7 @@ func setupNodeForTestWithConfig(t *testing.T, apiCfg publicapi.Config) (*node.No
executionStore, err := boltdb.NewStore(ctx, filepath.Join(repoPath, "executions.db"))
require.NoError(t, err)

computeConfig, err := node.NewComputeConfigWith(node.ComputeConfigParams{
computeConfig, err := node.NewComputeConfigWith(c, node.ComputeConfigParams{
ExecutionStore: executionStore,
})
require.NoError(t, err)
Expand All @@ -104,7 +105,7 @@ func setupNodeForTestWithConfig(t *testing.T, apiCfg publicapi.Config) (*node.No
NetworkConfig: networkConfig,
}

n, err := node.NewNode(ctx, nodeConfig)
n, err := node.NewNode(ctx, c, nodeConfig)
require.NoError(t, err)

err = n.Start(ctx)
Expand Down
11 changes: 8 additions & 3 deletions pkg/publicapi/test/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"testing"
"time"

"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/bacalhau-project/bacalhau/pkg/config"
"github.com/bacalhau-project/bacalhau/pkg/publicapi/client"

"github.com/bacalhau-project/bacalhau/pkg/logger"
"github.com/bacalhau-project/bacalhau/pkg/model"
"github.com/bacalhau-project/bacalhau/pkg/node"
Expand All @@ -39,9 +41,12 @@ func TestWebsocketSuite(t *testing.T) {
// Before each test
func (s *WebsocketSuite) SetupTest() {
logger.ConfigureTestLogging(s.T())
n, _ := setupNodeForTest(s.T())
c := config.New()
n, _ := setupNodeForTest(s.T(), c)
s.node = n
s.client = client.NewAPIClient(client.NoTLS, n.APIServer.Address, n.APIServer.Port)
var err error
s.client, err = client.NewAPIClient(client.NoTLS, c, n.APIServer.Address, n.APIServer.Port)
s.Require().NoError(err)
}

// After each test
Expand Down
13 changes: 9 additions & 4 deletions pkg/repo/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/bacalhau-project/bacalhau/pkg/config"
)

func TestNewFS(t *testing.T) {
c := config.New()
repo, err := NewFS(FsRepoParams{Path: t.TempDir() + t.Name()})
require.NoError(t, err)
require.NotNil(t, repo)
Expand All @@ -19,11 +22,13 @@ func TestNewFS(t *testing.T) {
require.False(t, exists)

// cannot open uninitialized repo
err = repo.Open()
err = repo.Open(c)
require.Error(t, err)

// can init a repo
err = repo.Init()
// TODO(forrest) [refactor]: assert the repo initializes the expected values
// in the config, such as paths and keys.
err = repo.Init(c)
require.NoError(t, err)

// it better exist now
Expand All @@ -32,10 +37,10 @@ func TestNewFS(t *testing.T) {
require.True(t, exists)

// should be able to open
err = repo.Open()
err = repo.Open(c)
require.NoError(t, err)

// cannot init an already init'ed repo.
err = repo.Init()
err = repo.Init(c)
require.Error(t, err)
}
5 changes: 2 additions & 3 deletions pkg/repo/migrations/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"os"
"path/filepath"

"github.com/bacalhau-project/bacalhau/pkg/repo"
"github.com/spf13/viper"
"github.com/stretchr/testify/suite"

"github.com/bacalhau-project/bacalhau/pkg/repo"
)

const (
Expand All @@ -23,7 +23,6 @@ type BaseMigrationTestSuite struct {

// SetupTest runs before each test in the suite.
func (suite *BaseMigrationTestSuite) SetupTest() {
viper.Reset()
suite.TempDir = suite.T().TempDir() // Create a temporary directory for testing
}

Expand Down

0 comments on commit a430cfe

Please sign in to comment.