2021-12-02 04:00:33 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2022-05-02 20:07:15 +00:00
|
|
|
"os"
|
2023-12-28 00:13:09 +00:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2021-12-02 04:00:33 +00:00
|
|
|
"testing"
|
2023-12-28 00:13:09 +00:00
|
|
|
"time"
|
2021-12-02 04:00:33 +00:00
|
|
|
|
|
|
|
"github.com/MarvinJWendt/testza"
|
2023-12-28 01:22:55 +00:00
|
|
|
"goftp.io/server/v2"
|
|
|
|
"goftp.io/server/v2/driver/file"
|
|
|
|
|
2021-12-02 04:00:33 +00:00
|
|
|
"github.com/satisfactorymodding/ficsit-cli/cfg"
|
|
|
|
)
|
|
|
|
|
2023-12-28 00:13:09 +00:00
|
|
|
// NOTE:
|
|
|
|
//
|
|
|
|
// This code contains sleep.
|
|
|
|
// This is because github actions are special.
|
|
|
|
// They don't properly sync to disk.
|
|
|
|
// And Go is faster than their disk.
|
|
|
|
// So tests are flaky :)
|
|
|
|
// DO NOT REMOVE THE SLEEP!
|
|
|
|
|
2021-12-02 04:00:33 +00:00
|
|
|
func init() {
|
|
|
|
cfg.SetDefaults()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInstallationsInit(t *testing.T) {
|
|
|
|
installations, err := InitInstallations()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
testza.AssertNotNil(t, installations)
|
|
|
|
}
|
|
|
|
|
2023-12-28 00:13:09 +00:00
|
|
|
func TestAddLocalInstallation(t *testing.T) {
|
2022-10-14 16:11:16 +00:00
|
|
|
ctx, err := InitCLI(false)
|
2021-12-02 04:00:33 +00:00
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
2023-12-07 21:31:37 +00:00
|
|
|
err = ctx.Wipe()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
err = ctx.ReInit()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
2023-12-07 16:57:31 +00:00
|
|
|
ctx.Provider = MockProvider{}
|
|
|
|
|
2021-12-02 04:00:33 +00:00
|
|
|
profileName := "InstallationTest"
|
2021-12-04 18:02:05 +00:00
|
|
|
profile, err := ctx.Profiles.AddProfile(profileName)
|
|
|
|
testza.AssertNoError(t, err)
|
2023-12-16 11:59:58 +00:00
|
|
|
testza.AssertNoError(t, profile.AddMod("AreaActions", "1.6.5"))
|
|
|
|
testza.AssertNoError(t, profile.AddMod("RefinedPower", "3.2.10"))
|
2021-12-02 04:00:33 +00:00
|
|
|
|
2022-05-02 20:07:15 +00:00
|
|
|
serverLocation := os.Getenv("SF_DEDICATED_SERVER")
|
|
|
|
if serverLocation != "" {
|
2023-12-28 00:13:09 +00:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
testza.AssertNoError(t, os.RemoveAll(filepath.Join(serverLocation, "FactoryGame", "Mods")))
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
2022-05-02 20:07:15 +00:00
|
|
|
installation, err := ctx.Installations.AddInstallation(ctx, serverLocation, profileName)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
testza.AssertNotNil(t, installation)
|
|
|
|
|
2023-12-06 23:39:34 +00:00
|
|
|
err = installation.Install(ctx, installWatcher())
|
2022-05-02 20:07:15 +00:00
|
|
|
testza.AssertNoError(t, err)
|
2023-12-06 04:02:06 +00:00
|
|
|
|
|
|
|
installation.Vanilla = true
|
2023-12-06 23:39:34 +00:00
|
|
|
err = installation.Install(ctx, installWatcher())
|
2023-12-06 04:02:06 +00:00
|
|
|
testza.AssertNoError(t, err)
|
2023-12-28 00:13:09 +00:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ctx.Wipe()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddFTPInstallation(t *testing.T) {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Not supported
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-12-28 01:19:42 +00:00
|
|
|
ctx, err := InitCLI(false)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
err = ctx.Wipe()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
err = ctx.ReInit()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
ctx.Provider = MockProvider{}
|
|
|
|
|
|
|
|
profileName := "InstallationTest"
|
|
|
|
profile, err := ctx.Profiles.AddProfile(profileName)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
testza.AssertNoError(t, profile.AddMod("AreaActions", "1.6.5"))
|
|
|
|
testza.AssertNoError(t, profile.AddMod("RefinedPower", "3.2.10"))
|
|
|
|
|
|
|
|
serverLocation := os.Getenv("SF_DEDICATED_SERVER")
|
|
|
|
if serverLocation != "" {
|
|
|
|
driver, err := file.NewDriver(serverLocation)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
s, err := server.NewServer(&server.Options{
|
|
|
|
Driver: driver,
|
|
|
|
Auth: &server.SimpleAuth{
|
|
|
|
Name: "user",
|
|
|
|
Password: "pass",
|
|
|
|
},
|
|
|
|
Port: 2121,
|
|
|
|
Perm: server.NewSimplePerm("root", "root"),
|
|
|
|
})
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
defer testza.AssertNoError(t, s.Shutdown())
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
testza.AssertNoError(t, s.ListenAndServe())
|
|
|
|
}()
|
|
|
|
|
|
|
|
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/", profileName)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
testza.AssertNotNil(t, installation)
|
|
|
|
|
|
|
|
err = installation.Install(ctx, installWatcher())
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
installation.Vanilla = true
|
|
|
|
err = installation.Install(ctx, installWatcher())
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ctx.Wipe()
|
2023-12-28 00:13:09 +00:00
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddSFTPInstallation(t *testing.T) {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
// Not supported
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, err := InitCLI(false)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
err = ctx.Wipe()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
err = ctx.ReInit()
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
ctx.Provider = MockProvider{}
|
|
|
|
|
|
|
|
profileName := "InstallationTest"
|
|
|
|
profile, err := ctx.Profiles.AddProfile(profileName)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
testza.AssertNoError(t, profile.AddMod("AreaActions", "1.6.5"))
|
|
|
|
testza.AssertNoError(t, profile.AddMod("RefinedPower", "3.2.10"))
|
|
|
|
|
|
|
|
serverLocation := os.Getenv("SF_DEDICATED_SERVER")
|
|
|
|
if serverLocation != "" {
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
testza.AssertNoError(t, os.RemoveAll(filepath.Join(serverLocation, "FactoryGame", "Mods")))
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
|
|
|
installation, err := ctx.Installations.AddInstallation(ctx, "sftp://user:pass@localhost:2222/home/user/server", profileName)
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
testza.AssertNotNil(t, installation)
|
|
|
|
|
|
|
|
err = installation.Install(ctx, installWatcher())
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
|
|
|
|
installation.Vanilla = true
|
|
|
|
err = installation.Install(ctx, installWatcher())
|
|
|
|
testza.AssertNoError(t, err)
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ctx.Wipe()
|
|
|
|
testza.AssertNoError(t, err)
|
2021-12-02 04:00:33 +00:00
|
|
|
}
|