Skip to content
Draft
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
45 changes: 28 additions & 17 deletions cli/commands_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ func setupTestServer(t *testing.T, handlers map[string]http.HandlerFunc) *httpte
}))
}

func paginatedResponse(data interface{}) map[string]interface{} {
return map[string]interface{}{
"data": data,
"meta": map[string]interface{}{
"hasMore": false,
"nextCursor": "",
"total": 0,
},
}
}

// setupTestClient creates and sets a mock blaxel client
func setupTestClient(t *testing.T, serverURL string) {
t.Setenv("BL_API_KEY", "test-api-key")
Expand Down Expand Up @@ -81,7 +92,7 @@ func TestListAgentsIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(agents)
_ = json.NewEncoder(w).Encode(paginatedResponse(agents))
},
}

Expand All @@ -91,7 +102,7 @@ func TestListAgentsIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
agents, err := client.Agents.List(ctx)
agents, err := core.ListAllAgents(ctx, client)
require.NoError(t, err)
assert.Len(t, *agents, 2)
}
Expand All @@ -110,7 +121,7 @@ func TestListFunctionsIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(functions)
_ = json.NewEncoder(w).Encode(paginatedResponse(functions))
},
}

Expand All @@ -120,7 +131,7 @@ func TestListFunctionsIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
functions, err := client.Functions.List(ctx)
functions, err := core.ListAllFunctions(ctx, client)
require.NoError(t, err)
assert.Len(t, *functions, 1)
}
Expand Down Expand Up @@ -150,7 +161,7 @@ func TestListModelsIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(models)
_ = json.NewEncoder(w).Encode(paginatedResponse(models))
},
}

Expand All @@ -160,7 +171,7 @@ func TestListModelsIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
models, err := client.Models.List(ctx)
models, err := core.ListAllModels(ctx, client)
require.NoError(t, err)
assert.Len(t, *models, 2)
}
Expand All @@ -179,7 +190,7 @@ func TestListJobsIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(jobs)
_ = json.NewEncoder(w).Encode(paginatedResponse(jobs))
},
}

Expand All @@ -189,7 +200,7 @@ func TestListJobsIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
jobs, err := client.Jobs.List(ctx)
jobs, err := core.ListAllJobs(ctx, client)
require.NoError(t, err)
assert.Len(t, *jobs, 1)
}
Expand All @@ -208,7 +219,7 @@ func TestListSandboxesIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(sandboxes)
_ = json.NewEncoder(w).Encode(paginatedResponse(sandboxes))
},
}

Expand All @@ -218,7 +229,7 @@ func TestListSandboxesIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
sandboxes, err := client.Sandboxes.List(ctx)
sandboxes, err := core.ListAllSandboxes(ctx, client)
require.NoError(t, err)
assert.Len(t, *sandboxes, 1)
}
Expand All @@ -239,7 +250,7 @@ func TestListVolumesIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(volumes)
_ = json.NewEncoder(w).Encode(paginatedResponse(volumes))
},
}

Expand All @@ -249,7 +260,7 @@ func TestListVolumesIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
volumes, err := client.Volumes.List(ctx)
volumes, err := core.ListAllVolumes(ctx, client)
require.NoError(t, err)
assert.Len(t, *volumes, 1)
}
Expand All @@ -267,7 +278,7 @@ func TestListPoliciesIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(policies)
_ = json.NewEncoder(w).Encode(paginatedResponse(policies))
},
}

Expand All @@ -277,7 +288,7 @@ func TestListPoliciesIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
policies, err := client.Policies.List(ctx)
policies, err := core.ListAllPolicies(ctx, client)
require.NoError(t, err)
assert.Len(t, *policies, 1)
}
Expand Down Expand Up @@ -469,7 +480,7 @@ func TestJobExecutionsListIntegration(t *testing.T) {
},
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(executions)
_ = json.NewEncoder(w).Encode(paginatedResponse(executions))
},
}

