MCPcopy Index your code
hub / github.com/cheat/cheat / TestCopyDeep

Function TestCopyDeep

internal/sheet/copy_test.go:58–107  ·  view source on GitHub ↗

TestCopyDeep asserts that Copy correctly copies files at several levels of depth

(t *testing.T)

Source from the content-addressed store, hash-verified

56// TestCopyDeep asserts that Copy correctly copies files at several levels of
57// depth
58func TestCopyDeep(t *testing.T) {
59
60 // mock a cheatsheet file
61 text := "this is the cheatsheet text"
62 src, err := os.CreateTemp("", "foo-src")
63 if err != nil {
64 t.Errorf("failed to mock cheatsheet: %v", err)
65 }
66 defer src.Close()
67 defer os.Remove(src.Name())
68
69 if _, err := src.WriteString(text); err != nil {
70 t.Errorf("failed to write to mock cheatsheet: %v", err)
71 }
72
73 // mock a cheatsheet struct
74 sheet, err := New(
75 "/cheat-tests/alpha/bravo/foo",
76 "community",
77 src.Name(),
78 []string{},
79 false,
80 )
81 if err != nil {
82 t.Errorf("failed to init cheatsheet: %v", err)
83 }
84
85 // compute the outfile's path
86 outpath := path.Join(os.TempDir(), sheet.Title)
87 defer os.RemoveAll(path.Join(os.TempDir(), "cheat-tests"))
88
89 // attempt to copy the cheatsheet
90 err = sheet.Copy(outpath)
91 if err != nil {
92 t.Errorf("failed to copy cheatsheet: %v", err)
93 }
94
95 // assert that the destination file contains the correct text
96 got, err := os.ReadFile(outpath)
97 if err != nil {
98 t.Errorf("failed to read destination file: %v", err)
99 }
100 if string(got) != text {
101 t.Errorf(
102 "destination file contained wrong text: want: '%s', got: '%s'",
103 text,
104 got,
105 )
106 }
107}

Callers

nothing calls this directly

Calls 2

CopyMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected