github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/caveats/types/map_test.go (about)

     1  package types
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestMapSubtree(t *testing.T) {
    10  	tcs := []struct {
    11  		map1    map[string]any
    12  		map2    map[string]any
    13  		subtree bool
    14  	}{
    15  		{
    16  			map[string]any{"a": 1},
    17  			map[string]any{"a": 1},
    18  			true,
    19  		},
    20  		{
    21  			map[string]any{"a": 1, "b": 2},
    22  			map[string]any{"a": 1},
    23  			false,
    24  		},
    25  		{
    26  			map[string]any{"a": 1},
    27  			map[string]any{"a": 1, "b": 1},
    28  			true,
    29  		},
    30  		{
    31  			map[string]any{"a": 1, "b": map[string]any{"a": 1}},
    32  			map[string]any{"a": 1},
    33  			false,
    34  		},
    35  		{
    36  			map[string]any{"a": 1, "b": map[string]any{"a": 1}},
    37  			map[string]any{"a": 1, "b": map[string]any{"a": 1}},
    38  			true,
    39  		},
    40  		{
    41  			map[string]any{"a": 1, "b": map[string]any{"a": 1}},
    42  			map[string]any{"a": 1, "b": map[string]any{"a": 1, "b": 1}},
    43  			true,
    44  		},
    45  		{
    46  			map[string]any{"a": 1, "b": map[string]any{"a": 1}},
    47  			map[string]any{"a": 1, "b": map[string]any{"a": "1", "b": 1}},
    48  			false,
    49  		},
    50  		{
    51  			map[string]any{"a": 1, "b": map[string]any{"a": 1}},
    52  			map[string]any{"a": 1, "b": map[string]any{"a": 1, "b": map[string]any{}}},
    53  			true,
    54  		},
    55  	}
    56  	for _, tt := range tcs {
    57  		tt := tt
    58  		t.Run("", func(t *testing.T) {
    59  			require.Equal(t, tt.subtree, subtree(tt.map1, tt.map2))
    60  		})
    61  	}
    62  }