Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
chore: add config tests (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
bketelsen authored Sep 25, 2023
1 parent 49f6a53 commit f4494bb
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/fleek/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -328,6 +329,7 @@ func (c *Config) UniqueSystems() []string {
systems = append(systems, syskey)
m[syskey] = true
}
sort.Strings(systems)
return systems

}
Expand Down
108 changes: 108 additions & 0 deletions internal/fleek/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package fleek

import (
"os"
"path/filepath"
"testing"

"github.com/ublue-os/fleek/internal/xdg"
)

func TestHostname(t *testing.T) {
h, err := Hostname()
if err != nil {
t.Error(err)
}
overrideHost := "fleekhost"
os.Setenv("FLEEK_HOST_OVERRIDE", overrideHost)
hOverride, err := Hostname()
if err != nil {
t.Error(err)
}
if h == hOverride {
t.Fatalf("host override: expected %s got %s", overrideHost, hOverride)
}
}

func TestUniqueSystems(t *testing.T) {
c := &Config{
Systems: []*System{
{
Arch: "x86-64",
OS: "darwin",
},
},
}
want := "x86-64-darwin"
got := c.UniqueSystems()
if got[0] != want {
t.Fatalf("unique systems: expected %s got %s", want, got)
}
c = &Config{
Systems: []*System{
{
Arch: "x86-64",
OS: "darwin",
},
{
Arch: "aarch64",
OS: "linux",
},
},
}
want = "aarch64-linux"
got = c.UniqueSystems()
if got[0] != want {
t.Fatalf("unique systems: expected %s got %s", want, got)
}
c = &Config{
Systems: []*System{
{
Hostname: "a",
Arch: "x86-64",
OS: "darwin",
},
{
Hostname: "b",
Arch: "aarch64",
OS: "linux",
},
{
Hostname: "c",
Arch: "aarch64",
OS: "darwin",
},
{
Hostname: "d",
Arch: "aarch64",
OS: "darwin",
},
},
}
wantCount := 3
got = c.UniqueSystems()
if len(got) != wantCount {
t.Fatalf("unique systems count: expected %d got %d", wantCount, len(got))
}
}
func TestUserFlakeDir(t *testing.T) {
c := &Config{}
home, _ := os.UserHomeDir()

blankFlakeDir := c.UserFlakeDir()
want := filepath.Join(home, xdg.DataSubpathRel("fleek"))

if blankFlakeDir != want {
t.Fatalf("user flake dir: expected %s, got %s", want, blankFlakeDir)
}
want = filepath.Join(home, ".config", "fleek", "flake")

c = &Config{
FlakeDir: ".config/fleek/flake",
}
manualFlakeDir := c.UserFlakeDir()
if manualFlakeDir != want {
t.Fatalf("manual user flake dir: expected %s, got %s", want, manualFlakeDir)
}

}

0 comments on commit f4494bb

Please sign in to comment.