@@ -1022,3 +1022,85 @@ func TestIncByteSlice(t *testing.T) {
1022
1022
}
1023
1023
}
1024
1024
}
1025
+
1026
+ // TestIndex_HasMulti validates that HasMulti returns a correct
1027
+ // slice of booleans for provided Items.
1028
+ func TestIndex_HasMulti (t * testing.T ) {
1029
+ db , cleanupFunc := newTestDB (t )
1030
+ defer cleanupFunc ()
1031
+
1032
+ index , err := db .NewIndex ("retrieval" , retrievalIndexFuncs )
1033
+ if err != nil {
1034
+ t .Fatal (err )
1035
+ }
1036
+
1037
+ items := []Item {
1038
+ {
1039
+ Address : []byte ("hash-01" ),
1040
+ Data : []byte ("data94" ),
1041
+ },
1042
+ {
1043
+ Address : []byte ("hash-03" ),
1044
+ Data : []byte ("data33" ),
1045
+ },
1046
+ {
1047
+ Address : []byte ("hash-05" ),
1048
+ Data : []byte ("data55" ),
1049
+ },
1050
+ {
1051
+ Address : []byte ("hash-02" ),
1052
+ Data : []byte ("data21" ),
1053
+ },
1054
+ {
1055
+ Address : []byte ("hash-06" ),
1056
+ Data : []byte ("data8" ),
1057
+ },
1058
+ }
1059
+ missingItem := Item {
1060
+ Address : []byte ("hash-10" ),
1061
+ Data : []byte ("data0" ),
1062
+ }
1063
+
1064
+ batch := new (leveldb.Batch )
1065
+ for _ , i := range items {
1066
+ index .PutInBatch (batch , i )
1067
+ }
1068
+ err = db .WriteBatch (batch )
1069
+ if err != nil {
1070
+ t .Fatal (err )
1071
+ }
1072
+
1073
+ got , err := index .HasMulti (items [0 ])
1074
+ if err != nil {
1075
+ t .Fatal (err )
1076
+ }
1077
+ if ! got [0 ] {
1078
+ t .Error ("first item not found" )
1079
+ }
1080
+
1081
+ got , err = index .HasMulti (missingItem )
1082
+ if err != nil {
1083
+ t .Fatal (err )
1084
+ }
1085
+ if got [0 ] {
1086
+ t .Error ("missing item found" )
1087
+ }
1088
+
1089
+ got , err = index .HasMulti (items ... )
1090
+ if err != nil {
1091
+ t .Fatal (err )
1092
+ }
1093
+ want := []bool {true , true , true , true , true }
1094
+ if fmt .Sprint (got ) != fmt .Sprint (want ) {
1095
+ t .Errorf ("got %v, want %v" , got , want )
1096
+ }
1097
+
1098
+ got , err = index .HasMulti (append (items , missingItem )... )
1099
+ if err != nil {
1100
+ t .Fatal (err )
1101
+ }
1102
+ want = []bool {true , true , true , true , true , false }
1103
+ if fmt .Sprint (got ) != fmt .Sprint (want ) {
1104
+ t .Errorf ("got %v, want %v" , got , want )
1105
+ }
1106
+ }
0 commit comments