MCPcopy
hub / github.com/urfave/cli / TestFileValueSource

Function TestFileValueSource

value_source_test.go:76–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestFileValueSource(t *testing.T) {
77 t.Run("implements ValueSource", func(t *testing.T) {
78 r := require.New(t)
79
80 r.Implements((*ValueSource)(nil), &fileValueSource{})
81
82 t.Run("not found", func(t *testing.T) {
83 src := File(fmt.Sprintf("junk_file_name-%[1]v", rand.Int()))
84 _, ok := src.Lookup()
85 r.False(ok)
86 })
87
88 fileName := filepath.Join(os.TempDir(), fmt.Sprintf("urfave-cli-testing-existing_file-%[1]v", rand.Int()))
89 t.Cleanup(func() { _ = os.Remove(fileName) })
90
91 r.Nil(os.WriteFile(fileName, []byte("pita"), 0o644))
92
93 t.Run("found", func(t *testing.T) {
94 src := File(fileName)
95 str, ok := src.Lookup()
96 r.True(ok)
97 r.Equal("pita", str)
98 })
99 })
100
101 t.Run("implements fmt.Stringer", func(t *testing.T) {
102 src := File("/dev/null")
103 r := require.New(t)
104
105 r.Implements((*ValueSource)(nil), src)
106 r.Equal("file \"/dev/null\"", src.String())
107 })
108
109 t.Run("implements fmt.GoStringer", func(t *testing.T) {
110 src := File("/dev/null")
111 r := require.New(t)
112
113 r.Implements((*ValueSource)(nil), src)
114 r.Equal("&fileValueSource{Path:\"/dev/null\"}", src.GoString())
115 })
116}
117
118func TestFilePaths(t *testing.T) {
119 r := require.New(t)

Callers

nothing calls this directly

Calls 6

FileFunction · 0.85
IntMethod · 0.80
LookupMethod · 0.65
RunMethod · 0.45
StringMethod · 0.45
GoStringMethod · 0.45

Tested by

no test coverage detected