Skip to content

Commit

Permalink
fix: various edge cases
Browse files Browse the repository at this point in the history
test: add tea unit test
  • Loading branch information
Vilsol committed Dec 7, 2023
1 parent 5f2e60a commit 8e1942d
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 602 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
run: go generate -tags tools -x ./...

- name: Test
run: go test -v ./...
run: go test -race -v ./...
env:
SF_DEDICATED_SERVER: ${{ github.workspace }}/SatisfactoryDedicatedServer
GOMAXPROCS: "1"
20 changes: 20 additions & 0 deletions cli/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ func InitCLI(apiOnly bool) (*GlobalContext, error) {
return globalContext, nil
}

// ReInit will initialize the context
//
// Used only by tests
func (g *GlobalContext) ReInit() error {
profiles, err := InitProfiles()
if err != nil {
return errors.Wrap(err, "failed to initialize profiles")
}

installations, err := InitInstallations()
if err != nil {
return errors.Wrap(err, "failed to initialize installations")
}

g.Installations = installations
g.Profiles = profiles

return g.Save()
}

// Wipe will remove any trace of ficsit anywhere
func (g *GlobalContext) Wipe() error {
// Wipe all installations
Expand Down
6 changes: 6 additions & 0 deletions cli/installations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func TestAddInstallation(t *testing.T) {
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"
Expand Down
11 changes: 11 additions & 0 deletions cli/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ var platforms = []Platform{
LockfilePath: filepath.Join("FactoryGame", "Mods"),
TargetName: "Windows",
},
// Update 9 stuff below
{
VersionPath: filepath.Join("Engine", "Binaries", "Linux", "FactoryServer-Linux-Shipping.version"),
LockfilePath: filepath.Join("FactoryGame", "Mods"),
TargetName: "LinuxServer",
},
{
VersionPath: filepath.Join("Engine", "Binaries", "Win64", "FactoryServer-Win64-Shipping.version"),
LockfilePath: filepath.Join("FactoryGame", "Mods"),
TargetName: "WindowsServer",
},
}
57 changes: 54 additions & 3 deletions cli/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"time"

"github.com/satisfactorymodding/ficsit-cli/cli/provider"
"github.com/satisfactorymodding/ficsit-cli/ficsit"
Expand All @@ -11,13 +12,63 @@ var _ provider.Provider = (*MockProvider)(nil)

type MockProvider struct{}

func (m MockProvider) Mods(_ context.Context, _ ficsit.ModFilter) (*ficsit.ModsResponse, error) {
// Currently used only by TUI
return nil, nil
func (m MockProvider) Mods(_ context.Context, f ficsit.ModFilter) (*ficsit.ModsResponse, error) {
if f.Offset > 0 {
return &ficsit.ModsResponse{
Mods: ficsit.ModsModsGetMods{
Count: 5,
Mods: []ficsit.ModsModsGetModsModsMod{},
},
}, nil
}

return &ficsit.ModsResponse{
Mods: ficsit.ModsModsGetMods{
Count: 5,
Mods: []ficsit.ModsModsGetModsModsMod{
{
Id: "9LguyCdDUrpT9N",
Name: "Ficsit Remote Monitoring",
Mod_reference: "FicsitRemoteMonitoring",
Last_version_date: time.Now(),
Created_at: time.Now(),
},
{
Id: "DGiLzB3ZErWu2V",
Name: "Refined Power",
Mod_reference: "RefinedPower",
Last_version_date: time.Now(),
Created_at: time.Now(),
},
{
Id: "B24emzbs6xVZQr",
Name: "RefinedRDLib",
Mod_reference: "RefinedRDLib",
Last_version_date: time.Now(),
Created_at: time.Now(),
},
{
Id: "6vQ6ckVYFiidDh",
Name: "Area Actions",
Mod_reference: "AreaActions",
Last_version_date: time.Now(),
Created_at: time.Now(),
},
{
Id: "As2uJmQLLxjXLG",
Name: "ModularUI",
Mod_reference: "ModularUI",
Last_version_date: time.Now(),
Created_at: time.Now(),
},
},
},
}, nil
}

func (m MockProvider) GetMod(_ context.Context, _ string) (*ficsit.GetModResponse, error) {
// Currently used only by TUI
panic("HELLO")
return nil, nil

Check failure on line 72 in cli/test_helpers.go

View workflow job for this annotation

GitHub Actions / Lint

unreachable: unreachable code (govet)

Check failure on line 72 in cli/test_helpers.go

View workflow job for this annotation

GitHub Actions / Lint

unreachable: unreachable code (govet)
}

Expand Down
92 changes: 48 additions & 44 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ module github.com/satisfactorymodding/ficsit-cli
go 1.21

require (
github.com/JohannesKaufmann/html-to-markdown v1.3.6
github.com/Khan/genqlient v0.5.0
github.com/JohannesKaufmann/html-to-markdown v1.4.2
github.com/Khan/genqlient v0.6.0
github.com/MarvinJWendt/testza v0.5.2
github.com/Masterminds/semver/v3 v3.2.1
github.com/PuerkitoBio/goquery v1.8.0
github.com/charmbracelet/bubbles v0.14.0
github.com/charmbracelet/bubbletea v0.22.1
github.com/charmbracelet/glamour v0.5.0
github.com/charmbracelet/lipgloss v0.6.0
github.com/jlaffaye/ftp v0.1.0
github.com/PuerkitoBio/goquery v1.8.1
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.9.1
github.com/charmbracelet/x/exp/teatest v0.0.0-20231206171822-6e7b9b308fe7
github.com/jlaffaye/ftp v0.2.0
github.com/mircearoata/pubgrub-go v0.3.3
github.com/muesli/reflow v0.3.0
github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.67
github.com/pterm/pterm v0.12.71
github.com/puzpuzpuz/xsync/v3 v3.0.2
github.com/rs/zerolog v1.28.0
github.com/rs/zerolog v1.31.0
github.com/sahilm/fuzzy v0.1.0
github.com/spf13/cobra v1.6.0
github.com/spf13/viper v1.13.0
golang.org/x/sync v0.1.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.0
golang.org/x/sync v0.5.0
)

require (
Expand All @@ -34,56 +34,60 @@ require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/alexflint/go-arg v1.4.3 // indirect
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52 v1.2.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymanbagabas/go-udiff v0.1.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.13.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/vektah/gqlparser/v2 v2.5.10 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.6.0 // indirect
github.com/yuin/goldmark v1.6.0 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 8e1942d

Please sign in to comment.