github.com/blend/go-sdk@v1.20220411.3/vault/decompose_json_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package vault 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 type testConfig struct { 17 Omitted string `json:"omitted"` 18 ExplicitOmit string `json:"explicitOmit" secret:"-"` 19 Included string `json:"included" secret:"included"` 20 Number float64 `json:"number" secret:"number"` 21 Binary []byte `json:"binary" secret:"binary"` 22 Nested testConfigInner `json:"nested" secret:"nested"` 23 } 24 25 type testConfigInner struct { 26 Foo string 27 Bar string 28 } 29 30 func TestDecomposeRestore(t *testing.T) { 31 assert := assert.New(t) 32 33 config := testConfig{ 34 Omitted: "a", 35 ExplicitOmit: "b", 36 Included: "c", 37 Number: 3.14, 38 Binary: []byte("just a test"), 39 Nested: testConfigInner{ 40 Foo: "is foo", 41 Bar: "is bar", 42 }, 43 } 44 45 data, err := DecomposeJSON(config) 46 assert.Nil(err) 47 assert.Len(data, 4) 48 49 var verify testConfig 50 assert.Nil(RestoreJSON(data, &verify)) 51 assert.Empty(verify.Omitted) 52 assert.Empty(verify.ExplicitOmit) 53 assert.Equal("c", verify.Included) 54 assert.Equal(3.14, verify.Number) 55 assert.Equal([]byte("just a test"), verify.Binary) 56 assert.Equal("is foo", verify.Nested.Foo) 57 assert.Equal("is bar", verify.Nested.Bar) 58 }