test: add retry to ftp test
This commit is contained in:
parent
2672b17f44
commit
b2d8e22977
1 changed files with 34 additions and 9 deletions
|
@ -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)
|
||||||
|
|
||||||
|
err := retry.Do(func() error {
|
||||||
testza.AssertNoError(t, os.RemoveAll(filepath.Join(serverLocation, "FactoryGame", "Mods")))
|
testza.AssertNoError(t, os.RemoveAll(filepath.Join(serverLocation, "FactoryGame", "Mods")))
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
installation, err := ctx.Installations.AddInstallation(ctx, "ftp://user:pass@localhost:2121/server", profileName)
|
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)
|
testza.AssertNotNil(t, installation)
|
||||||
|
|
||||||
err = installation.Install(ctx, installWatcher())
|
err = installation.Install(ctx, installWatcher())
|
||||||
testza.AssertNoError(t, err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
installation.Vanilla = true
|
installation.Vanilla = true
|
||||||
err = installation.Install(ctx, installWatcher())
|
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)
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue