github.com/matrixorigin/matrixone@v1.2.0/pkg/util/dump_config_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package util
    16  
    17  import (
    18  	"github.com/stretchr/testify/assert"
    19  	"testing"
    20  )
    21  
    22  type abc struct {
    23  	A string
    24  	B string `user_setting:"advanced"`
    25  }
    26  
    27  type kkk struct {
    28  	kk string `user_setting:"basic"`
    29  	jj string
    30  }
    31  
    32  type def struct {
    33  	FFF *abc  `user_setting:"advanced"`
    34  	DDD []kkk `user_setting:"advanced"`
    35  	ABC []abc `toml:"abc"`
    36  	EEE [3]abc
    37  	MMM map[string]string
    38  	NNN map[string]abc
    39  	PPP *abc
    40  	QQQ *abc
    41  	RRR map[string]string
    42  }
    43  
    44  func Test_flatten(t *testing.T) {
    45  	cf1 := def{
    46  		ABC: []abc{
    47  			{"a", "a1"},
    48  			{"b", "b1"},
    49  		},
    50  		EEE: [3]abc{
    51  			{"a", "a1"},
    52  			{"b", "b1"},
    53  			{"c", "c1"},
    54  		},
    55  		MMM: map[string]string{
    56  			"abc":  "ABC",
    57  			"abcd": "ABCd",
    58  		},
    59  		NNN: map[string]abc{
    60  			"abc":  {"a", "a1"},
    61  			"abcd": {"a", "a1"},
    62  		},
    63  		PPP: &abc{"a", "a1"},
    64  		FFF: &abc{"a", "a1"},
    65  	}
    66  	exp := newExporter()
    67  	err := flatten(cf1, "", "", "", exp)
    68  	assert.NoError(t, err)
    69  	err = flatten(&cf1, "", "", "", exp)
    70  	assert.NoError(t, err)
    71  
    72  	k := kkk{
    73  		"abc",
    74  		"def",
    75  	}
    76  	err = flatten(k, "", "", "", exp)
    77  	assert.NoError(t, err)
    78  	exp.Print()
    79  }