@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"bytes"
5
5
"encoding/json"
6
+ "reflect"
6
7
"testing"
7
8
)
8
9
@@ -20,6 +21,59 @@ func TestContains(t *testing.T) {
20
21
}
21
22
}
22
23
24
+ func TestKeys (t * testing.T ) {
25
+ expected := "VIRTUAL_HOST"
26
+ env := map [string ]string {
27
+ expected : "demo.local" ,
28
+ }
29
+
30
+ k , err := keys (env )
31
+ if err != nil {
32
+ t .Fatalf ("Error fetching keys: %v" , err )
33
+ }
34
+ vk := reflect .ValueOf (k )
35
+ if vk .Kind () == reflect .Invalid {
36
+ t .Fatalf ("Got invalid kind for keys: %v" , vk )
37
+ }
38
+
39
+ if len (env ) != vk .Len () {
40
+ t .Fatalf ("Incorrect key count; expected %s, got %s" , len (env ), vk .Len ())
41
+ }
42
+
43
+ got := vk .Index (0 ).Interface ()
44
+ if expected != got {
45
+ t .Fatalf ("Incorrect key found; expected %s, got %s" , expected , got )
46
+ }
47
+ }
48
+
49
+ func TestKeysEmpty (t * testing.T ) {
50
+ input := map [string ]int {}
51
+
52
+ k , err := keys (input )
53
+ if err != nil {
54
+ t .Fatalf ("Error fetching keys: %v" , err )
55
+ }
56
+ vk := reflect .ValueOf (k )
57
+ if vk .Kind () == reflect .Invalid {
58
+ t .Fatalf ("Got invalid kind for keys: %v" , vk )
59
+ }
60
+
61
+ if len (input ) != vk .Len () {
62
+ t .Fatalf ("Incorrect key count; expected %s, got %s" , len (input ), vk .Len ())
63
+ }
64
+ }
65
+
66
+ func TestKeysNil (t * testing.T ) {
67
+ k , err := keys (nil )
68
+ if err != nil {
69
+ t .Fatalf ("Error fetching keys: %v" , err )
70
+ }
71
+ vk := reflect .ValueOf (k )
72
+ if vk .Kind () != reflect .Invalid {
73
+ t .Fatalf ("Got invalid kind for keys: %v" , vk )
74
+ }
75
+ }
76
+
23
77
func TestGroupByExistingKey (t * testing.T ) {
24
78
containers := []* RuntimeContainer {
25
79
& RuntimeContainer {
0 commit comments