| 184 | } |
| 185 | |
| 186 | func 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 | |
| 213 | func TestTruncateFile(t *testing.T) { |
| 214 | condSkip(t) |