chore(gitops): increase coverage BE-13171 (#3314)

This commit is contained in:
andres-portainer
2026-08-04 16:26:28 -03:00
committed by GitHub
parent 5205ca95e2
commit b2009d1937
+33
View File
@@ -1,9 +1,11 @@
package workflows
import (
"errors"
"testing"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
"github.com/portainer/portainer/api/datastore"
"github.com/stretchr/testify/require"
@@ -45,6 +47,18 @@ func TestDeleteIfSingleArtifact_MultipleArtifactsAreKept(t *testing.T) {
require.NoError(t, err)
}
// TestDeleteIfSingleArtifact_ReadErrorPropagates covers the branch where the Workflow lookup
// fails for a reason other than not-found (e.g. a corrupt record); that error must still
// surface to the caller instead of being swallowed alongside the not-found case.
func TestDeleteIfSingleArtifact_ReadErrorPropagates(t *testing.T) {
t.Parallel()
wantErr := errors.New("boom")
store := erroringWorkflowStore{err: wantErr}
err := DeleteIfSingleArtifact(store, 1)
require.ErrorIs(t, err, wantErr)
}
func TestDeleteIfSingleArtifact_SingleArtifactIsDeleted(t *testing.T) {
t.Parallel()
_, store := datastore.MustNewTestStore(t, false, true)
@@ -61,3 +75,22 @@ func TestDeleteIfSingleArtifact_SingleArtifactIsDeleted(t *testing.T) {
_, err = store.Workflow().Read(wf.ID)
require.Error(t, err)
}
// erroringWorkflowStore is a workflowDeleteStore whose Workflow().Read always fails with a
// non-not-found error, to exercise the error-propagation branch of DeleteIfSingleArtifact.
type erroringWorkflowStore struct {
err error
}
func (s erroringWorkflowStore) Workflow() dataservices.WorkflowService {
return erroringWorkflowService{err: s.err}
}
type erroringWorkflowService struct {
dataservices.WorkflowService
err error
}
func (s erroringWorkflowService) Read(portainer.WorkflowID) (*portainer.Workflow, error) {
return nil, s.err
}