Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed May 7, 2024
1 parent 41ea597 commit dc6c3f8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/sidecarlogresults/sidecarlogresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func parseResults(resultBytes []byte, maxResultLimit int) (result.RunResult, err
case stepArtifactType:
resultType = result.StepArtifactsResultType
default:
return result.RunResult{}, fmt.Errorf("invalid sidecar result type %v. Must be %v or %v", res.Type, taskResultType, stepResultType)
return result.RunResult{}, fmt.Errorf("invalid sidecar result type %v. Must be %v or %v or %v", res.Type, taskResultType, stepResultType, stepArtifactType)
}
runResult = result.RunResult{
Key: res.Name,
Expand Down
68 changes: 66 additions & 2 deletions internal/sidecarlogresults/sidecarlogresults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@ func TestParseResults(t *testing.T) {
Name: "step-foo.result3",
Value: `["hello","world"]`,
Type: "step",
}, {
Name: "step-artifacts-result",
Value: `{
"inputs":[
{
"name":"input-artifacts",
"values":[
{
"uri":"pkg:example.github.com/inputs",
"digest":{
"sha256":"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"
}
}
]
}
],
"outputs":[
{
"name":"image",
"values":[
{
"uri":"pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c",
"digest":{
"sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48",
"sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2"
}
}
]
}
]
}`,
Type: "stepArtifact",
},
}
podLogs := []string{}
Expand Down Expand Up @@ -336,6 +368,38 @@ func TestParseResults(t *testing.T) {
Key: "step-foo.result3",
Value: `["hello","world"]`,
ResultType: result.StepResultType,
}, {
Key: "step-artifacts-result",
Value: `{
"inputs":[
{
"name":"input-artifacts",
"values":[
{
"uri":"pkg:example.github.com/inputs",
"digest":{
"sha256":"b35cacccfdb1e24dc497d15d553891345fd155713ffe647c281c583269eaaae0"
}
}
]
}
],
"outputs":[
{
"name":"image",
"values":[
{
"uri":"pkg:github/package-url/purl-spec@244fd47e07d1004f0aed9c",
"digest":{
"sha256":"df85b9e3983fe2ce20ef76ad675ecf435cc99fc9350adc54fa230bae8c32ce48",
"sha1":"95588b8f34c31eb7d62c92aaa4e6506639b06ef2"
}
}
]
}
]
}`,
ResultType: result.StepArtifactsResultType,
}}
stepResults := []result.RunResult{}
for _, plog := range podLogs {
Expand All @@ -354,7 +418,7 @@ func TestParseResults_InvalidType(t *testing.T) {
results := []SidecarLogResult{{
Name: "result1",
Value: "foo",
Type: "not task or step",
Type: "invalid",
}}
podLogs := []string{}
for _, r := range results {
Expand All @@ -363,7 +427,7 @@ func TestParseResults_InvalidType(t *testing.T) {
}
for _, plog := range podLogs {
_, err := parseResults([]byte(plog), 4096)
wantErr := errors.New("invalid sidecar result type not task or step. Must be task or step")
wantErr := errors.New("invalid sidecar result type invalid. Must be task or step or stepArtifact")
if d := cmp.Diff(wantErr.Error(), err.Error()); d != "" {
t.Fatal(diff.PrintWantGot(d))
}
Expand Down

0 comments on commit dc6c3f8

Please sign in to comment.