MCPcopy Index your code
hub / github.com/dnote/dnote / TestGetTmpContentPath

Function TestGetTmpContentPath

pkg/cli/ui/editor_test.go:28–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestGetTmpContentPath(t *testing.T) {
29 t.Run("no collision", func(t *testing.T) {
30 ctx := context.InitTestCtx(t)
31
32 res, err := GetTmpContentPath(ctx)
33 if err != nil {
34 t.Fatal(errors.Wrap(err, "executing"))
35 }
36
37 expected := fmt.Sprintf("%s/%s", ctx.Paths.Cache, "DNOTE_TMPCONTENT_0.md")
38 assert.Equal(t, res, expected, "filename did not match")
39 })
40
41 t.Run("one existing session", func(t *testing.T) {
42 // set up
43 ctx := context.InitTestCtx(t)
44
45 p := fmt.Sprintf("%s/%s", ctx.Paths.Cache, "DNOTE_TMPCONTENT_0.md")
46 if _, err := os.Create(p); err != nil {
47 t.Fatal(errors.Wrap(err, "preparing the conflicting file"))
48 }
49
50 // execute
51 res, err := GetTmpContentPath(ctx)
52 if err != nil {
53 t.Fatal(errors.Wrap(err, "executing"))
54 }
55
56 // test
57 expected := fmt.Sprintf("%s/%s", ctx.Paths.Cache, "DNOTE_TMPCONTENT_1.md")
58 assert.Equal(t, res, expected, "filename did not match")
59 })
60
61 t.Run("two existing sessions", func(t *testing.T) {
62 // set up
63 ctx := context.InitTestCtx(t)
64
65 p1 := fmt.Sprintf("%s/%s", ctx.Paths.Cache, "DNOTE_TMPCONTENT_0.md")
66 if _, err := os.Create(p1); err != nil {
67 t.Fatal(errors.Wrap(err, "preparing the conflicting file"))
68 }
69 p2 := fmt.Sprintf("%s/%s", ctx.Paths.Cache, "DNOTE_TMPCONTENT_1.md")
70 if _, err := os.Create(p2); err != nil {
71 t.Fatal(errors.Wrap(err, "preparing the conflicting file"))
72 }
73
74 // execute
75 res, err := GetTmpContentPath(ctx)
76 if err != nil {
77 t.Fatal(errors.Wrap(err, "executing"))
78 }
79
80 // test
81 expected := fmt.Sprintf("%s/%s", ctx.Paths.Cache, "DNOTE_TMPCONTENT_2.md")
82 assert.Equal(t, res, expected, "filename did not match")
83 })
84}

Callers

nothing calls this directly

Calls 4

InitTestCtxFunction · 0.92
EqualFunction · 0.92
GetTmpContentPathFunction · 0.85
CreateMethod · 0.80

Tested by

no test coverage detected