MCPcopy
hub / github.com/dnote/dnote / TestMigrateToV1

Function TestMigrateToV1

pkg/cli/migrate/legacy_test.go:54–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestMigrateToV1(t *testing.T) {
55 t.Run("yaml exists", func(t *testing.T) {
56 // set up
57 ctx := setupEnv(t, "../tmp")
58 defer teardownEnv(t, ctx)
59
60 yamlPath, err := filepath.Abs(filepath.Join(ctx.Paths.Home, ".dnote-yaml-archived"))
61 if err != nil {
62 panic(errors.Wrap(err, "Failed to get absolute YAML path").Error())
63 }
64 os.WriteFile(yamlPath, []byte{}, 0644)
65
66 // execute
67 if err := migrateToV1(ctx); err != nil {
68 t.Fatal(errors.Wrapf(err, "Failed to migrate").Error())
69 }
70
71 // test
72 ok, err := utils.FileExists(yamlPath)
73 if err != nil {
74 t.Fatal(errors.Wrap(err, "checking if yaml file exists"))
75 }
76 if ok {
77 t.Fatal("YAML archive file has not been deleted")
78 }
79 })
80
81 t.Run("yaml does not exist", func(t *testing.T) {
82 // set up
83 ctx := setupEnv(t, "../tmp")
84 defer teardownEnv(t, ctx)
85
86 yamlPath, err := filepath.Abs(filepath.Join(ctx.Paths.Home, ".dnote-yaml-archived"))
87 if err != nil {
88 panic(errors.Wrap(err, "Failed to get absolute YAML path").Error())
89 }
90
91 // execute
92 if err := migrateToV1(ctx); err != nil {
93 t.Fatal(errors.Wrapf(err, "Failed to migrate").Error())
94 }
95
96 // test
97 ok, err := utils.FileExists(yamlPath)
98 if err != nil {
99 t.Fatal(errors.Wrap(err, "checking if yaml file exists"))
100 }
101 if ok {
102 t.Fatal("YAML archive file must not exist")
103 }
104 })
105}
106
107func TestMigrateToV2(t *testing.T) {
108 ctx := setupEnv(t, "../tmp")

Callers

nothing calls this directly

Calls 5

FileExistsFunction · 0.92
setupEnvFunction · 0.85
teardownEnvFunction · 0.85
migrateToV1Function · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected