SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
Adding unit tests for volume ttl.
Chris Lu7920b4685e41
diff --git a/go/storage/needle.go b/go/storage/needle.goindex 3bf6271419..51079376af 100644--- a/go/storage/needle.go+++ b/go/storage/needle.go@@ -118,7 +118,7 @@ func NewNeedle(r *http.Request, fixJpgOrientation bool) (n *Needle, e error) {n.LastModified = uint64(time.Now().Unix())}n.SetHasLastModifiedDate()- if n.Ttl != nil {+ if n.Ttl != EMPTY_TTL {n.SetHasTtl()}diff --git a/go/storage/volume_ttl.go b/go/storage/volume_ttl.goindex 5ff43e24e3..459ee55bae 100644--- a/go/storage/volume_ttl.go+++ b/go/storage/volume_ttl.go@@ -4,10 +4,6 @@ import ("strconv")-var (- TtlRange []uint16-)-const (//stored unit typesEmpty byte = iota@@ -19,14 +15,6 @@ const (Year)-func init() {- TtlRange = []uint16{3, 10, 30,- 60 /*1 hour*/, 60 * 3, 60 * 6, 60 * 12,- 1440 /*1 day*/, 1440 * 3, 1440 * 7, 1440 * 15, 1440 * 31,- 44888 /*1 month*/, 65535,- }-}-type TTL struct {count byteunit byte@@ -120,7 +108,7 @@ func toStoredByte(readableUnitByte byte) byte {return Weekcase 'M':return Month- case 'Y':+ case 'y':return Year}return 0@@ -141,7 +129,7 @@ func (t TTL) Minutes() uint32 {case Month:return uint32(t.count) * 60 * 24 * 31case Year:- return uint32(t.count) * 60 * 24 * 31 * 365+ return uint32(t.count) * 60 * 24 * 365}return 0}diff --git a/go/storage/volume_ttl_test.go b/go/storage/volume_ttl_test.gonew file mode 100644index 0000000000..216469a4c1--- /dev/null+++ b/go/storage/volume_ttl_test.go@@ -0,0 +1,60 @@+package storage++import (+ "testing"+)++func TestTTLReadWrite(t *testing.T) {+ ttl, _ := ReadTTL("")+ if ttl.Minutes() != 0 {+ t.Errorf("empty ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("9")+ if ttl.Minutes() != 9 {+ t.Errorf("9 ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("8m")+ if ttl.Minutes() != 8 {+ t.Errorf("8m ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("5h")+ if ttl.Minutes() != 300 {+ t.Errorf("5h ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("5d")+ if ttl.Minutes() != 5*24*60 {+ t.Errorf("5d ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("5w")+ if ttl.Minutes() != 5*7*24*60 {+ t.Errorf("5w ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("5M")+ if ttl.Minutes() != 5*31*24*60 {+ t.Errorf("5M ttl:%v", ttl)+ }++ ttl, _ = ReadTTL("5y")+ if ttl.Minutes() != 5*365*24*60 {+ t.Errorf("5y ttl:%v", ttl)+ }++ output := make([]byte, 2)+ ttl.ToBytes(output)+ ttl2 := LoadTTLFromBytes(output)+ if ttl.Minutes() != ttl2.Minutes() {+ t.Errorf("ttl:%v ttl2:%v", ttl, ttl2)+ }++ ttl3 := LoadTTLFromUint32(ttl.ToUint32())+ if ttl.Minutes() != ttl3.Minutes() {+ t.Errorf("ttl:%v ttl3:%v", ttl, ttl3)+ }++}