mirror of
https://github.com/hanzoai/ingress.git
synced 2026-10-30 14:58:23 +00:00
376 files. All tests pass. Breaking wire changes: - X-Traefik-Fast-Proxy → X-Ingress-Fast-Proxy - X-Traefik-Router → X-Ingress-Router - Metric prefix traefik.* → ingress.* - ACME user agent containous-traefik → hanzoai-ingress - Plugin manifest .traefik.yml → .ingress.yml - Recovery middleware traefik-internal-recovery → ingress-internal-recovery Copyright: Traefik Labs → Hanzo AI Inc (all headers) Test domains: *.traefik.wtf → *.ingress.test Doc URLs: doc.traefik.io → hanzo.ai/docs/ingress Internal vars: traefikService* → ingressService*, etc. Docker refs: traefik:latest → ghcr.io/hanzoai/ingress:latest 100+ YAML/JSON test fixtures updated Remaining 30 refs are paerser library constraints (traefik.configfile flag, TRAEFIK_* env prefix) and digest auth hash-bound realm values. Cannot change without forking github.com/traefik/paerser.
119 lines
2.4 KiB
Go
119 lines
2.4 KiB
Go
package kv
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDecode(t *testing.T) {
|
|
testCases := []struct {
|
|
desc string
|
|
rootName string
|
|
pairs map[string]string
|
|
expected *sample
|
|
}{
|
|
{
|
|
desc: "simple case",
|
|
rootName: "ingress",
|
|
pairs: map[string]string{
|
|
"ingress/fielda": "bar",
|
|
"ingress/fieldb": "1",
|
|
"ingress/fieldc": "true",
|
|
"ingress/fieldd/0": "one",
|
|
"ingress/fieldd/1": "two",
|
|
"ingress/fielde": "",
|
|
"ingress/fieldf/Test1": "A",
|
|
"ingress/fieldf/Test2": "B",
|
|
"ingress/fieldg/0/name": "A",
|
|
"ingress/fieldg/1/name": "B",
|
|
"ingress/fieldh/": "foo",
|
|
},
|
|
expected: &sample{
|
|
FieldA: "bar",
|
|
FieldB: 1,
|
|
FieldC: true,
|
|
FieldD: []string{"one", "two"},
|
|
FieldE: &struct {
|
|
Name string
|
|
}{},
|
|
FieldF: map[string]string{
|
|
"Test1": "A",
|
|
"Test2": "B",
|
|
},
|
|
FieldG: []sub{
|
|
{Name: "A"},
|
|
{Name: "B"},
|
|
},
|
|
FieldH: "foo",
|
|
},
|
|
},
|
|
{
|
|
desc: "multi-level root name",
|
|
rootName: "foo/bar/ingress",
|
|
pairs: map[string]string{
|
|
"foo/bar/ingress/fielda": "bar",
|
|
"foo/bar/ingress/fieldb": "2",
|
|
"foo/bar/ingress/fieldc": "true",
|
|
"foo/bar/ingress/fieldd/0": "one",
|
|
"foo/bar/ingress/fieldd/1": "two",
|
|
"foo/bar/ingress/fielde": "",
|
|
"foo/bar/ingress/fieldf/Test1": "A",
|
|
"foo/bar/ingress/fieldf/Test2": "B",
|
|
"foo/bar/ingress/fieldg/0/name": "A",
|
|
"foo/bar/ingress/fieldg/1/name": "B",
|
|
"foo/bar/ingress/fieldh/": "foo",
|
|
},
|
|
expected: &sample{
|
|
FieldA: "bar",
|
|
FieldB: 2,
|
|
FieldC: true,
|
|
FieldD: []string{"one", "two"},
|
|
FieldE: &struct {
|
|
Name string
|
|
}{},
|
|
FieldF: map[string]string{
|
|
"Test1": "A",
|
|
"Test2": "B",
|
|
},
|
|
FieldG: []sub{
|
|
{Name: "A"},
|
|
{Name: "B"},
|
|
},
|
|
FieldH: "foo",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range testCases {
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
element := &sample{}
|
|
|
|
err := Decode(mapToPairs(test.pairs), element, test.rootName)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, test.expected, element)
|
|
})
|
|
}
|
|
}
|
|
|
|
type sample struct {
|
|
FieldA string
|
|
FieldB int
|
|
FieldC bool
|
|
FieldD []string
|
|
FieldE *struct {
|
|
Name string
|
|
} `kv:"allowEmpty"`
|
|
FieldF map[string]string
|
|
FieldG []sub
|
|
FieldH string
|
|
}
|
|
|
|
type sub struct {
|
|
Name string
|
|
}
|