|
1 | 1 | package main
|
2 | 2 |
|
3 |
| -import ( |
4 |
| - "testing" |
5 |
| -) |
| 3 | +import "testing" |
6 | 4 |
|
7 | 5 | func TestContains(t *testing.T) {
|
8 | 6 | env := map[string]string{
|
@@ -56,3 +54,48 @@ func TestGroupByExitingKey(t *testing.T) {
|
56 | 54 | t.Fail()
|
57 | 55 | }
|
58 | 56 | }
|
| 57 | + |
| 58 | +func TestGroupByMulti(t *testing.T) { |
| 59 | + containers := []*RuntimeContainer{ |
| 60 | + &RuntimeContainer{ |
| 61 | + Env: map[string]string{ |
| 62 | + "VIRTUAL_HOST": "demo1.localhost", |
| 63 | + }, |
| 64 | + ID: "1", |
| 65 | + }, |
| 66 | + &RuntimeContainer{ |
| 67 | + Env: map[string]string{ |
| 68 | + "VIRTUAL_HOST": "demo1.localhost,demo3.localhost", |
| 69 | + }, |
| 70 | + ID: "2", |
| 71 | + }, |
| 72 | + &RuntimeContainer{ |
| 73 | + Env: map[string]string{ |
| 74 | + "VIRTUAL_HOST": "demo2.localhost", |
| 75 | + }, |
| 76 | + ID: "3", |
| 77 | + }, |
| 78 | + } |
| 79 | + |
| 80 | + groups := groupByMulti(containers, "Env.VIRTUAL_HOST", ",") |
| 81 | + if len(groups) != 3 { |
| 82 | + t.Fatalf("expected 3 got %d", len(groups)) |
| 83 | + } |
| 84 | + |
| 85 | + if len(groups["demo1.localhost"]) != 2 { |
| 86 | + t.Fatalf("expected 2 got %s", len(groups["demo1.localhost"])) |
| 87 | + } |
| 88 | + |
| 89 | + if len(groups["demo2.localhost"]) != 1 { |
| 90 | + t.Fatalf("expected 1 got %s", len(groups["demo2.localhost"])) |
| 91 | + } |
| 92 | + if groups["demo2.localhost"][0].ID != "3" { |
| 93 | + t.Fatalf("expected 2 got %s", groups["demo2.localhost"][0].ID) |
| 94 | + } |
| 95 | + if len(groups["demo3.localhost"]) != 1 { |
| 96 | + t.Fatalf("expect 1 got %d", len(groups["demo3.localhost"])) |
| 97 | + } |
| 98 | + if groups["demo3.localhost"][0].ID != "2" { |
| 99 | + t.Fatalf("expected 2 got %s", groups["demo3.localhost"][0].ID) |
| 100 | + } |
| 101 | +} |
0 commit comments