Füge Modelle für Flows, FlowRuns, TaskRuns, WorkPools, WorkQueues, Deployments, Variablen, FlowRunStates, Logs, und Blocks samt zugehöriger Unmarshal-Logik und Zeitfeld-Unterstützung hinzu; ergänze Tests für die FlowRunStates-Service-Methoden.
This commit is contained in:
63
pkg/client/task_run_states_test.go
Normal file
63
pkg/client/task_run_states_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.schultes.dev/schultesdev/prefect-go/pkg/models"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestTaskRunStatesService_List(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/task_run_states/" {
|
||||
t.Errorf("path = %v, want /api/task_run_states/", r.URL.Path)
|
||||
}
|
||||
if r.Method != http.MethodGet {
|
||||
t.Errorf("method = %v, want GET", r.Method)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode([]models.State{
|
||||
{ID: uuid.New(), Type: models.StateTypeFailed},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(WithBaseURL(server.URL + "/api"))
|
||||
ctx := context.Background()
|
||||
|
||||
states, err := client.TaskRunStates.List(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(states) != 1 {
|
||||
t.Errorf("count = %v, want 1", len(states))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskRunStatesService_Get(t *testing.T) {
|
||||
id := uuid.New()
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
t.Errorf("method = %v, want GET", r.Method)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(models.State{ID: id, Type: models.StateTypePending})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, _ := NewClient(WithBaseURL(server.URL + "/api"))
|
||||
ctx := context.Background()
|
||||
|
||||
state, err := client.TaskRunStates.Get(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if state.ID != id {
|
||||
t.Errorf("ID = %v, want %v", state.ID, id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user