github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/lsmkv/strategies_set_test.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package lsmkv
    13  
    14  import (
    15  	"testing"
    16  
    17  	"github.com/stretchr/testify/assert"
    18  )
    19  
    20  func TestSetDecoder(t *testing.T) {
    21  	type test struct {
    22  		name string
    23  		in   []value
    24  		out  [][]byte
    25  	}
    26  
    27  	tests := []test{
    28  		{
    29  			name: "single value",
    30  			in: []value{
    31  				{
    32  					value: []byte("foo"),
    33  				},
    34  			},
    35  			out: [][]byte{
    36  				[]byte("foo"),
    37  			},
    38  		},
    39  
    40  		{
    41  			name: "single value with tombstone",
    42  			in: []value{
    43  				{
    44  					value:     []byte("foo"),
    45  					tombstone: true,
    46  				},
    47  			},
    48  			out: [][]byte{},
    49  		},
    50  		{
    51  			name: "single value, then a tombstone added",
    52  			in: []value{
    53  				{
    54  					value: []byte("foo"),
    55  				},
    56  				{
    57  					value:     []byte("foo"),
    58  					tombstone: true,
    59  				},
    60  			},
    61  			out: [][]byte{},
    62  		},
    63  		{
    64  			name: "single value, then a tombstone added, then added again",
    65  			in: []value{
    66  				{
    67  					value: []byte("foo"),
    68  				},
    69  				{
    70  					value:     []byte("foo"),
    71  					tombstone: true,
    72  				},
    73  				{
    74  					value: []byte("foo"),
    75  				},
    76  			},
    77  			out: [][]byte{
    78  				[]byte("foo"),
    79  			},
    80  		},
    81  		{
    82  			name: "one value, repeating",
    83  			in: []value{
    84  				{
    85  					value: []byte("foo"),
    86  				},
    87  				{
    88  					value: []byte("foo"),
    89  				},
    90  			},
    91  			out: [][]byte{
    92  				[]byte("foo"),
    93  			},
    94  		},
    95  		{
    96  			name: "multiple values, some tombstones, ending in everything present",
    97  			in: []value{
    98  				{
    99  					value: []byte("foo"),
   100  				},
   101  				{
   102  					value: []byte("bar"),
   103  				},
   104  				{
   105  					value:     []byte("foo"),
   106  					tombstone: true,
   107  				},
   108  				{
   109  					value:     []byte("foo"),
   110  					tombstone: true,
   111  				},
   112  				{
   113  					value:     []byte("foo"),
   114  					tombstone: true,
   115  				},
   116  				{
   117  					value: []byte("foo"),
   118  				},
   119  				{
   120  					value: []byte("bar"),
   121  				},
   122  				{
   123  					value:     []byte("bar"),
   124  					tombstone: true,
   125  				},
   126  				{
   127  					value: []byte("bar"),
   128  				},
   129  			},
   130  			out: [][]byte{
   131  				[]byte("foo"),
   132  				[]byte("bar"),
   133  			},
   134  		},
   135  		{
   136  			name: "multiple values, some tombstones, ending in everything deleted",
   137  			in: []value{
   138  				{
   139  					value: []byte("foo"),
   140  				},
   141  				{
   142  					value: []byte("bar"),
   143  				},
   144  				{
   145  					value:     []byte("foo"),
   146  					tombstone: true,
   147  				},
   148  				{
   149  					value:     []byte("foo"),
   150  					tombstone: true,
   151  				},
   152  				{
   153  					value:     []byte("foo"),
   154  					tombstone: true,
   155  				},
   156  				{
   157  					value: []byte("foo"),
   158  				},
   159  				{
   160  					value: []byte("bar"),
   161  				},
   162  				{
   163  					value:     []byte("bar"),
   164  					tombstone: true,
   165  				},
   166  				{
   167  					value:     []byte("foo"),
   168  					tombstone: true,
   169  				},
   170  			},
   171  			out: [][]byte{},
   172  		},
   173  	}
   174  
   175  	for _, test := range tests {
   176  		t.Run(test.name, func(t *testing.T) {
   177  			assert.Equal(t, test.out, newSetDecoder().Do(test.in))
   178  		})
   179  	}
   180  }