fleet/orbit/pkg/useraction/mdm_migration_darwin_test.go
Roberto Dip ea6b59f179
upgrade Go version to 1.21.1 (#13877)
For #13715, this:

- Upgrades the Go version to `1.21.1`, infrastructure changes are
addressed separately at https://github.com/fleetdm/fleet/pull/13878
- Upgrades the linter version, as the current version doesn't work well
after the Go upgrade
- Fixes new linting errors (we now get errors for memory aliasing in
loops! 🎉 )

After this is merged people will need to:

1. Update their Go version. I use `gvm` and I did it like:

```
$ gvm install go1.21.1
$ gvm use go1.21.1 --default
```

2. Update the local version of `golangci-lint`:

```
$ go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2
```

3. (optional) depending on your setup, you might need to re-install some
packages, for example:

```
# goimports to automatically import libraries
$  go install golang.org/x/tools/cmd/goimports@latest

# gopls for the language server
$ go install golang.org/x/tools/gopls@latest

# etc...
```
2023-09-13 15:59:35 -03:00

59 lines
1.3 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) {
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.testEnrollmentCheckFn = func() (bool, error) {
if tries >= c.unenrollAfterNTries {
return false, c.enrollErr
}
tries++
return true, c.enrollErr
}
outErr := m.waitForUnenrollment()
if c.wantErr {
require.Error(t, outErr)
} else {
require.NoError(t, outErr)
require.Equal(t, c.unenrollAfterNTries, tries)
}
})
}
}