Skip to content

Commit

Permalink
Test icingadb.EntitiesById#IDs()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Sep 5, 2024
1 parent 0331f47 commit f5b8945
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/icingadb/entitiesbyid_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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())
})
}
}

0 comments on commit f5b8945

Please sign in to comment.