MCPcopy
hub / github.com/cheat/cheat / TestValidatePathsNix

Function TestValidatePathsNix

internal/config/paths_test.go:14–60  ·  view source on GitHub ↗

TestValidatePathsNix asserts that the proper config paths are returned on *nix platforms

(t *testing.T)

Source from the content-addressed store, hash-verified

12// TestValidatePathsNix asserts that the proper config paths are returned on
13// *nix platforms
14func TestValidatePathsNix(t *testing.T) {
15 if runtime.GOOS == "windows" {
16 t.Skip("filepath.Join uses backslashes on Windows")
17 }
18
19 // mock the user's home directory
20 home := "/home/foo"
21
22 // mock some envvars
23 envvars := map[string]string{
24 "XDG_CONFIG_HOME": "/home/bar",
25 }
26
27 // specify the platforms to test
28 oses := []string{
29 "android",
30 "darwin",
31 "freebsd",
32 "linux",
33 }
34
35 // test each *nix os
36 for _, os := range oses {
37 // get the paths for the platform
38 paths, err := Paths(os, home, envvars)
39 if err != nil {
40 t.Errorf("paths returned an error: %v", err)
41 }
42
43 // specify the expected output
44 want := []string{
45 "/home/bar/cheat/conf.yml",
46 "/home/foo/.config/cheat/conf.yml",
47 "/home/foo/.cheat/conf.yml",
48 "/etc/cheat/conf.yml",
49 }
50
51 // assert that output matches expectations
52 if !reflect.DeepEqual(paths, want) {
53 t.Errorf(
54 "failed to return expected paths: want:\n%s, got:\n%s",
55 spew.Sdump(want),
56 spew.Sdump(paths),
57 )
58 }
59 }
60}
61
62// TestValidatePathsNixNoXDG asserts that the proper config paths are returned
63// on *nix platforms when `XDG_CONFIG_HOME is not set

Callers

nothing calls this directly

Calls 1

PathsFunction · 0.70

Tested by

no test coverage detected