Skip to content

Commit

Permalink
feat: add title to test run events (#2271)
Browse files Browse the repository at this point in the history
* add title to test run events

* add title to openapi spec
  • Loading branch information
mathnogueira committed Mar 29, 2023
1 parent 14ad865 commit a7ad995
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 11 deletions.
2 changes: 2 additions & 0 deletions api/testEvents.yaml
Expand Up @@ -12,6 +12,8 @@ components:
- trigger
- trace
- test
title:
type: string
description:
type: string
createdAt:
Expand Down
36 changes: 36 additions & 0 deletions cli/openapi/model_test_run_event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions server/migrations/24_add_test_run_events_title.down.sql
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE "test_run_events" DROP COLUMN title;

COMMIT;
5 changes: 5 additions & 0 deletions server/migrations/24_add_test_run_events_title.up.sql
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE "test_run_events" ADD COLUMN "title" varchar not null;

COMMIT;
1 change: 1 addition & 0 deletions server/model/test_run_event.go
Expand Up @@ -44,6 +44,7 @@ type TestRunEvent struct {
ID int64
Type string
Stage TestRunEventStage
Title string
Description string
CreatedAt time.Time
TestID id.ID
Expand Down
2 changes: 2 additions & 0 deletions server/openapi/model_test_run_event.go
Expand Up @@ -18,6 +18,8 @@ type TestRunEvent struct {

Stage string `json:"stage,omitempty"`

Title string `json:"title,omitempty"`

Description string `json:"description,omitempty"`

CreatedAt time.Time `json:"createdAt,omitempty"`
Expand Down
15 changes: 10 additions & 5 deletions server/testdb/test_run_event.go
Expand Up @@ -18,6 +18,7 @@ const insertTestRunEventQuery = `
"run_id",
"type",
"stage",
"title",
"description",
"created_at",
"data_store_connection",
Expand All @@ -28,11 +29,12 @@ const insertTestRunEventQuery = `
$2, -- run_id
$3, -- type
$4, -- stage
$5, -- description
$6, -- created_at
$7, -- data_store_connection
$8, -- polling
$9 -- outputs
$5, -- title
$6, -- description
$7, -- created_at
$8, -- data_store_connection
$9, -- polling
$10 -- outputs
)
RETURNING "id"
`
Expand Down Expand Up @@ -64,6 +66,7 @@ func (td *postgresDB) CreateTestRunEvent(ctx context.Context, event model.TestRu
event.RunID,
event.Type,
event.Stage,
event.Title,
event.Description,
event.CreatedAt,
dataStoreConnectionJSON,
Expand All @@ -85,6 +88,7 @@ const getTestRunEventsQuery = `
"run_id",
"type",
"stage",
"title",
"description",
"created_at",
"data_store_connection",
Expand Down Expand Up @@ -123,6 +127,7 @@ func readTestRunEventFromRows(rows *sql.Rows) (model.TestRunEvent, error) {
&event.RunID,
&event.Type,
&event.Stage,
&event.Title,
&event.Description,
&event.CreatedAt,
&dataStoreConnectionBytes,
Expand Down
14 changes: 8 additions & 6 deletions server/testdb/test_run_event_test.go
Expand Up @@ -19,25 +19,25 @@ func TestRunEvents(t *testing.T) {
run2 := createRun(t, db, test1)

events := []model.TestRunEvent{
{TestID: test1.ID, RunID: run1.ID, Type: "EVENT_1", Stage: model.StageTrigger, Description: "This happened"},
{TestID: test1.ID, RunID: run1.ID, Type: "EVENT_2", Stage: model.StageTrigger, Description: "That happened now"},
{TestID: test1.ID, RunID: run1.ID, Type: "EVENT_1", Stage: model.StageTrigger, Title: "OP 1", Description: "This happened"},
{TestID: test1.ID, RunID: run1.ID, Type: "EVENT_2", Stage: model.StageTrigger, Title: "OP 2", Description: "That happened now"},

{TestID: test1.ID, RunID: run2.ID, Type: "EVENT_1", Stage: model.StageTrigger, Description: "That happened", DataStoreConnection: model.ConnectionResult{
{TestID: test1.ID, RunID: run2.ID, Type: "EVENT_1", Stage: model.StageTrigger, Title: "OP 1", Description: "That happened", DataStoreConnection: model.ConnectionResult{
PortCheck: model.ConnectionTestStep{
Passed: true,
Status: model.StatusPassed,
Message: "Should pass",
Error: nil,
},
}},
{TestID: test1.ID, RunID: run2.ID, Type: "EVENT_2_FAILED", Stage: model.StageTrigger, Description: "That happened, but failed", Polling: model.PollingInfo{
{TestID: test1.ID, RunID: run2.ID, Type: "EVENT_2_FAILED", Stage: model.StageTrigger, Title: "OP 2", Description: "That happened, but failed", Polling: model.PollingInfo{
Type: model.PollingTypePeriodic,
Periodic: &model.PeriodicPollingConfig{
NumberSpans: 3,
NumberIterations: 1,
},
}},
{TestID: test1.ID, RunID: run2.ID, Type: "ANOTHER_EVENT", Stage: model.StageTrigger, Description: "Clean up after error", Outputs: []model.OutputInfo{
{TestID: test1.ID, RunID: run2.ID, Type: "ANOTHER_EVENT", Stage: model.StageTrigger, Title: "OP 3", Description: "Clean up after error", Outputs: []model.OutputInfo{
{LogLevel: model.LogLevelWarn, Message: "INVALID SYNTAX", OutputName: "my_output"},
}},
}
Expand All @@ -52,6 +52,8 @@ func TestRunEvents(t *testing.T) {

assert.Len(t, events, 2)
assert.LessOrEqual(t, events[0].CreatedAt, events[1].CreatedAt)
assert.Equal(t, "OP 1", events[0].Title)
assert.Equal(t, "OP 2", events[1].Title)

eventsFromRun2, err := db.GetTestRunEvents(context.Background(), test1.ID, run2.ID)
require.NoError(t, err)
Expand All @@ -60,7 +62,7 @@ func TestRunEvents(t *testing.T) {
assert.LessOrEqual(t, eventsFromRun2[0].CreatedAt, eventsFromRun2[1].CreatedAt)
assert.LessOrEqual(t, eventsFromRun2[1].CreatedAt, eventsFromRun2[2].CreatedAt)

// assert eevents from run 2 have fields that were stored as JSON
// assert events from run 2 have fields that were stored as JSON
// data store connection
assert.Equal(t, true, eventsFromRun2[0].DataStoreConnection.PortCheck.Passed)
assert.Equal(t, model.StatusPassed, eventsFromRun2[0].DataStoreConnection.PortCheck.Status)
Expand Down
1 change: 1 addition & 0 deletions web/src/types/Generated.types.ts
Expand Up @@ -1797,6 +1797,7 @@ export interface external {
type?: string;
/** @enum {string} */
stage?: "trigger" | "trace" | "test";
title?: string;
description?: string;
/** Format: date-time */
createdAt?: string;
Expand Down

0 comments on commit a7ad995

Please sign in to comment.