Skip to content

Commit

Permalink
ESSNTL-4817: test InventoryHostsJoin
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Jul 13, 2023
1 parent 569f76f commit b11404d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions base/database/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package database

import (
"app/base/rbac"
"app/base/utils"
"testing"

"github.com/stretchr/testify/assert"
)

var (
// counts of systems from system_platform JOIN inventory.hosts
nGroup1 int64 = 6
nGroup2 int64 = 2
nUngrouped int64 = 6
nAll int64 = 16
)

// nolint: lll
var testCases = []map[int64]map[string]string{
{nGroup1: {rbac.KeyGrouped: "{\"[{\\\"id\\\":\\\"inventory-group-1\\\"}]\"}"}},
{nGroup2: {rbac.KeyGrouped: "{\"[{\\\"id\\\":\\\"inventory-group-2\\\"}]\"}"}},
{nGroup1 + nGroup2: {rbac.KeyGrouped: "{\"[{\\\"id\\\":\\\"inventory-group-1\\\"}]\",\"[{\\\"id\\\":\\\"inventory-group-2\\\"}]\"}"}},
{nGroup1 + nUngrouped: {
rbac.KeyGrouped: "{\"[{\\\"id\\\":\\\"inventory-group-1\\\"}]\"}",
rbac.KeyUngrouped: "[]",
}},
{nUngrouped: {
rbac.KeyGrouped: "{\"[{\\\"id\\\":\\\"non-existing-group\\\"}]\"}",
rbac.KeyUngrouped: "[]",
}},
{0: {rbac.KeyGrouped: "{\"[{\\\"id\\\":\\\"non-existing-group\\\"}]\"}"}},
{nAll: {}},
}

func TestInventoryHostsJoin(t *testing.T) {
utils.SkipWithoutDB(t)
Configure()

for _, tc := range testCases {
for expectedCount, groups := range tc {
var count int64
InventoryHostsJoin(Db.Table("system_platform sp"), groups).Count(&count)
assert.Equal(t, expectedCount, count)
}
}
}

0 comments on commit b11404d

Please sign in to comment.