| package tilo |
| |
| import ( |
| "time" |
| |
| "fuchsia.googlesource.com/infra/infra/fuchsia/testexec" |
| "fuchsia.googlesource.com/infra/infra/tilo/resultstore" |
| ) |
| |
| // TestStatus describes the outcome of a test. |
| type TestStatus = resultstore.Status |
| |
| // TestStatus constants. |
| const ( |
| TestPassed = resultstore.Passed |
| TestFailed = resultstore.Failed |
| ) |
| |
| // TestFinishedEvent represents the ending of some test. |
| type TestFinishedEvent struct { |
| TestName string |
| EnvName string |
| StartTime time.Time |
| EndTime time.Time |
| LogFileURI string |
| TestStatus TestStatus |
| } |
| |
| // ToTestAction returns a TestAction that should be passed to |
| // resultstore.Service.UpdateTestAction. |
| func (e TestFinishedEvent) ToTestAction(name string) *resultstore.TestAction { |
| return &resultstore.TestAction{ |
| Name: name, |
| StartTime: e.StartTime, |
| Duration: e.EndTime.Sub(e.StartTime), |
| Status: resultstore.Status(e.TestStatus), |
| TestLogURI: e.LogFileURI, |
| } |
| } |
| |
| // ToConfiguredTarget returns a ConfiguredTarget that should be passed to |
| // resultstore.Service.UpdateConfiguredTarget |
| func (e TestFinishedEvent) ToConfiguredTarget(name string) *resultstore.ConfiguredTarget { |
| return &resultstore.ConfiguredTarget{ |
| Name: name, |
| StartTime: e.StartTime, |
| Duration: e.EndTime.Sub(e.StartTime), |
| Status: resultstore.Status(e.TestStatus), |
| } |
| } |
| |
| // ToTarget returns a Target that should be passed to resultstore.Service.UpdateTarget. |
| func (e TestFinishedEvent) ToTarget(name string) *resultstore.Target { |
| return &resultstore.Target{ |
| Name: name, |
| StartTime: e.StartTime, |
| Duration: e.EndTime.Sub(e.StartTime), |
| Status: resultstore.Status(e.TestStatus), |
| } |
| } |
| |
| // TestStartedEvent represents the start of some test. |
| type TestStartedEvent struct { |
| TestName string |
| EnvName string |
| StartTime time.Time |
| } |
| |
| // ToTestAction returns a TestAction that should be passed to |
| // resultstore.Service.CreateTestAction. |
| func (e TestStartedEvent) ToTestAction(invocationID string) *resultstore.TestAction { |
| return &resultstore.TestAction{ |
| ID: "test", |
| InvocationID: invocationID, |
| TestSuite: e.TestName, |
| TargetID: e.TestName, |
| ConfigID: e.EnvName, |
| StartTime: e.StartTime, |
| } |
| } |
| |
| // ToConfiguredTarget returns a ConfiguredTarget that should be passed to |
| // resultstore.Service.CreateConfiguredTarget. |
| func (e TestStartedEvent) ToConfiguredTarget(invocationID string) *resultstore.ConfiguredTarget { |
| return &resultstore.ConfiguredTarget{ |
| InvocationID: invocationID, |
| ConfigID: e.EnvName, |
| TargetID: e.TestName, |
| StartTime: e.StartTime, |
| } |
| } |
| |
| // ToTarget returns a Target that should be passed to resultstore.Service.UpdateTarget. |
| func (e TestStartedEvent) ToTarget(invocationID string) *resultstore.Target { |
| return &resultstore.Target{ |
| InvocationID: invocationID, |
| ID: e.TestName, |
| StartTime: e.StartTime, |
| } |
| } |
| |
| // TestFoundEvent represents the discovery of a test. |
| type TestFoundEvent testexec.Test |
| |
| // ToTarget returns a Target that should be passed to resultstore.Service.CreateTarget. |
| func (e TestFoundEvent) ToTarget(invocationID string) *resultstore.Target { |
| test := testexec.Test(e) |
| return &resultstore.Target{ |
| ID: test.Name, |
| InvocationID: invocationID, |
| } |
| } |
| |
| // EnvironmentFoundEvent represents the discovery of a test environment. |
| type EnvironmentFoundEvent testexec.Environment |
| |
| // ToConfig returns a Configuration that should be passed to |
| // resultstore.CreateConfiguration. |
| func (e EnvironmentFoundEvent) ToConfig(invocationID string) *resultstore.Configuration { |
| env := testexec.Environment(e) |
| return &resultstore.Configuration{ |
| ID: env.Name(), |
| InvocationID: invocationID, |
| Properties: dimensionSetToMap(env.Dimensions), |
| } |
| } |
| |
| func dimensionSetToMap(set testexec.DimensionSet) map[string]string { |
| return map[string]string{ |
| "device_type": set.DeviceType, |
| } |
| } |