update tests in utilities
This commit is contained in:
parent
9acf562ccc
commit
b35040aa79
2 changed files with 77 additions and 37 deletions
|
@ -7,34 +7,45 @@ import (
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCalculateMediaCacheDir(t *testing.T) {
|
func TestDirectoryCalculations(t *testing.T) {
|
||||||
t.Parallel()
|
t.Log("Testing the directory calculations")
|
||||||
|
|
||||||
projectDir, err := projectRoot()
|
projectDir, err := projectRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to get the project root directory: %v", err)
|
t.Fatalf("Unable to get the project root directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheRoot := filepath.Join(projectDir, "test", "cache")
|
t.Setenv("XDG_CACHE_HOME", "/home/enbas/.cache")
|
||||||
instance := "http://gotosocial.yellow-desert.social"
|
t.Setenv("XDG_CONFIG_HOME", "/home/enbas/.config")
|
||||||
|
|
||||||
got, err := utilities.CalculateMediaCacheDir(cacheRoot, instance)
|
t.Run("Media Cache Directory Calculation", testCalculateMediaCacheDir(projectDir))
|
||||||
if err != nil {
|
t.Run("Media Cache Directory Calculation (with XDG_CACHE_HOME)", testCalculateMediaCacheDirWithXDG)
|
||||||
t.Fatalf("Unable to calculate the media cache directory: %v", err)
|
t.Run("Statuses Cache Directory Calculation", testCalculateStatusesCacheDir(projectDir))
|
||||||
}
|
t.Run("Configuration Directory Calculation", testCalculateConfigDir(projectDir))
|
||||||
|
t.Run("Configuration Directory Calculation (with XDG_CONFIG_HOME)", testCalculateConfigCacheDirWithXDG)
|
||||||
|
}
|
||||||
|
|
||||||
want := projectDir + "/test/cache/gotosocial.yellow-desert.social/media"
|
func testCalculateMediaCacheDir(projectDir string) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
cacheRoot := filepath.Join(projectDir, "test", "cache")
|
||||||
|
instance := "http://gotosocial.yellow-desert.social"
|
||||||
|
|
||||||
if got != want {
|
got, err := utilities.CalculateMediaCacheDir(cacheRoot, instance)
|
||||||
t.Errorf("Unexpected media cache directory calculated: want %s, got %s", want, got)
|
if err != nil {
|
||||||
} else {
|
t.Fatalf("Unable to calculate the media cache directory: %v", err)
|
||||||
t.Logf("Expected media cache directory calculated: got %s", got)
|
}
|
||||||
|
|
||||||
|
want := projectDir + "/test/cache/gotosocial.yellow-desert.social/media"
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("Unexpected media cache directory calculated: want %s, got %s", want, got)
|
||||||
|
} else {
|
||||||
|
t.Logf("Expected media cache directory calculated: got %s", got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalculateMediaCacheDirWithXDG(t *testing.T) {
|
func testCalculateMediaCacheDirWithXDG(t *testing.T) {
|
||||||
t.Setenv("XDG_CACHE_HOME", "/home/enbas/.cache")
|
|
||||||
|
|
||||||
cacheRoot := ""
|
cacheRoot := ""
|
||||||
instance := "https://gotosocial.yellow-desert.social"
|
instance := "https://gotosocial.yellow-desert.social"
|
||||||
|
|
||||||
|
@ -52,27 +63,58 @@ func TestCalculateMediaCacheDirWithXDG(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalculateStatusesCacheDir(t *testing.T) {
|
func testCalculateStatusesCacheDir(projectDir string) func(t *testing.T) {
|
||||||
t.Parallel()
|
return func(t *testing.T) {
|
||||||
|
cacheRoot := filepath.Join(projectDir, "test", "cache")
|
||||||
|
instance := "https://fedi.blue-mammoth.party"
|
||||||
|
|
||||||
projectDir, err := projectRoot()
|
got, err := utilities.CalculateStatusesCacheDir(cacheRoot, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to get the project root directory: %v", err)
|
t.Fatalf("Unable to calculate the statuses cache directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheRoot := filepath.Join(projectDir, "test", "cache")
|
want := projectDir + "/test/cache/fedi.blue-mammoth.party/statuses"
|
||||||
instance := "https://fedi.blue-mammoth.party"
|
|
||||||
|
|
||||||
got, err := utilities.CalculateStatusesCacheDir(cacheRoot, instance)
|
if got != want {
|
||||||
if err != nil {
|
t.Errorf("Unexpected statuses cache directory calculated: want %s, got %s", want, got)
|
||||||
t.Fatalf("Unable to calculate the statuses cache directory: %v", err)
|
} else {
|
||||||
}
|
t.Logf("Expected statuses cache directory calculated: got %s", got)
|
||||||
|
}
|
||||||
want := projectDir + "/test/cache/fedi.blue-mammoth.party/statuses"
|
}
|
||||||
|
}
|
||||||
if got != want {
|
|
||||||
t.Errorf("Unexpected statuses cache directory calculated: want %s, got %s", want, got)
|
func testCalculateConfigDir(projectDir string) func(t *testing.T) {
|
||||||
} else {
|
return func(t *testing.T) {
|
||||||
t.Logf("Expected statuses cache directory calculated: got %s", got)
|
configDir := filepath.Join(projectDir, "test", "config")
|
||||||
|
|
||||||
|
got, err := utilities.CalculateConfigDir(configDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to calculate the config directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := projectDir + "/test/config"
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("Unexpected config directory calculated: want %s, got %s", want, got)
|
||||||
|
} else {
|
||||||
|
t.Logf("Expected config directory calculated: got %s", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCalculateConfigCacheDirWithXDG(t *testing.T) {
|
||||||
|
configDir := ""
|
||||||
|
|
||||||
|
got, err := utilities.CalculateConfigDir(configDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to calculate the config directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := "/home/enbas/.config/enbas"
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("Unexpected config directory calculated: want %s, got %s", want, got)
|
||||||
|
} else {
|
||||||
|
t.Logf("Expected config directory calculated: got %s", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetFQDN(t *testing.T) {
|
func TestGetFQDN(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
instance string
|
instance string
|
||||||
want string
|
want string
|
||||||
|
|
Loading…
Reference in a new issue