MCPcopy
hub / github.com/cheat/cheat / TestValidatePathsNixNoXDG

Function TestValidatePathsNixNoXDG

internal/config/paths_test.go:64–106  ·  view source on GitHub ↗

TestValidatePathsNixNoXDG asserts that the proper config paths are returned on *nix platforms when `XDG_CONFIG_HOME is not set

(t *testing.T)

Source from the content-addressed store, hash-verified

62// TestValidatePathsNixNoXDG asserts that the proper config paths are returned
63// on *nix platforms when `XDG_CONFIG_HOME is not set
64func TestValidatePathsNixNoXDG(t *testing.T) {
65 if runtime.GOOS == "windows" {
66 t.Skip("filepath.Join uses backslashes on Windows")
67 }
68
69 // mock the user's home directory
70 home := "/home/foo"
71
72 // mock some envvars
73 envvars := map[string]string{}
74
75 // specify the platforms to test
76 oses := []string{
77 "darwin",
78 "freebsd",
79 "linux",
80 }
81
82 // test each *nix os
83 for _, os := range oses {
84 // get the paths for the platform
85 paths, err := Paths(os, home, envvars)
86 if err != nil {
87 t.Errorf("paths returned an error: %v", err)
88 }
89
90 // specify the expected output
91 want := []string{
92 "/home/foo/.config/cheat/conf.yml",
93 "/home/foo/.cheat/conf.yml",
94 "/etc/cheat/conf.yml",
95 }
96
97 // assert that output matches expectations
98 if !reflect.DeepEqual(paths, want) {
99 t.Errorf(
100 "failed to return expected paths: want:\n%s, got:\n%s",
101 spew.Sdump(want),
102 spew.Sdump(paths),
103 )
104 }
105 }
106}
107
108// TestValidatePathsWindows asserts that the proper config paths are returned
109// on Windows platforms

Callers

nothing calls this directly

Calls 1

PathsFunction · 0.70

Tested by

no test coverage detected