Skip to content

Commit

Permalink
Test Flatten()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Mar 13, 2024
1 parent afeca08 commit 383a6f9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/flatten/flatten_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package flatten

import (
"github.com/icinga/icingadb/pkg/types"
"github.com/stretchr/testify/assert"
"testing"
)

func TestFlatten(t *testing.T) {
for _, st := range []struct {
name string
prefix string
value any
output map[string]types.String
}{
{"nil", "a", nil, map[string]types.String{"a": types.NewString("null")}},
{"bool", "b", true, map[string]types.String{"b": types.NewString("true")}},
{"int", "c", 42, map[string]types.String{"c": types.NewString("42")}},
{"float", "d", 77.7, map[string]types.String{"d": types.NewString("77.7")}},
{"large_float", "e", 1e23, map[string]types.String{"e": types.NewString("100000000000000000000000")}},
{"string", "f", "\x00", map[string]types.String{"f": types.NewString("\x00")}},
{"nil_slice", "g", []any(nil), map[string]types.String{"g": {}}},
{"empty_slice", "h", []any{}, map[string]types.String{"h": {}}},
{"slice", "i", []any{nil}, map[string]types.String{"i[0]": types.NewString("null")}},
{"nil_map", "j", map[string]any(nil), map[string]types.String{"j": {}}},
{"empty_map", "k", map[string]any{}, map[string]types.String{"k": {}}},
{"map", "l", map[string]any{" ": nil}, map[string]types.String{"l. ": types.NewString("null")}},
} {
t.Run(st.name, func(t *testing.T) {
assert.Equal(t, st.output, Flatten(st.value, st.prefix))
})
}
}

0 comments on commit 383a6f9

Please sign in to comment.