Expand All @@ -479,7 +490,7 @@ func TestJobExecutionsListIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
executions, err := client.Jobs.Executions.List(ctx, "my-job", blaxel.JobExecutionListParams{})
executions, err := core.ListAllJobExecutions(ctx, client, "my-job")
require.NoError(t, err)
assert.Len(t, *executions, 2)
}
Expand Down Expand Up @@ -571,7 +582,7 @@ func TestAPIErrorHandlingIntegration(t *testing.T) {

ctx := context.Background()
client := core.GetClient()
_, err := client.Agents.List(ctx)
_, err := core.ListAllAgents(ctx, client)
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.expected)
})
Expand Down
18 changes: 9 additions & 9 deletions cli/completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

blaxel "github.com/blaxel-ai/sdk-go"
"github.com/blaxel-ai/sdk-go/option"
"github.com/blaxel-ai/toolkit/cli/core"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -113,7 +114,6 @@ var sandboxPreviewKeywords = []string{"previews", "preview", "pv"}
// previewTokenKeywords are the keywords that indicate token nested resources for previews
var previewTokenKeywords = []string{"tokens", "token", "pvt"}


// CompleteSandboxNames returns a list of sandbox names for shell completion
func CompleteSandboxNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx, cancel := completionContext()
Expand All @@ -123,7 +123,7 @@ func CompleteSandboxNames(cmd *cobra.Command, args []string, toComplete string)
return nil, cobra.ShellCompDirectiveNoFileComp
}

sandboxes, err := client.Sandboxes.List(ctx)
sandboxes, err := core.ListAllSandboxes(ctx, client)
if err != nil || sandboxes == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func CompleteJobNames(cmd *cobra.Command, args []string, toComplete string) ([]s
return nil, cobra.ShellCompDirectiveNoFileComp
}

jobs, err := client.Jobs.List(ctx)
jobs, err := core.ListAllJobs(ctx, client)
if err != nil || jobs == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -403,7 +403,7 @@ func CompleteJobExecutionIDs(jobName string, toComplete string) ([]string, cobra
return nil, cobra.ShellCompDirectiveNoFileComp
}

executions, err := client.Jobs.Executions.List(ctx, jobName, blaxel.JobExecutionListParams{})
executions, err := core.ListAllJobExecutions(ctx, client, jobName)
if err != nil || executions == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -553,7 +553,7 @@ func CompleteAgentNames(cmd *cobra.Command, args []string, toComplete string) ([
return nil, cobra.ShellCompDirectiveNoFileComp
}

agents, err := client.Agents.List(ctx)
agents, err := core.ListAllAgents(ctx, client)
if err != nil || agents == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -618,7 +618,7 @@ func CompleteFunctionNames(cmd *cobra.Command, args []string, toComplete string)
return nil, cobra.ShellCompDirectiveNoFileComp
}

functions, err := client.Functions.List(ctx)
functions, err := core.ListAllFunctions(ctx, client)
if err != nil || functions == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -683,7 +683,7 @@ func CompleteModelNames(cmd *cobra.Command, args []string, toComplete string) ([
return nil, cobra.ShellCompDirectiveNoFileComp
}

models, err := client.Models.List(ctx)
models, err := core.ListAllModels(ctx, client)
if err != nil || models == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -748,7 +748,7 @@ func CompleteVolumeNames(cmd *cobra.Command, args []string, toComplete string) (
return nil, cobra.ShellCompDirectiveNoFileComp
}

volumes, err := client.Volumes.List(ctx)
volumes, err := core.ListAllVolumes(ctx, client)
if err != nil || volumes == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -810,7 +810,7 @@ func CompletePolicyNames(cmd *cobra.Command, args []string, toComplete string) (
return nil, cobra.ShellCompDirectiveNoFileComp
}

policies, err := client.Policies.List(ctx)
policies, err := core.ListAllPolicies(ctx, client)
if err != nil || policies == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Expand Down
2 changes: 1 addition & 1 deletion cli/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Examples:
core.PrintError("Connect", err)

// List available sandboxes
sandboxes, listErr := client.Sandboxes.List(ctx)
sandboxes, listErr := core.ListAllSandboxes(ctx, client)
if listErr == nil && sandboxes != nil && len(*sandboxes) > 0 {
names := make([]string, 0, len(*sandboxes))
for _, sb := range *sandboxes {
Expand Down
Loading
Loading