Skip to content

Commit

Permalink
Adding test for JSONTypeExtractor
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Mar 18, 2023
1 parent 5d89ba0 commit 561a2c4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions internal/utils/json_type_extractor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utils_test

import (
"github.com/stretchr/testify/assert"
"github.com/thomaspoignant/go-feature-flag/internal/utils"
"testing"
)

func Test_JSONTypeExtractor(t *testing.T) {
tests := []struct {
name string
input interface{}
expected string
}{
{"string", "hello", "(string)"},
{"integer", 42, "(number)"},
{"float", 3.14, "(number)"},
{"bool", true, "(bool)"},
{"[]interface", []interface{}{1, "two", 3.0}, "([]interface{})"},
{"map", map[string]interface{}{"key1": "value1", "key2": 2}, "(map[string]interface{})"},
{"null", nil, ""},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := utils.JSONTypeExtractor(tt.input)
assert.NoError(t, err, "unexpected error")
assert.Equal(t, tt.expected, got)
})
}
}

0 comments on commit 561a2c4

Please sign in to comment.