mirror of
https://github.com/kubescape/kubescape.git
synced 2026-04-15 06:58:11 +00:00
* feat: added support for ListControls and GetFrameworks * perf: introduced jsoniter unmarshalling for faster decoding * introduced stricted error handling & predefined errors: * suppressed edge cases when a flaky value is returned instead of an error * added full unit tests of LoadPolicy Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
33 lines
711 B
Go
33 lines
711 B
Go
package getter
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestJSONDecoder(t *testing.T) {
|
|
t.Run("should decode json string", func(t *testing.T) {
|
|
const input = `"xyz"`
|
|
d := JSONDecoder(input)
|
|
var receiver string
|
|
require.NoError(t, d.Decode(&receiver))
|
|
require.Equal(t, "xyz", receiver)
|
|
})
|
|
|
|
t.Run("should decode json number", func(t *testing.T) {
|
|
const input = `123.01`
|
|
d := JSONDecoder(input)
|
|
var receiver float64
|
|
require.NoError(t, d.Decode(&receiver))
|
|
require.Equal(t, 123.01, receiver)
|
|
})
|
|
|
|
t.Run("requires json quotes", func(t *testing.T) {
|
|
const input = `xyz`
|
|
d := JSONDecoder(input)
|
|
var receiver string
|
|
require.Error(t, d.Decode(&receiver))
|
|
})
|
|
}
|