Skip to content

Commit

Permalink
feat: test list augmented response (#2732)
Browse files Browse the repository at this point in the history
add augmented list
  • Loading branch information
mathnogueira committed Jun 21, 2023
1 parent ee439a5 commit 4107756
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ func registerDataStoreResource(repository *datastoreresource.Repository, router
func registerTestResource(repository test.Repository, router *mux.Router, provisioner *provisioning.Provisioner, tracer trace.Tracer) {
operations := []resourcemanager.Operation{
resourcemanager.OperationList,
// TODO: replace it with the option `resourcemanager.CanBeAugmented()`
// once we have the `resourcemanager.OperationGet` operation.
resourcemanager.OperationListAugmented,
}

manager := resourcemanager.New[test.Test](
Expand Down
31 changes: 30 additions & 1 deletion server/test/test_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

type Repository interface {
List(_ context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error)
ListAugmented(_ context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error)
Count(context.Context, string) (int, error)
SortingFields() []string
Provision(context.Context, Test) error
Expand Down Expand Up @@ -81,6 +82,27 @@ const (
)

func (r *repository) List(ctx context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error) {
tests, err := r.list(ctx, take, skip, query, sortBy, sortDirection)
if err != nil {
return []Test{}, err
}

for i, test := range tests {
test.CreatedAt = nil
test.Summary = nil
test.Version = nil
tests[i] = test
}

return tests, err

}

func (r *repository) ListAugmented(ctx context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error) {
return r.list(ctx, take, skip, query, sortBy, sortDirection)
}

func (r *repository) list(ctx context.Context, take, skip int, query, sortBy, sortDirection string) ([]Test, error) {
sql := getTestSQL + testMaxVersionQuery
params := []any{take, skip}

Expand Down Expand Up @@ -155,7 +177,14 @@ func (r *repository) readRows(ctx context.Context, rows *sql.Rows) ([]Test, erro
}

func (r *repository) readRow(ctx context.Context, row scanner) (Test, error) {
test := Test{}
version := 0
createdAt := time.Now()

test := Test{
CreatedAt: &createdAt,
Version: &version,
Summary: &Summary{},
}

var (
jsonServiceUnderTest,
Expand Down
18 changes: 9 additions & 9 deletions server/test/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const (
type (
// this struct yaml/json encoding is handled at ./test_json.go for custom encodings
Test struct {
ID id.ID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
Name string `json:"name"`
Description string `json:"description"`
Version int `json:"version"`
Trigger trigger.Trigger `json:"trigger"`
Specs Specs `json:"specs"`
Outputs maps.Ordered[string, Output] `json:"outputs"`
Summary Summary `json:"summary"`
ID id.ID `json:"id,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Version *int `json:"version,omitempty"`
Trigger trigger.Trigger `json:"trigger,omitempty"`
Specs Specs `json:"specs,omitempty"`
Outputs maps.Ordered[string, Output] `json:"outputs,omitempty"`
Summary *Summary `json:"summary,omitempty"`
}

Specs []TestSpec
Expand Down

0 comments on commit 4107756

Please sign in to comment.