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