Expand coverage for runtime and sqlite paths
This commit is contained in:
@@ -202,6 +202,64 @@ func TestBatchImportHTTP(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestBatchImportWrapperFunctions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("handleCreateBatchImportRun requires action", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
req := httptestRequest(t, http.MethodPost, "/api/batch-import/runs", map[string]any{}, "")
|
||||
rec := &responseRecorder{header: map[string][]string{}}
|
||||
handleCreateBatchImportRun(rec, req, nil)
|
||||
assertStatusCode(t, rec, http.StatusInternalServerError)
|
||||
assertJSONContains(t, rec.Body().Bytes(), "error.code", "server_misconfigured")
|
||||
})
|
||||
|
||||
t.Run("handleCreateBatchImportRun classifies action error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
req := httptestRequest(t, http.MethodPost, "/api/batch-import/runs", map[string]any{
|
||||
"host_id": "host-1",
|
||||
"mode": "strict",
|
||||
"access_mode": "self_service",
|
||||
"probe_api_key": "probe-key",
|
||||
"entries": []map[string]any{
|
||||
{"base_url": "https://kimi.example.com/v1", "api_key": "sk-test"},
|
||||
},
|
||||
}, "")
|
||||
rec := &responseRecorder{header: map[string][]string{}}
|
||||
handleCreateBatchImportRun(rec, req, func(context.Context, CreateBatchImportRunRequest) (BatchImportRunCreateResponse, error) {
|
||||
return BatchImportRunCreateResponse{}, fmt.Errorf("host x not found")
|
||||
})
|
||||
assertStatusCode(t, rec, http.StatusNotFound)
|
||||
assertJSONContains(t, rec.Body().Bytes(), "error.code", "not_found")
|
||||
})
|
||||
|
||||
t.Run("handleListBatchImportRuns requires action", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
req := httptestRequest(t, http.MethodGet, "/api/batch-import/runs", nil, "")
|
||||
rec := &responseRecorder{header: map[string][]string{}}
|
||||
handleListBatchImportRuns(rec, req, nil)
|
||||
assertStatusCode(t, rec, http.StatusInternalServerError)
|
||||
assertJSONContains(t, rec.Body().Bytes(), "error.code", "server_misconfigured")
|
||||
})
|
||||
|
||||
t.Run("handleListBatchImportRuns returns empty array", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
req := httptestRequest(t, http.MethodGet, "/api/batch-import/runs?limit=5", nil, "")
|
||||
rec := &responseRecorder{header: map[string][]string{}}
|
||||
handleListBatchImportRuns(rec, req, func(_ context.Context, got ListBatchImportRunsRequest) (ListBatchImportRunsResponse, error) {
|
||||
if got.Limit != 5 {
|
||||
t.Fatalf("ListBatchImportRunsRequest.Limit = %d, want 5", got.Limit)
|
||||
}
|
||||
return ListBatchImportRunsResponse{}, nil
|
||||
})
|
||||
assertStatusCode(t, rec, http.StatusOK)
|
||||
runs, ok := decodeTopLevelArray(t, rec.Body().Bytes(), "runs")
|
||||
if !ok || len(runs) != 0 {
|
||||
t.Fatalf("runs = %#v, want empty array", runs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func newBatchImportActionStubServer(t *testing.T) http.Handler {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user