149 lines
2.7 KiB
Go
Raw Normal View History

2025-12-24 16:44:53 +04:00
package storage
2025-10-08 13:07:59 +02:00
import "testing"
func TestManifests(t *testing.T) {
2025-12-24 16:44:53 +04:00
storage := newStorageNode(t)
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
manifests, err := storage.Manifests()
2025-10-08 13:07:59 +02:00
if err != nil {
t.Fatal(err)
}
if len(manifests) != 0 {
t.Fatal("expected manifests to be empty")
}
2025-12-24 16:44:53 +04:00
cid, _ := uploadHelper(t, storage)
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
manifests, err = storage.Manifests()
2025-10-08 13:07:59 +02:00
if err != nil {
t.Fatal(err)
}
if len(manifests) == 0 {
t.Fatal("expected manifests to be non-empty")
}
for _, m := range manifests {
if m.Cid != cid {
t.Errorf("expected cid %q, got %q", cid, m.Cid)
}
}
}
func TestSpace(t *testing.T) {
2025-12-24 16:44:53 +04:00
storage := newStorageNode(t)
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
space, err := storage.Space()
2025-10-08 13:07:59 +02:00
if err != nil {
t.Fatal(err)
}
if space.TotalBlocks != 0 {
t.Fatal("expected total blocks to be non-zero")
}
if space.QuotaMaxBytes == 0 {
t.Fatal("expected quota max bytes to be non-zero")
}
if space.QuotaUsedBytes != 0 {
t.Fatal("expected quota used bytes to be non-zero")
}
if space.QuotaReservedBytes != 0 {
t.Fatal("expected quota reserved bytes to be non-zero")
}
2025-12-24 16:44:53 +04:00
uploadHelper(t, storage)
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
space, err = storage.Space()
2025-10-08 13:07:59 +02:00
if err != nil {
t.Fatal(err)
}
if space.TotalBlocks == 0 {
t.Fatal("expected total blocks to be non-zero after upload")
}
if space.QuotaUsedBytes == 0 {
t.Fatal("expected quota used bytes to be non-zero after upload")
}
}
func TestFetch(t *testing.T) {
2025-12-24 16:44:53 +04:00
storage := newStorageNode(t)
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
cid, _ := uploadHelper(t, storage)
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
_, err := storage.Fetch(cid)
2025-10-08 13:07:59 +02:00
if err != nil {
t.Fatal("expected error when fetching non-existent manifest")
}
}
func TestFetchCidDoesNotExist(t *testing.T) {
2025-12-24 16:44:53 +04:00
storage := newStorageNode(t, Config{BlockRetries: 1})
2025-10-08 13:07:59 +02:00
2025-12-24 16:44:53 +04:00
_, err := storage.Fetch("bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku")
2025-10-08 13:07:59 +02:00
if err == nil {
t.Fatal("expected error when fetching non-existent manifest")
}
}
2025-10-09 05:30:19 +02:00
func TestDelete(t *testing.T) {
2025-12-24 16:44:53 +04:00
storage := newStorageNode(t)
2025-10-09 05:30:19 +02:00
2025-12-24 16:44:53 +04:00
cid, _ := uploadHelper(t, storage)
2025-10-09 05:30:19 +02:00
2025-12-24 16:44:53 +04:00
manifests, err := storage.Manifests()
2025-10-09 05:30:19 +02:00
if err != nil {
t.Fatal(err)
}
if len(manifests) != 1 {
t.Fatal("expected manifests to be empty after deletion")
}
2025-12-24 16:44:53 +04:00
err = storage.Delete(cid)
2025-10-09 05:30:19 +02:00
if err != nil {
t.Fatal(err)
}
2025-12-24 16:44:53 +04:00
manifests, err = storage.Manifests()
2025-10-09 05:30:19 +02:00
if err != nil {
t.Fatal(err)
}
if len(manifests) != 0 {
t.Fatal("expected manifests to be empty after deletion")
}
}
2025-11-02 17:20:59 +01:00
func TestExists(t *testing.T) {
2025-12-24 16:44:53 +04:00
storage := newStorageNode(t)
2025-11-02 17:20:59 +01:00
2025-12-24 16:44:53 +04:00
cid, _ := uploadHelper(t, storage)
2025-11-02 17:20:59 +01:00
2025-12-24 16:44:53 +04:00
exists, err := storage.Exists(cid)
2025-11-02 17:20:59 +01:00
if err != nil {
t.Fatal(err)
}
if !exists {
t.Fatal("expected cid to exist")
}
2025-12-24 16:44:53 +04:00
err = storage.Delete(cid)
2025-11-02 17:20:59 +01:00
if err != nil {
t.Fatal(err)
}
2025-12-24 16:44:53 +04:00
exists, err = storage.Exists(cid)
2025-11-02 17:20:59 +01:00
if err != nil {
t.Fatal(err)
}
if exists {
t.Fatal("expected cid to not exist after deletion")
}
}