From f5b8945cae07e4e5701791faf719cff52bd0eee8 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 5 Sep 2024 10:10:45 +0200 Subject: [PATCH] Test icingadb.EntitiesById#IDs() --- pkg/icingadb/entitiesbyid_test.go | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/icingadb/entitiesbyid_test.go b/pkg/icingadb/entitiesbyid_test.go index ca2d0856a..4608ff095 100644 --- a/pkg/icingadb/entitiesbyid_test.go +++ b/pkg/icingadb/entitiesbyid_test.go @@ -1,6 +1,7 @@ package icingadb import ( + "github.com/icinga/icinga-go-library/types" "github.com/icinga/icingadb/pkg/icingadb/v1" "github.com/stretchr/testify/require" "testing" @@ -35,3 +36,37 @@ func TestEntitiesById_Keys(t *testing.T) { }) } } + +func newEntity(id []byte) *v1.EntityWithoutChecksum { + return &v1.EntityWithoutChecksum{IdMeta: v1.IdMeta{Id: id}} +} + +func TestEntitiesById_IDs(t *testing.T) { + subtests := []struct { + name string + input EntitiesById + output []types.Binary + }{ + {name: "nil"}, + { + name: "empty", + input: EntitiesById{}, + }, + { + name: "one", + input: EntitiesById{"one": newEntity([]byte{23})}, + output: []types.Binary{{23}}, + }, + { + name: "two", + input: EntitiesById{"one": newEntity([]byte{23}), "two": newEntity([]byte{42})}, + output: []types.Binary{{23}, {42}}, + }, + } + + for _, st := range subtests { + t.Run(st.name, func(t *testing.T) { + require.ElementsMatch(t, st.output, st.input.IDs()) + }) + } +}