github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/core/meta/bck_test.go (about) 1 // Package meta_test: unit tests for the package 2 /* 3 * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package meta_test 6 7 import ( 8 "github.com/NVIDIA/aistore/api/apc" 9 "github.com/NVIDIA/aistore/cmn" 10 "github.com/NVIDIA/aistore/core/meta" 11 . "github.com/onsi/ginkgo/v2" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Bck", func() { 16 Describe("Uname", func() { 17 DescribeTable("should convert bucket and object name to uname and back", 18 func(bckName, bckProvider string, bckNs cmn.Ns, objName string) { 19 bck := meta.NewBck(bckName, bckProvider, bckNs) 20 uname := bck.MakeUname(objName) 21 22 gotBck, gotObjName := cmn.ParseUname(uname) 23 Expect(gotBck.Name).To(Equal(bckName)) 24 Expect(gotBck.Provider).To(Equal(bckProvider)) 25 Expect(gotBck.Ns).To(Equal(bckNs)) 26 Expect(gotObjName).To(Equal(objName)) 27 }, 28 Entry( 29 "regular ais bucket with simple object name", 30 "bck", apc.AIS, cmn.NsGlobal, "obj", 31 ), 32 Entry( 33 "regular ais bucket with long object name", 34 "bck", apc.AIS, cmn.NsGlobal, "obj/tmp1/tmp2", 35 ), 36 Entry( 37 "non-empty local namespace", 38 "bck", apc.AIS, cmn.Ns{Name: "namespace"}, "obj/tmp1/tmp2", 39 ), 40 Entry( 41 "non-empty cloud namespace", 42 "bck", apc.AIS, cmn.Ns{UUID: "uuid", Name: "namespace"}, "obj/tmp1/tmp2", 43 ), 44 Entry( 45 "aws provider", 46 "bck", apc.AWS, cmn.NsGlobal, "obj", 47 ), 48 Entry( 49 "gcp provider", 50 "bck", apc.GCP, cmn.NsGlobal, "obj", 51 ), 52 Entry( 53 "backend provider", 54 "bck", apc.GCP, cmn.NsGlobal, "obj", 55 ), 56 ) 57 }) 58 59 Describe("Equal", func() { 60 DescribeTable("should not be equal", 61 func(a, b *meta.Bck) { 62 a.Props, b.Props = &cmn.Bprops{}, &cmn.Bprops{} 63 Expect(a.Equal(b, true /*same BID*/, true /* same backend*/)).To(BeFalse()) 64 }, 65 Entry( 66 "not matching names", 67 meta.NewBck("a", apc.AIS, cmn.NsGlobal), 68 meta.NewBck("b", apc.AIS, cmn.NsGlobal), 69 ), 70 Entry( 71 "not matching namespace #1", 72 meta.NewBck("a", apc.AIS, cmn.Ns{UUID: "uuid", Name: "ns1"}), 73 meta.NewBck("a", apc.AIS, cmn.Ns{UUID: "uuid", Name: "ns2"}), 74 ), 75 Entry( 76 "not matching namespace #2", 77 meta.NewBck("a", apc.AIS, cmn.Ns{UUID: "uuid1", Name: "ns"}), 78 meta.NewBck("a", apc.AIS, cmn.Ns{UUID: "uuid2", Name: "ns"}), 79 ), 80 Entry( 81 "not matching providers #2", 82 meta.NewBck("a", apc.AIS, cmn.NsGlobal), 83 meta.NewBck("a", apc.AWS, cmn.NsGlobal), 84 ), 85 Entry( 86 "not matching Backend providers #4", 87 meta.NewBck("a", apc.AWS, cmn.NsGlobal), 88 meta.NewBck("a", apc.GCP, cmn.NsGlobal), 89 ), 90 Entry( 91 "not matching Backend providers #5", 92 meta.NewBck("a", apc.GCP, cmn.NsGlobal), 93 meta.NewBck("a", apc.AWS, cmn.NsGlobal), 94 ), 95 ) 96 97 DescribeTable("should be equal", 98 func(a, b *meta.Bck) { 99 a.Props, b.Props = &cmn.Bprops{}, &cmn.Bprops{} 100 Expect(a.Equal(b, true /*same BID*/, true /* same backend */)).To(BeTrue()) 101 }, 102 Entry( 103 "matching AIS providers", 104 meta.NewBck("a", apc.AIS, cmn.NsGlobal), 105 meta.NewBck("a", apc.AIS, cmn.NsGlobal), 106 ), 107 Entry( 108 "matching local namespaces", 109 meta.NewBck("a", apc.AIS, cmn.Ns{Name: "ns"}), 110 meta.NewBck("a", apc.AIS, cmn.Ns{Name: "ns"}), 111 ), 112 Entry( 113 "matching cloud namespaces", 114 meta.NewBck("a", apc.AIS, cmn.Ns{UUID: "uuid", Name: "ns"}), 115 meta.NewBck("a", apc.AIS, cmn.Ns{UUID: "uuid", Name: "ns"}), 116 ), 117 ) 118 }) 119 })