env_test.go 832 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package exec
  5. import (
  6. "reflect"
  7. "testing"
  8. )
  9. func TestDedupEnv(t *testing.T) {
  10. tests := []struct {
  11. noCase bool
  12. in []string
  13. want []string
  14. }{
  15. {
  16. noCase: true,
  17. in: []string{"k1=v1", "k2=v2", "K1=v3"},
  18. want: []string{"K1=v3", "k2=v2"},
  19. },
  20. {
  21. noCase: false,
  22. in: []string{"k1=v1", "K1=V2", "k1=v3"},
  23. want: []string{"k1=v3", "K1=V2"},
  24. },
  25. {
  26. in: []string{"=a", "=b", "foo", "bar"},
  27. want: []string{"=b", "foo", "bar"},
  28. },
  29. }
  30. for _, tt := range tests {
  31. got := dedupEnvCase(tt.noCase, tt.in)
  32. if !reflect.DeepEqual(got, tt.want) {
  33. t.Errorf("Dedup(%v, %q) = %q; want %q", tt.noCase, tt.in, got, tt.want)
  34. }
  35. }
  36. }