Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ const (
defaultAuctionStall = 1 * time.Second
)

type NexClient interface {
GetNexusPTags() (map[string]string, error)
GetNodeInfo(nodeId string) (*models.NodeInfoResponse, error)
SetLameduck(nodeId string, delay time.Duration, tag map[string]string) (*models.LameduckResponse, error)
ListNodes(filter map[string]string) ([]*models.NodePingResponse, error)
Auction(typ string, tags map[string]string) ([]*models.AuctionResponse, error)
StartWorkload(deployId, name, desc, runRequest, typ string, lifecycle models.WorkloadLifecycle, pTags models.NodeTags) (*models.StartWorkloadResponse, error)
StopWorkload(workloadId string) (*models.StopWorkloadResponse, error)
ListWorkloads(filter []string) ([]*models.AgentListWorkloadsResponse, error)
CloneWorkload(id string, tags map[string]string) (*models.StartWorkloadResponse, error)
}

type nexClient struct {
ctx context.Context
cancel context.CancelFunc
Expand All @@ -37,7 +49,7 @@ type nexClient struct {
auctionRequestManyStall time.Duration
}

func NewClient(ctx context.Context, nc *nats.Conn, namespace string, opts ...ClientOption) (*nexClient, error) {
func NewClient(ctx context.Context, nc *nats.Conn, namespace string, opts ...ClientOption) (NexClient, error) {
var cancel context.CancelFunc
if ctx == nil {
ctx = context.Background()
Expand Down
12 changes: 7 additions & 5 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func TestNewNexClient(t *testing.T) {
be.NilErr(t, err)
be.Nonzero(t, client)

be.DeepEqual(t, nc, client.nc)
be.Equal(t, "test", client.namespace)
c := client.(*nexClient)
be.DeepEqual(t, nc, c.nc)
be.Equal(t, "test", c.namespace)
}

func TestNewNexClientWithOptions(t *testing.T) {
Expand Down Expand Up @@ -57,9 +58,10 @@ func TestNewNexClientWithOptions(t *testing.T) {
be.NilErr(t, err)
be.Nonzero(t, client)

be.Equal(t, customTimeout, client.defaultTimeout)
be.Equal(t, customStartTimeout, client.startWorkloadTimeout)
be.Equal(t, customStall, client.requestManyStall)
c := client.(*nexClient)
be.Equal(t, customTimeout, c.defaultTimeout)
be.Equal(t, customStartTimeout, c.startWorkloadTimeout)
be.Equal(t, customStall, c.requestManyStall)
}

func TestNexClient_User(t *testing.T) {
Expand Down
12 changes: 8 additions & 4 deletions client/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func TestNexClientErrorHelpers_GenerateUniqueIDs(t *testing.T) {
be.NilErr(t, err)
defer nc.Close()

client, err := NewClient(context.Background(), nc, "test")
c, err := NewClient(context.Background(), nc, "test")
be.NilErr(t, err)
client := c.(*nexClient)

e1 := client.nexInternalError(errors.New("a"), "a")
e2 := client.nexInternalError(errors.New("b"), "b")
Expand All @@ -51,8 +52,9 @@ func TestNexClientErrorHelpers_NonEmptyIDs(t *testing.T) {
be.NilErr(t, err)
defer nc.Close()

client, err := NewClient(context.Background(), nc, "test")
c, err := NewClient(context.Background(), nc, "test")
be.NilErr(t, err)
client := c.(*nexClient)

be.Nonzero(t, client.nexInternalError(errors.New("x"), "x").ID())
be.Nonzero(t, client.nexBadRequestError(errors.New("x"), "x").ID())
Expand All @@ -69,8 +71,9 @@ func TestNexClientErrorHelpers_StatusCodes(t *testing.T) {
be.NilErr(t, err)
defer nc.Close()

client, err := NewClient(context.Background(), nc, "test")
c, err := NewClient(context.Background(), nc, "test")
be.NilErr(t, err)
client := c.(*nexClient)

be.Equal(t, http.StatusInternalServerError, client.nexInternalError(errors.New("x"), "x").Status())
be.Equal(t, http.StatusBadRequest, client.nexBadRequestError(errors.New("x"), "x").Status())
Expand All @@ -87,8 +90,9 @@ func TestNexClientErrorHelpers_PreservesMessages(t *testing.T) {
be.NilErr(t, err)
defer nc.Close()

client, err := NewClient(context.Background(), nc, "test")
c, err := NewClient(context.Background(), nc, "test")
be.NilErr(t, err)
client := c.(*nexClient)

ne := client.nexInternalError(errors.New("raw detail"), "friendly message")
be.Equal(t, "raw detail", ne.Error())
Expand Down
Loading