github.com/zntrio/harp/v2@v2.0.9/pkg/sdk/value/flatmap/expand_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  	"testing"
    22  
    23  	"github.com/google/go-cmp/cmp"
    24  
    25  	"github.com/zntrio/harp/v2/pkg/bundle"
    26  )
    27  
    28  func TestExpand(t *testing.T) {
    29  	type args struct {
    30  		m   bundle.KV
    31  		key string
    32  	}
    33  	tests := []struct {
    34  		name string
    35  		args args
    36  		want interface{}
    37  	}{
    38  		{
    39  			name: "empty",
    40  		},
    41  		{
    42  			name: "map",
    43  			args: args{
    44  				m: bundle.KV{
    45  					"app/database": bundle.KV{
    46  						"user":     "test",
    47  						"password": "password",
    48  					},
    49  				},
    50  			},
    51  			want: bundle.KV{
    52  				"app": bundle.KV{
    53  					"database": bundle.KV{
    54  						"user":     "test",
    55  						"password": "password",
    56  					},
    57  				},
    58  			},
    59  		},
    60  	}
    61  	for _, tt := range tests {
    62  		t.Run(tt.name, func(t *testing.T) {
    63  			got := Expand(tt.args.m, tt.args.key)
    64  			if diff := cmp.Diff(got, tt.want); diff != "" {
    65  				t.Errorf("Expand() = \n%s", diff)
    66  			}
    67  		})
    68  	}
    69  }