Files

45 lines
1.5 KiB
Go

package holder
import (
"sort"
"strings"
"testing"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// A-31: the keys of the older form (`seat.<seat>.<kind>_<subject>`) are deleted once; a key of the writer's form, another seat's
// and another kind's stay.
func TestTheOldFindingKeysAreDeletedOnce(t *testing.T) {
state := &oldKeysState{keys: map[string]bool{}}
for _, k := range []string{
"seat.distribution.publish-refused_write", "seat.distribution.publish-refused_a_b_c",
"seat.distribution.sub.publish-refused", "seat.other.publish-refused_write", "seat.distribution.unrelated_write"} {
state.keys[k] = true
}
if err := DeleteOldFindings(state, "distribution", []string{"publish-refused", "incoming-full"}); err != nil {
t.Fatal(err)
}
var left []string
for k := range state.keys {
left = append(left, k)
}
sort.Strings(left)
if got, want := strings.Join(left, " "), "seat.distribution.sub.publish-refused seat.distribution.unrelated_write seat.other.publish-refused_write"; got != want {
t.Errorf("left %s, want %s", got, want)
}
}
type oldKeysState struct{ keys map[string]bool }
func (s *oldKeysState) Get(string) (*stdio.StateEntry, error) { return nil, nil }
func (s *oldKeysState) Put(string, any) (uint64, error) { return 0, nil }
func (s *oldKeysState) Delete(k string) error { delete(s.keys, k); return nil }
func (s *oldKeysState) Keys() ([]string, error) {
var out []string
for k := range s.keys {
out = append(out, k)
}
return out, nil
}