File: app_darwin_test.go

package info (click to toggle)
golang-github-apparentlymart-go-userdirs 0.0~git20200915.b0c018a-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: makefile: 2
file content (73 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// +build darwin

package userdirs

import (
	"os"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestForAppDarwin(t *testing.T) {
	tests := map[string]struct {
		env  map[string]string
		want Dirs
	}{
		"defaults": {
			map[string]string{
				"HOME":            "/Users/placeholder",
			},
			Dirs{
				ConfigDirs: []string{
					"/Users/placeholder/Library/Application Support/com.example.splines",
				},
				DataDirs: []string{
					"/Users/placeholder/Library/Application Support/com.example.splines",
					"/Library/Application Support/com.example.splines",
				},
				CacheDir: "/Users/placeholder/Library/Caches/com.example.splines",
			},
		},
	}

	for name, test := range tests {
		t.Run(name, func(t *testing.T) {
			defer testTempEnvMany(test.env)()
			got := ForApp("Spline Reticulator", "Acme Corp", "com.example.splines")

			if diff := cmp.Diff(test.want, got); diff != "" {
				t.Errorf("wrong result\n%s", diff)
			}
		})
	}
}

func TestForAppDarwinNoEnv(t *testing.T) {
	// This test deals with the situation where no environment variables are
	// set at all, including $HOME. In that case the results will vary depending
	// on where we are running, so we'll run this one only inside the Travis-CI
	// test runs so we can depend on its execution environment.
	if travisEnv := os.Getenv("TRAVIS"); travisEnv == "" {
		t.Skipf("No-environment tests run only in Travis-CI")
	}

	defer testTempEnvMany(map[string]string{
		"HOME":            "",
	})()

	got := ForApp("Spline Reticulator", "Acme Corp", "com.example.splines")
	want := Dirs{
		ConfigDirs: []string{
			"/Users/travis/Library/Application Support/com.example.splines",
		},
		DataDirs: []string{
			"/Users/travis/Library/Application Support/com.example.splines",
			"/Library/Application Support/com.example.splines",
		},
		CacheDir: "/Users/travis/Library/Caches/com.example.splines",
	}
	if diff := cmp.Diff(want, got); diff != "" {
		t.Errorf("wrong result\n%s", diff)
	}
}