MCPcopy
hub / github.com/perkeep/perkeep / TestCamPkConfigMigration

Function TestCamPkConfigMigration

internal/osutil/paths_test.go:131–197  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

129}
130
131func TestCamPkConfigMigration(t *testing.T) {
132 oldFuncs := configDirFuncs
133 defer func() {
134 configDirFuncs = oldFuncs
135 configDirNamedTestHook = nil
136 log.SetOutput(os.Stderr)
137 }()
138 log.SetOutput(io.Discard)
139
140 td := t.TempDir()
141
142 configDirNamedTestHook = func(name string) string {
143 return filepath.Join(td, name)
144 }
145
146 oldDir := filepath.Join(td, "camlistore")
147 newDir := filepath.Join(td, "perkeep")
148
149 if err := os.MkdirAll(filepath.Join(oldDir, "blobs", "foo", "sub"), 0755); err != nil {
150 t.Fatal(err)
151 }
152
153 calls := 0
154 RegisterConfigDirFunc(func() string {
155 calls++
156 log.Printf("call %d", calls)
157 switch calls {
158 case 1:
159 return oldDir
160 case 2:
161 return newDir
162 }
163 t.Fatalf("unexpected %d calls to get config dir", calls)
164 return ""
165 })
166
167 got, err := perkeepConfigDir()
168 if err != nil {
169 t.Fatal(err)
170 }
171 if got != newDir {
172 t.Errorf("first call = %v; want %v", got, newDir)
173 }
174
175 if fi, err := os.Lstat(oldDir); !os.IsNotExist(err) {
176 t.Errorf("Lstat = %v, %v; want IsNotExist error", fi, err)
177 }
178
179 // Now try with some regular file in the old dir.
180 if err := os.MkdirAll(filepath.Join(oldDir, "blobs"), 0755); err != nil {
181 t.Fatal(err)
182 }
183 if err := os.WriteFile(filepath.Join(oldDir, "blobs/x.dat"), []byte("hi"), 0644); err != nil {
184 t.Fatal(err)
185 }
186
187 _, err = perkeepConfigDir()
188 if err == nil {

Callers

nothing calls this directly

Calls 10

RegisterConfigDirFuncFunction · 0.85
perkeepConfigDirFunction · 0.85
FatalMethod · 0.80
PrintfMethod · 0.80
ContainsMethod · 0.80
MkdirAllMethod · 0.65
FatalfMethod · 0.65
LstatMethod · 0.65
IsDirMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected