test: add retry to ftp test

This commit is contained in:
Vilsol 2023-12-28 02:28:21 +02:00
parent 2672b17f44
commit b2d8e22977
No known key found for this signature in database

View file

@ -1,6 +1,7 @@
package cli
import (
"log/slog"
"os"
"path/filepath"
"runtime"
@ -8,6 +9,7 @@ import (
"time"
"github.com/MarvinJWendt/testza"
"github.com/avast/retry-go"
"github.com/satisfactorymodding/ficsit-cli/cfg"
)
@ -98,19 +100,42 @@ func TestAddFTPInstallation(t *testing.T) {
serverLocation := os.Getenv("SF_DEDICATED_SERVER")
if serverLocation != "" {
time.Sleep(time.Second)
err := retry.Do(func() error {
testza.AssertNoError(t, os.RemoveAll(filepath.Join(serverLocation, "FactoryGame", "Mods")))
time.Sleep(time.Second)
installation, err := ctx.Installations.AddInstallation(ctx, "ftp://user:pass@localhost:2121/server", profileName)
testza.AssertNoError(t, err)
if err != nil {
return err
}
testza.AssertNotNil(t, installation)
err = installation.Install(ctx, installWatcher())
testza.AssertNoError(t, err)
if err != nil {
return err
}
installation.Vanilla = true
err = installation.Install(ctx, installWatcher())
if err != nil {
return err
}
return nil
},
retry.Attempts(30),
retry.Delay(time.Second),
retry.DelayType(retry.FixedDelay),
retry.OnRetry(func(n uint, err error) {
if n > 0 {
slog.Info("retrying ftp test", slog.Uint64("n", uint64(n)))
}
}),
)
testza.AssertNoError(t, err)
time.Sleep(time.Second)
}