github.com/zntrio/harp/v2@v2.0.9/pkg/sdk/value/flatmap/flatmap_test.go (about) 1 // Licensed to Elasticsearch B.V. under one or more contributor 2 // license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright 4 // ownership. Elasticsearch B.V. licenses this file to you under 5 // the Apache License, Version 2.0 (the "License"); you may 6 // not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 package flatmap 19 20 import ( 21 "reflect" 22 "testing" 23 24 "github.com/zntrio/harp/v2/pkg/bundle" 25 ) 26 27 func TestFlatten(t *testing.T) { 28 cases := []struct { 29 Input map[string]interface{} 30 Output map[string]bundle.KV 31 }{ 32 { 33 Input: map[string]interface{}{ 34 "app": bundle.KV{ 35 "database": bundle.KV{ 36 "user": "app-12345679", 37 "password": "testpassword", 38 }, 39 "integers": bundle.KV{ 40 "int": int(8), 41 "int8": int8(0x7F), 42 "int16": int16(0x7FF), 43 "int32": int32(0x7FFFFFFF), 44 "int64": int64(0x7FFFFFFFFFFFFFFF), 45 "uint": uint(8), 46 "uint8": uint8(0xFF), 47 "uint16": uint16(0xFFF), 48 "uint32": uint32(0xFFFFFFFF), 49 "uint64": uint64(0xFFFFFFFFFFFFFFFF), 50 }, 51 "arrays": bundle.KV{ 52 "strings": []string{"first", "second", "third"}, 53 }, 54 }, 55 }, 56 Output: map[string]bundle.KV{ 57 "app/database": { 58 "user": "app-12345679", 59 "password": "testpassword", 60 }, 61 "app/integers": { 62 "int": "8", 63 "int16": "2047", 64 "int32": "2147483647", 65 "int64": "9223372036854775807", 66 "int8": "127", 67 "uint": "8", 68 "uint16": "4095", 69 "uint32": "4294967295", 70 "uint64": "18446744073709551615", 71 "uint8": "255", 72 }, 73 "app/arrays/strings": { 74 "#": "3", 75 "0": "first", 76 "1": "second", 77 "2": "third", 78 }, 79 }, 80 }, 81 } 82 83 for _, tc := range cases { 84 actual := Flatten(tc.Input) 85 if !reflect.DeepEqual(actual, tc.Output) { 86 t.Fatalf( 87 "Input:\n\n%#v\n\nOutput:\n\n%#v\n\nExpected:\n\n%#v\n", 88 tc.Input, 89 actual, 90 tc.Output) 91 } 92 } 93 }