|
7 | 7 | "fmt"
|
8 | 8 | "io/ioutil"
|
9 | 9 | "os"
|
| 10 | + "strconv" |
10 | 11 | "strings"
|
11 | 12 | "testing"
|
12 | 13 |
|
@@ -125,15 +126,14 @@ func TestParseContainerName(t *testing.T) {
|
125 | 126 | }
|
126 | 127 |
|
127 | 128 | func TestPublishInfo(t *testing.T) {
|
128 |
| - node := &types.Node{Endpoint: "tcp://127.0.0.1:12345"} |
129 | 129 | ports := []string{"123", "233"}
|
130 | 130 | n1 := map[string]*network.EndpointSettings{
|
131 | 131 | "n1": &network.EndpointSettings{
|
132 | 132 | IPAddress: "233.233.233.233",
|
133 | 133 | },
|
134 | 134 | "host": &network.EndpointSettings{},
|
135 | 135 | }
|
136 |
| - r := MakePublishInfo(n1, node, ports) |
| 136 | + r := MakePublishInfo(n1, "127.0.0.1", ports) |
137 | 137 | assert.Equal(t, len(r), 2)
|
138 | 138 | assert.Equal(t, len(r["n1"]), 2)
|
139 | 139 | assert.Equal(t, r["n1"][0], "233.233.233.233:123")
|
@@ -227,3 +227,17 @@ func TestCreateTarStream(t *testing.T) {
|
227 | 227 | _, err = CreateTarStream(fname)
|
228 | 228 | assert.NoError(t, err)
|
229 | 229 | }
|
| 230 | + |
| 231 | +func TestRound(t *testing.T) { |
| 232 | + f := func(f float64) string { |
| 233 | + return strconv.FormatFloat(f, 'f', -1, 64) |
| 234 | + } |
| 235 | + a := 0.0199999998 |
| 236 | + assert.Equal(t, f(Round(a, 2)), "0.02") |
| 237 | + a = 0.1999998 |
| 238 | + assert.Equal(t, f(Round(a, 2)), "0.2") |
| 239 | + a = 1.999998 |
| 240 | + assert.Equal(t, f(Round(a, 2)), "2") |
| 241 | + a = 19.99998 |
| 242 | + assert.Equal(t, f(Round(a, 2)), "20") |
| 243 | +} |
0 commit comments