MCPcopy
hub / github.com/perkeep/perkeep / TestReadFileFromRoot

Function TestReadFileFromRoot

pkg/fs/fs_test.go:186–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

184}
185
186func TestReadFileFromRoot(t *testing.T) {
187 condSkip(t)
188 pkmountTest(t, func(env *mountEnv) {
189 // pk-put a file
190 tmpFile, err := os.CreateTemp(t.TempDir(), "camlitest")
191 if err != nil {
192 t.Fatal(err)
193 }
194 testContent := "some test content"
195 tmpFile.WriteString(testContent)
196 blobRef := env.world.PutFile(t, tmpFile.Name())
197
198 // Read it using the file's blobref
199 if contents, err := os.ReadFile(filepath.Join(env.mountPoint, blobRef.String())); err != nil {
200 t.Fatal(err)
201 } else if got := string(contents); got != testContent {
202 t.Fatalf("Expected test content, got %q", got)
203 }
204
205 // Read a non-existing blobref, should return NotExist.
206 badRefPath := filepath.Join(env.mountPoint, "sha224-1853501438ffe541dd1e48b9efc4a230f67f7b98afe83df24bfbfa25")
207 if _, err := os.Stat(badRefPath); !os.IsNotExist(err) {
208 t.Fatalf("expected NotExist; got stat err = %v instead", err)
209 }
210 })
211}
212
213func TestTruncateFile(t *testing.T) {
214 condSkip(t)

Callers

nothing calls this directly

Calls 8

condSkipFunction · 0.85
pkmountTestFunction · 0.85
FatalMethod · 0.80
PutFileMethod · 0.80
NameMethod · 0.65
FatalfMethod · 0.65
StatMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected