| 1089 | } |
| 1090 | |
| 1091 | func TestFSets_remove(t *testing.T) { |
| 1092 | tests := []struct { |
| 1093 | name string |
| 1094 | setup *FSets |
| 1095 | members []string |
| 1096 | want []string |
| 1097 | wantErrors error |
| 1098 | }{ |
| 1099 | { |
| 1100 | name: "test when empty Set", |
| 1101 | setup: &FSets{}, |
| 1102 | members: []string{"key1", "key2"}, |
| 1103 | want: []string{}, |
| 1104 | wantErrors: ErrMemberNotFound, |
| 1105 | }, |
| 1106 | { |
| 1107 | name: "test Set with wrong members ", |
| 1108 | setup: &FSets{"non1": struct{}{}, "non2": struct{}{}}, |
| 1109 | want: []string{"non1", "non2"}, |
| 1110 | members: []string{"key1", "key2"}, |
| 1111 | wantErrors: ErrMemberNotFound, |
| 1112 | }, |
| 1113 | { |
| 1114 | name: "test Set with partial members found", // this should not delete the found member neither |
| 1115 | setup: &FSets{"key1": struct{}{}, "non2": struct{}{}}, |
| 1116 | want: []string{"key1", "non2"}, |
| 1117 | members: []string{"key1", "key2"}, |
| 1118 | wantErrors: ErrMemberNotFound, |
| 1119 | }, |
| 1120 | { |
| 1121 | name: "test Set with all members found", |
| 1122 | setup: &FSets{"key1": struct{}{}, "non2": struct{}{}, "key2": struct{}{}}, |
| 1123 | want: []string{"non2"}, |
| 1124 | members: []string{"key1", "key2"}, |
| 1125 | }, |
| 1126 | { |
| 1127 | name: "test Set not initialized", |
| 1128 | want: []string{}, |
| 1129 | members: []string{"key1", "key2"}, |
| 1130 | wantErrors: ErrSetNotInitialized, |
| 1131 | }, |
| 1132 | } |
| 1133 | for _, tt := range tests { |
| 1134 | t.Run(tt.name, func(t *testing.T) { |
| 1135 | |
| 1136 | err := tt.setup.remove(tt.members...) |
| 1137 | assert.Equal(t, tt.wantErrors, err) |
| 1138 | assert.True(t, tt.setup.exists(tt.want...)) |
| 1139 | }) |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | func TestSetStructure_Keys(t *testing.T) { |
| 1144 | set, _ := initTestSetDb() |