You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
// Copyright 2019 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
func TestMergeEnvValues(t *testing.T) {
|
|
testData := []struct {
|
|
values []string
|
|
updates []string
|
|
result []string
|
|
}{
|
|
{[]string{}, []string{}, []string{}},
|
|
{[]string{"A=1"}, []string{}, []string{"A=1"}},
|
|
{[]string{"A=1=2=3"}, []string{}, []string{"A=1=2=3"}},
|
|
{[]string{}, []string{"A=1"}, []string{"A=1"}},
|
|
{[]string{}, []string{"A=1=2=3"}, []string{"A=1=2=3"}},
|
|
{[]string{"A=1"}, []string{"A=2"}, []string{"A=2"}},
|
|
{[]string{"A="}, []string{}, []string{"A="}},
|
|
{[]string{"A="}, []string{"A=2"}, []string{"A=2"}},
|
|
{[]string{"A=1"}, []string{"A="}, []string{}},
|
|
{[]string{}, []string{"A=1", "A="}, []string{}},
|
|
{[]string{}, []string{"A=1", "A=", "A=2"}, []string{"A=2"}},
|
|
{[]string{"A=1", "B=2"}, []string{"C=3", "D=4"}, []string{"A=1", "B=2", "C=3", "D=4"}},
|
|
}
|
|
for _, tt := range testData {
|
|
result := mergeEnvValues(tt.values, tt.updates)
|
|
sort.Strings(result)
|
|
if !reflect.DeepEqual(tt.result, result) {
|
|
t.Errorf("unexpected result: %s", result)
|
|
}
|
|
}
|
|
}
|