-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osbuild-worker: improve error "reason" in case of stage failures
- Loading branch information
1 parent
4e1ab4c
commit afcafa7
Showing
3 changed files
with
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
package main | ||
|
||
var WorkerClientErrorFrom = workerClientErrorFrom | ||
var ( | ||
WorkerClientErrorFrom = workerClientErrorFrom | ||
MakeJobErrorFromOsbuildOutput = makeJobErrorFromOsbuildOutput | ||
) |
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,81 @@ | ||
package main_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/osbuild/images/pkg/osbuild" | ||
|
||
main "github.com/osbuild/osbuild-composer/cmd/osbuild-worker" | ||
) | ||
|
||
func TestMakeJobErrorFromOsbuildOutput(t *testing.T) { | ||
tests := []struct { | ||
inputData *osbuild.Result | ||
expected string | ||
}{ | ||
{ | ||
inputData: &osbuild.Result{ | ||
Success: false, | ||
Log: map[string]osbuild.PipelineResult{ | ||
"fake-os": []osbuild.StageResult{ | ||
{ | ||
Type: "good-stage", | ||
Success: true, | ||
Output: "good-output", | ||
}, | ||
{ | ||
Type: "bad-stage", | ||
Success: false, | ||
Output: "bad-failure", | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: `Code: 10, Reason: osbuild build failed in stage: | ||
bad-stage, Details: []`, | ||
}, | ||
{ | ||
inputData: &osbuild.Result{ | ||
Success: false, | ||
Log: map[string]osbuild.PipelineResult{ | ||
"fake-os": []osbuild.StageResult{}, | ||
}, | ||
}, | ||
expected: `Code: 10, Reason: osbuild build failed, Details: []`, | ||
}, | ||
{ | ||
inputData: &osbuild.Result{ | ||
Error: json.RawMessage("some_osbuild_error"), | ||
Success: false, | ||
Log: map[string]osbuild.PipelineResult{ | ||
"fake-os": []osbuild.StageResult{}, | ||
}, | ||
}, | ||
expected: `Code: 10, Reason: osbuild build failed, Details: [osbuild error: some_osbuild_error]`, | ||
}, | ||
{ | ||
inputData: &osbuild.Result{ | ||
Errors: []osbuild.ValidationError{ | ||
{ | ||
Message: "validation error message", | ||
Path: []string{"error path"}, | ||
}, | ||
}, | ||
Success: false, | ||
Log: map[string]osbuild.PipelineResult{ | ||
"fake-os": []osbuild.StageResult{}, | ||
}, | ||
}, | ||
expected: `Code: 10, Reason: osbuild build failed, Details: [manifest validation error: {validation error message [error path]}]`, | ||
}, | ||
} | ||
for _, testData := range tests { | ||
fakeOsbuildResult := testData.inputData | ||
|
||
wce := main.MakeJobErrorFromOsbuildOutput(fakeOsbuildResult) | ||
require.Equal(t, testData.expected, wce.String()) | ||
} | ||
} |