fleet/orbit/pkg/useraction/mdm_migration_darwin_test.go
Victor Lyuboslavsky e0d36366fe
Moving Go integration tests to integration test job (#21126)
#20929
Moving Go integration tests to integration test job, which runs tests
that start with `TestIntegrations`
Test changes only. No product changes
2024-08-07 14:00:25 +02:00

77 lines
1.7 KiB
Go

package useraction
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/require"
)
type dummyHandler struct{}
func (d dummyHandler) NotifyRemote() error {
return nil
}
func (d dummyHandler) ShowInstructions() error { return nil }
func TestWaitForUnenrollment(t *testing.T) {
t.Parallel()
m := &swiftDialogMDMMigrator{
handler: dummyHandler{},
baseDialog: newBaseDialog("foo/bar"),
frequency: 15 * time.Minute,
unenrollmentRetryInterval: 300 * time.Millisecond,
}
cases := []struct {
name string
enrollErr error
unenrollAfterNTries int
wantErr bool
}{
{"unenroll after 3 tries", nil, 3, false},
{"unenroll after one try", nil, 1, false},
{"error after max number of tries is exceeded", nil, 1000, true},
{"always error calling profiles func", errors.New("test"), 1, true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
tries := 0
m.testEnrollmentCheckFileFn = func() (bool, error) {
if tries >= c.unenrollAfterNTries {
return false, c.enrollErr
}
tries++
return true, c.enrollErr
}
m.testEnrollmentCheckStatusFn = func() (bool, string, error) {
return true, "example.com", nil
}
outErr := m.waitForUnenrollment()
if c.wantErr {
require.Error(t, outErr)
} else {
require.NoError(t, outErr)
require.Equal(t, c.unenrollAfterNTries, tries)
}
})
}
t.Run("fallback to enrollment check file", func(t *testing.T) {
m.testEnrollmentCheckFileFn = func() (bool, error) {
return true, nil
}
m.testEnrollmentCheckStatusFn = func() (bool, string, error) {
return false, "", nil
}
outErr := m.waitForUnenrollment()
require.NoError(t, outErr)
})
}