mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-26 07:59:37 -05:00
968cdc1a38
* cli: move internal packages Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * cli: fix buildfiles Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * bazel: fix exclude dir Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * cli: move back libraries that will not be used by TF provider Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
105 lines
1.8 KiB
Go
105 lines
1.8 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package helm
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRetryApply(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
applier *stubRetriableApplier
|
|
wantErr bool
|
|
}{
|
|
"success": {
|
|
applier: &stubRetriableApplier{
|
|
atomic: true,
|
|
},
|
|
},
|
|
"two errors": {
|
|
applier: &stubRetriableApplier{
|
|
applyErrs: []error{
|
|
assert.AnError,
|
|
assert.AnError,
|
|
nil,
|
|
},
|
|
atomic: true,
|
|
},
|
|
},
|
|
"retries are aborted after maximumRetryAttempts": {
|
|
applier: &stubRetriableApplier{
|
|
applyErrs: []error{
|
|
assert.AnError,
|
|
assert.AnError,
|
|
assert.AnError,
|
|
assert.AnError,
|
|
},
|
|
atomic: true,
|
|
},
|
|
wantErr: true,
|
|
},
|
|
"non atomic actions are not retried": {
|
|
applier: &stubRetriableApplier{
|
|
atomic: false,
|
|
applyErrs: []error{
|
|
assert.AnError,
|
|
assert.AnError,
|
|
nil,
|
|
},
|
|
},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
err := retryApply(context.Background(), tc.applier, time.Millisecond, logger.NewTest(t))
|
|
if tc.wantErr {
|
|
assert.Error(err)
|
|
} else {
|
|
assert.NoError(err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
type stubRetriableApplier struct {
|
|
atomic bool
|
|
applyErrs []error
|
|
}
|
|
|
|
func (s *stubRetriableApplier) apply(context.Context) error {
|
|
if len(s.applyErrs) == 0 {
|
|
return nil
|
|
}
|
|
|
|
// return the first error in the list
|
|
// and remove it from the list
|
|
err := s.applyErrs[0]
|
|
if len(s.applyErrs) > 1 {
|
|
s.applyErrs = s.applyErrs[1:]
|
|
} else {
|
|
s.applyErrs = nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s *stubRetriableApplier) ReleaseName() string {
|
|
return ""
|
|
}
|
|
|
|
func (s *stubRetriableApplier) IsAtomic() bool {
|
|
return s.atomic
|
|
}
|