worker/osbuild: move target errors to detail of job error
Add a new worker client error type `ErrorTargetError` representing that at least one of job targets failed. The actual target errors are added to the job detail. Add a new `OSBuildJobResult.TargetErrors()` method for gathering a slice of target errors contained within an `OSBuildJobResult` instance. Cover the method with unit test.
This commit is contained in:
parent
20cb2e1b2c
commit
6dcadc9d20
5 changed files with 112 additions and 3 deletions
85
internal/worker/json_test.go
Normal file
85
internal/worker/json_test.go
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package worker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestOSBuildJobResultTargetErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
jobResult OSBuildJobResult
|
||||
targetErrors []*clienterrors.Error
|
||||
}{
|
||||
{
|
||||
jobResult: OSBuildJobResult{
|
||||
TargetResults: []*target.TargetResult{
|
||||
{
|
||||
Name: target.TargetNameAWS,
|
||||
TargetError: clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "can't login to AWS"),
|
||||
},
|
||||
{
|
||||
Name: target.TargetNameVMWare,
|
||||
TargetError: clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "can't upload image to VMWare"),
|
||||
},
|
||||
{
|
||||
Name: target.TargetNameAWSS3,
|
||||
TargetError: clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "failed to upload image to AWS S3"),
|
||||
},
|
||||
},
|
||||
},
|
||||
targetErrors: []*clienterrors.Error{
|
||||
clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "can't login to AWS", target.TargetNameAWS),
|
||||
clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "can't upload image to VMWare", target.TargetNameVMWare),
|
||||
clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "failed to upload image to AWS S3", target.TargetNameAWSS3),
|
||||
},
|
||||
},
|
||||
{
|
||||
jobResult: OSBuildJobResult{
|
||||
TargetResults: []*target.TargetResult{
|
||||
{
|
||||
Name: target.TargetNameAWS,
|
||||
TargetError: clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "can't login to AWS"),
|
||||
},
|
||||
{
|
||||
Name: target.TargetNameVMWare,
|
||||
},
|
||||
{
|
||||
Name: target.TargetNameAWSS3,
|
||||
TargetError: clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "failed to upload image to AWS S3"),
|
||||
},
|
||||
},
|
||||
},
|
||||
targetErrors: []*clienterrors.Error{
|
||||
clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "can't login to AWS", target.TargetNameAWS),
|
||||
clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, "failed to upload image to AWS S3", target.TargetNameAWSS3),
|
||||
},
|
||||
},
|
||||
{
|
||||
jobResult: OSBuildJobResult{
|
||||
TargetResults: []*target.TargetResult{
|
||||
{
|
||||
Name: target.TargetNameAWS,
|
||||
},
|
||||
{
|
||||
Name: target.TargetNameVMWare,
|
||||
},
|
||||
{
|
||||
Name: target.TargetNameAWSS3,
|
||||
},
|
||||
},
|
||||
},
|
||||
targetErrors: []*clienterrors.Error{},
|
||||
},
|
||||
{
|
||||
jobResult: OSBuildJobResult{},
|
||||
targetErrors: []*clienterrors.Error{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
assert.EqualValues(t, testCase.targetErrors, testCase.jobResult.TargetErrors())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue