Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test list augmented response #2732

Merged
merged 1 commit into from
Jun 16, 2023
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
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