-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TimHuynh
committed
Jan 17, 2025
1 parent
41df509
commit 86d822d
Showing
16 changed files
with
263 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package pipeline | ||
|
||
// 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"` | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package pipeline | ||
|
||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package yaml | ||
|
||
import "github.com/go-vela/server/compiler/types/pipeline" | ||
|
||
// TestReport represents the structure for test report configuration. | ||
type TestReport struct { | ||
Results []string `yaml:"results,omitempty" json:"results,omitempty"` | ||
Attachments []string `yaml:"attachments,omitempty" json:"attachments,omitempty"` | ||
} | ||
|
||
// ToPipeline converts the TestReport type | ||
// to a pipeline TestReport type. | ||
func (t *TestReport) ToPipeline() *pipeline.TestReport { | ||
return &pipeline.TestReport{ | ||
Results: t.Results, | ||
Attachments: t.Attachments, | ||
} | ||
} | ||
|
||
// UnmarshalYAML implements the Unmarshaler interface for the TestReport type. | ||
func (t *TestReport) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
// test report we try unmarshalling to | ||
testReport := new(struct { | ||
Results []string `yaml:"results,omitempty" json:"results,omitempty"` | ||
Attachments []string `yaml:"attachments,omitempty" json:"attachments,omitempty"` | ||
}) | ||
|
||
// attempt to unmarshal test report type | ||
err := unmarshal(testReport) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// set the results field | ||
t.Results = testReport.Results | ||
// set the attachments field | ||
t.Attachments = testReport.Attachments | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.