github.com/anjalikarhana/fabric@v2.1.1+incompatible/orderer/common/localconfig/flatten_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package localconfig 8 9 import ( 10 "fmt" 11 "reflect" 12 "testing" 13 14 "github.com/stretchr/testify/assert" 15 ) 16 17 type A struct { 18 s string 19 } 20 21 type B struct { 22 A A 23 i int 24 X string 25 } 26 27 type C struct{} 28 29 type D struct { 30 B B 31 c *C 32 } 33 34 func (a A) String() string { 35 return fmt.Sprintf("I'm '%s'", a.s) 36 } 37 38 func TestFlattenStruct(t *testing.T) { 39 d := &D{ 40 B: B{ 41 A: A{ 42 s: "foo", 43 }, 44 i: 42, 45 X: "bar ", 46 }, 47 c: nil, 48 } 49 50 var x []string 51 flatten("", &x, reflect.ValueOf(d)) 52 assert.Equal(t, 4, len(x), "expect 3 items") 53 assert.Equal(t, x[0], "B.A = I'm 'foo'") 54 assert.Equal(t, x[1], "B.i = 42") 55 assert.Equal(t, x[2], "B.X = \"bar \"") 56 assert.Equal(t, x[3], "c =") 57 }