Skip to content

Commit

Permalink
add-packed-KV-specific-interface-support-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BoskyWSMFN committed Sep 2, 2024
1 parent a35fc0f commit 0c12668
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions internal/convert/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nil-go/konf/internal/maps"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -921,9 +922,57 @@ func TestConverter(t *testing.T) { //nolint:maintidx
},
{
description: "map to interface",
from: map[string]int{"key": 42},
from: map[string]int{"key": 42, "keySensitive": 43},
to: pointer(any(nil)),
expected: pointer(any(map[string]int{"key": 42})),
expected: pointer(any(map[string]int{"key": 42, "keySensitive": 43})),
},
{
description: "map to interface (with keyMap)", // Probably redundant.
opts: []convert.Option{
convert.WithKeyMapper(strings.ToLower),
},
from: map[string]int{"key": 42, "keysensitive": 43},
to: pointer(any(nil)),
expected: pointer(any(map[string]int{"key": 42, "keysensitive": 43})),
},
{
description: "packed KV and field to map[string]interface{}",
from: map[string]interface{}{
"key1": maps.KeyValue{
Key: "key1",
Value: "value1",
},
"key2": "value2",
},
to: pointer(map[string]interface{}{}),
expected: pointer(map[string]interface{}{
"key1": "value1",
"key2": "value2",
}),
},
{
description: "packed KV and field to struct (with keyMap)",
opts: []convert.Option{
convert.WithKeyMapper(strings.ToLower),
},
from: map[string]interface{}{
"key1": maps.KeyValue{
Key: "key1",
Value: "value1",
},
"key2": "value2",
},
to: pointer(struct {
Key1 interface{}
Key2 interface{}
}{}),
expected: pointer(struct {
Key1 interface{}
Key2 interface{}
}{
Key1: "value1",
Key2: "value2",
}),
},
{
description: "slice to interface",
Expand Down

0 comments on commit 0c12668

Please sign in to comment.