package cfg_test
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
"git.sr.ht/~hristoast/wem/cfg"
)
func TestCfg(t *testing.T) {
// Setup
dir, err := ioutil.TempDir("", "wemTestCfg")
if err != nil {
log.Fatal(err)
}
os.Setenv("HOME", dir)
t.Run("ApplyArgs: cacheDir", func(t *testing.T) {
c, _ := cfg.GetConfig()
c.ApplyArgs("applied!", c.ProtonDir, c.WineBuildDir, c.WineEnvDir, c.WineSrcDir)
if c.CacheDir != "applied!" {
t.Errorf("got: %s; want: %s", c.CacheDir, "applied!")
}
})
t.Run("ApplyArgs: protonDir", func(t *testing.T) {
c, _ := cfg.GetConfig()
c.ApplyArgs(c.CacheDir, "applied!", c.WineBuildDir, c.WineEnvDir, c.WineSrcDir)
if c.ProtonDir != "applied!" {
t.Errorf("got: %s; want: %s", c.ProtonDir, "applied!")
}
})
t.Run("ApplyArgs: wineBuildDir", func(t *testing.T) {
c, _ := cfg.GetConfig()
c.ApplyArgs(c.CacheDir, c.ProtonDir, "applied!", c.WineEnvDir, c.WineSrcDir)
if c.WineBuildDir != "applied!" {
t.Errorf("got: %s; want: %s", c.WineBuildDir, "applied!")
}
})
t.Run("ApplyArgs: wineEnvDir", func(t *testing.T) {
c, _ := cfg.GetConfig()
c.ApplyArgs(c.CacheDir, c.ProtonDir, c.WineBuildDir, "applied!", c.WineSrcDir)
if c.WineEnvDir != "applied!" {
t.Errorf("got: %s; want: %s", c.WineEnvDir, "applied!")
}
})
t.Run("ApplyArgs: wineSrcDir", func(t *testing.T) {
c, _ := cfg.GetConfig()
c.ApplyArgs(c.CacheDir, c.ProtonDir, c.WineBuildDir, c.WineEnvDir, "applied!")
if c.WineSrcDir != "applied!" {
t.Errorf("got: %s; want: %s", c.WineSrcDir, "applied!")
}
})
t.Run("Validate", func(t *testing.T) {
c, _ := cfg.GetConfig()
validate := c.Validate()
if validate != nil {
t.Errorf("got: %v; want: %v", validate, nil)
}
})
t.Run("CfgDir", func(t *testing.T) {
cfgDir := cfg.CfgDir()
expected := filepath.Join(dir, ".config", "wem")
if cfgDir != expected {
t.Errorf("got: %s; want: %s", cfgDir, expected)
}
})
os.RemoveAll(dir)
}