-
Notifications
You must be signed in to change notification settings - Fork 30
feat(test reports): test_report key functionality #1278
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
base: main
Are you sure you want to change the base?
Changes from all commits
ca76bd4
9b5142b
fd358ff
90487e6
676e374
83f56c8
0f333ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package types | ||
|
|
||
| import "fmt" | ||
|
|
||
| // TestReport is the API representation of a test report for a pipeline. | ||
| // | ||
| // swagger:model TestReport | ||
| type TestReport struct { | ||
| Results *string `json:"results,omitempty"` | ||
| Attachments *string `json:"attachments,omitempty"` | ||
| } | ||
|
|
||
| // GetResults returns the Results field. | ||
| // | ||
| // When the provided TestReport type is nil, or the field within | ||
| // the type is nil, it returns the zero value for the field. | ||
| func (t *TestReport) GetResults() string { | ||
| // return zero value if TestReport type or Results field is nil | ||
| if t == nil || t.Results == nil { | ||
| return "" | ||
| } | ||
|
|
||
| return *t.Results | ||
| } | ||
|
|
||
| // GetAttachments returns the Attachments field. | ||
| // | ||
| // When the provided TestReport type is nil, or the field within | ||
| // the type is nil, it returns the zero value for the field. | ||
| func (t *TestReport) GetAttachments() string { | ||
| // return zero value if TestReport type or Attachments field is nil | ||
| if t == nil || t.Attachments == nil { | ||
| return "" | ||
| } | ||
|
|
||
| return *t.Attachments | ||
| } | ||
|
|
||
| // SetResults sets the Results field. | ||
| func (t *TestReport) SetResults(v string) { | ||
| // return if TestReport type is nil | ||
| if t == nil { | ||
| return | ||
| } | ||
| // set the Results field | ||
| t.Results = &v | ||
| } | ||
|
|
||
| // SetAttachments sets the Attachments field. | ||
| func (t *TestReport) SetAttachments(v string) { | ||
| // return if TestReport type is nil | ||
| if t == nil { | ||
| return | ||
| } | ||
| // set the Attachments field | ||
| t.Attachments = &v | ||
| } | ||
|
|
||
| // String implements the Stringer interface for the TestReport type. | ||
| func (t *TestReport) String() string { | ||
| return fmt.Sprintf("Results: %s, Attachments: %s", t.GetResults(), t.GetAttachments()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,7 +108,9 @@ | |
|
|
||
| if len(step.Commands) == 0 && len(step.Environment) == 0 && | ||
| len(step.Parameters) == 0 && len(step.Secrets) == 0 && | ||
| len(step.Template.Name) == 0 && !step.Detach { | ||
| len(step.Template.Name) == 0 && len(step.TestReport.Results) == 0 && | ||
| len(step.TestReport.Attachments) == 0 && !step.Detach { | ||
|
Check failure on line 112 in compiler/native/validate.go
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| return fmt.Errorf("no commands, environment, parameters, secrets or template provided for step %s", step.Name) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |
| Pull string `json:"pull,omitempty" yaml:"pull,omitempty"` | ||
| Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"` | ||
| Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"` | ||
| TestReport TestReport `json:"test_report,omitempty" yaml:"test_report,omitempty"` | ||
|
Check failure on line 51 in compiler/types/pipeline/container.go
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"` | ||
| Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"` | ||
| User string `json:"user,omitempty" yaml:"user,omitempty"` | ||
|
|
@@ -137,7 +138,8 @@ | |
| len(c.Volumes) == 0 && | ||
| len(c.User) == 0 && | ||
| len(c.ReportAs) == 0 && | ||
| len(c.IDRequest) == 0 { | ||
| len(c.IDRequest) == 0 && | ||
| reflect.DeepEqual(c.TestReport, TestReport{}) { | ||
| return true | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package pipeline | ||
|
Check failure on line 1 in compiler/types/pipeline/test_report.go
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| // TestReport represents the structure for test report configuration. | ||
| type ( | ||
| // TestReportSlice is the pipleine representation | ||
| //of a slice of TestReport. | ||
| // | ||
| // swagger:model PipelineTestReportSlice | ||
| TestReportSlice []*TestReport | ||
|
|
||
| // TestReport is the pipeline representation | ||
| // of a test report for a pipeline. | ||
| // | ||
| // swagger:model PipelineTestReport | ||
| TestReport struct { | ||
| Results []string `yaml:"results,omitempty" json:"results,omitempty"` | ||
|
Check failure on line 16 in compiler/types/pipeline/test_report.go
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
| Attachments []string `yaml:"attachments,omitempty" json:"attachments,omitempty"` | ||
| } | ||
| ) | ||
|
|
||
| // Purge removes the test report configuration from the pipeline | ||
| // if it does not match the provided ruledata. If both results | ||
| // and attachments are provided, then an empty test report is returned. | ||
| //func (t *TestReport) Purge(r *RuleData) (*TestReport, error) { | ||
| // // return an empty test report if both results and attachments are provided | ||
| // if len(t.Results) > 0 && len(t.Attachments) > 0 { | ||
| // return nil, fmt.Errorf("cannot have both results and attachments in the test report") | ||
| // } | ||
| // | ||
| // // purge results if provided | ||
| // if len(t.Results) > 0 { | ||
| // t.Results = "" | ||
| // } | ||
| // | ||
| // // purge attachments if provided | ||
| // if len(t.Attachments) > 0 { | ||
| // t.Attachments = "" | ||
| // } | ||
| // | ||
| // // return the purged test report | ||
| // return t, nil | ||
| //} | ||
|
|
||
| // Empty returns true if the provided test report is empty. | ||
| func (t *TestReport) Empty() bool { | ||
| // return true if every test report field is empty | ||
| if len(t.Results) == 0 && | ||
| len(t.Attachments) == 0 { | ||
| return true | ||
| } | ||
|
|
||
| // return false if any of the test report fields are provided | ||
| return false | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package pipeline | ||
|
Check failure on line 1 in compiler/types/pipeline/test_report_test.go
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [golangci] reported by reviewdog 🐶 |
||
|
|
||
| import "testing" | ||
|
|
||
| func TestPipeline_TestReport_Empty(t *testing.T) { | ||
| // setup tests | ||
| tests := []struct { | ||
| report *TestReport | ||
| want bool | ||
| }{ | ||
| { | ||
| report: &TestReport{Results: []string{"foo"}}, | ||
| want: false, | ||
| }, | ||
| { | ||
| report: new(TestReport), | ||
| want: true, | ||
| }, | ||
| } | ||
|
|
||
| // run tests | ||
| for _, test := range tests { | ||
| got := test.report.Empty() | ||
|
|
||
| if got != test.want { | ||
| t.Errorf("Empty is %v, want %t", got, test.want) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
Missed header for check (goheader)