[tilo] Allow setting InvocationStatus independently from test results
(See subsequent changes) This is more convenient than updating the
Invocation inside Logger when a test fails.
Change-Id: Ic1e18502baad12aa26243849ea1d35ed9e3ecd31
diff --git a/tilo/logger.go b/tilo/logger.go
index 297f7ba..a8b15ac 100644
--- a/tilo/logger.go
+++ b/tilo/logger.go
@@ -101,6 +101,9 @@
// Action, ConfiguredTarget, and Target are updated and finished.
LogTestFinished(context.Context, TestFinishedEvent) error
+ // SetInvocationStatus updates the status of the Invocation.
+ SetInvocationStatus(context.Context, resultstore.Status) error
+
// End finishes the Invocation.
End(context.Context) error
}
@@ -177,13 +180,6 @@
return err
}
- // Fail the entire invocation if a single test failed.
- if e.TestStatus != TestPassed {
- if err := l.updateInvocationStatus(ctx, resultstore.Failed); err != nil {
- return err
- }
- }
-
return l.finishTarget(ctx, e)
}
@@ -196,7 +192,12 @@
return l.finishInvocation(ctx)
}
-func (l *logger) updateInvocationStatus(ctx context.Context, status resultstore.Status) error {
+func (l *logger) SetInvocationStatus(ctx context.Context, status resultstore.Status) error {
+ ctx, err := l.setAuthToken(ctx)
+ if err != nil {
+ return err
+ }
+
invocationName, err := l.invocationName()
if err != nil {
return err
diff --git a/tilo/logger_test.go b/tilo/logger_test.go
index c263138..0020a8e 100644
--- a/tilo/logger_test.go
+++ b/tilo/logger_test.go
@@ -186,15 +186,9 @@
})
})
- t.Run("LogTestFinished", func(t *testing.T) {
- t.Run("should mark a failed test's TestAction, ConfiguredTarget, Target and the Invocation as failed", func(t *testing.T) {
+ t.Run("SetInvocationStatus", func(t *testing.T) {
+ t.Run("should update the Invocation's status", func(t *testing.T) {
test(t, func(tester *loggerTester, logger tilo.Logger) {
- input := tilo.TestFinishedEvent{
- TestName: "test_a",
- EnvName: "env_a",
- TestStatus: tilo.TestFailed,
- }
-
expectedInvocation := &resultstore.Invocation{
Name: "resultstore_invocation_name",
Status: resultstore.Failed,
@@ -204,39 +198,6 @@
"status_attributes",
}
- expectedTarget := &resultstore.Target{
- Name: "resultstore_target_name",
- Status: resultstore.Failed,
- }
-
- expectedTargetFields := []string{
- "timing.start_time",
- "status_attributes",
- }
-
- expectedConfiguredTarget := &resultstore.ConfiguredTarget{
- Name: "resultstore_cfg_tgt_name",
- Status: resultstore.Failed,
- }
-
- expectedConfiguredTargetFields := []string{
- "timing.start_time",
- "timing.duration",
- "status_attributes",
- }
-
- expectedTestAction := &resultstore.TestAction{
- Name: "resultstore_action_name",
- Status: resultstore.Failed,
- }
-
- expectedTestActionFields := []string{
- "timing.start_time",
- "timing.duration",
- "status_attributes",
- "files",
- }
-
tester.SetInvocationName("resultstore_invocation_name")
tester.SetInvocationID("inv_id")
@@ -245,35 +206,15 @@
tester.AssertNil(err)
tester.SetAuthToken("auth_token")
- // Set the names of each entity that would have been created by the
- // ResultStore backend because the Logger reads these names when coverting
- // test events their ResultStore counterparts.
- tester.SetConfiguredTarget("test_a", "env_a", "resultstore_cfg_tgt_name")
- tester.SetTarget("test_a", "resultstore_target_name")
- tester.SetTestAction("test_a", "env_a", "resultstore_action_name")
-
- tester.EXPECT().
- UpdateTestAction(expectedContext, expectedTestAction, expectedTestActionFields).
- Return(expectedTestAction, nil)
- tester.EXPECT().
- UpdateConfiguredTarget(expectedContext, expectedConfiguredTarget, expectedConfiguredTargetFields).
- Return(expectedConfiguredTarget, nil)
- tester.EXPECT().
- FinishConfiguredTarget(expectedContext, "resultstore_cfg_tgt_name").
- Return(nil)
- tester.EXPECT().
- UpdateTarget(expectedContext, expectedTarget, expectedTargetFields).
- Return(expectedTarget, nil)
- tester.EXPECT().
- FinishTarget(expectedContext, "resultstore_target_name").
- Return(nil)
tester.EXPECT().
UpdateInvocation(expectedContext, expectedInvocation, expectedInvocationFields).
Return(nil, nil)
- tester.AssertNil(logger.LogTestFinished(ctx, input))
+ tester.AssertNil(logger.SetInvocationStatus(ctx, resultstore.Failed))
})
})
+ })
+ t.Run("LogTestFinished", func(t *testing.T) {
t.Run("should udpate and Finish a test's ConfiguredTarget, Action, and Target", func(t *testing.T) {
test(t, func(tester *loggerTester, logger tilo.Logger) {
startTime := time.Date(1, 2, 3, 4, 5, 6, 7, time.UTC)