Browse code

Fix issue where network inspect does not show Created time in swarm scope

This fix tries to address the issue raised in 36083 where
`network inspect` does not show Created time if the network is
created in swarm scope.

The issue was that Created was not converted from swarm api.
This fix addresses the issue.

An unit test has been added.

This fix fixes 36083.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2018/01/24 03:25:23
Showing 2 changed files
... ...
@@ -168,6 +168,7 @@ func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource {
168 168
 		Ingress:    IsIngressNetwork(&n),
169 169
 		Labels:     n.Spec.Annotations.Labels,
170 170
 	}
171
+	nr.Created, _ = gogotypes.TimestampFromProto(n.Meta.CreatedAt)
171 172
 
172 173
 	if n.Spec.GetNetwork() != "" {
173 174
 		nr.ConfigFrom = networktypes.ConfigReference{
174 175
new file mode 100644
... ...
@@ -0,0 +1,34 @@
0
+package convert
1
+
2
+import (
3
+	"testing"
4
+	"time"
5
+
6
+	swarmapi "github.com/docker/swarmkit/api"
7
+	gogotypes "github.com/gogo/protobuf/types"
8
+)
9
+
10
+func TestNetworkConvertBasicNetworkFromGRPCCreatedAt(t *testing.T) {
11
+	expected, err := time.Parse("Jan 2, 2006 at 3:04pm (MST)", "Jan 10, 2018 at 7:54pm (PST)")
12
+	if err != nil {
13
+		t.Fatal(err)
14
+	}
15
+	createdAt, err := gogotypes.TimestampProto(expected)
16
+	if err != nil {
17
+		t.Fatal(err)
18
+	}
19
+
20
+	nw := swarmapi.Network{
21
+		Meta: swarmapi.Meta{
22
+			Version: swarmapi.Version{
23
+				Index: 1,
24
+			},
25
+			CreatedAt: createdAt,
26
+		},
27
+	}
28
+
29
+	n := BasicNetworkFromGRPC(nw)
30
+	if !n.Created.Equal(expected) {
31
+		t.Fatalf("expected time %s; received %s", expected, n.Created)
32
+	}
33
+}