Skip to content

Commit 8e8cac8

Browse files
committed
Some improvements to TestVolumesInspect
Some improvements in this test; - use the volume-information that's returned by VolumeCreate as "expected" - don't use an explict name for the volume, as it was only used to reference the volume for inspection - improve the test-output on failure, so that "expected" and "actual" values are printed Without this patch applied; === RUN TestVolumesInspect --- FAIL: TestVolumesInspect (0.02s) volume_test.go:108: assertion failed: false (bool) != true (true bool): Time Volume is CreatedAt not equal to current time FAIL With this patch applied; === RUN TestVolumesInspect --- FAIL: TestVolumesInspect (0.02s) volume_test.go:95: assertion failed: expression is false: createdAt.Truncate(time.Minute).Equal(now.Truncate(time.Minute)): CreatedAt (2018-11-01 16:15:20 +0000 UTC) not equal to creation time (2018-11-01 16:15:20.2421166 +0000 UTC m=+13.733512701) FAIL Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 104cbc0 commit 8e8cac8

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

‎integration/volume/volume_test.go‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,19 @@ func TestVolumesInspect(t *testing.T) {
8282
client := request.NewAPIClient(t)
8383
ctx := context.Background()
8484

85-
// sampling current time minus a minute so to now have false positive in case of delays
86-
now := time.Now().Truncate(time.Minute)
87-
88-
name := t.Name()
89-
_, err := client.VolumeCreate(ctx, volumetypes.VolumeCreateBody{
90-
Name: name,
91-
})
85+
now := time.Now()
86+
vol, err := client.VolumeCreate(ctx, volumetypes.VolumeCreateBody{})
9287
assert.NilError(t, err)
9388

94-
vol, err := client.VolumeInspect(ctx, name)
89+
inspected, err := client.VolumeInspect(ctx, vol.Name)
9590
assert.NilError(t, err)
9691

97-
expected := types.Volume{
98-
// Ignore timestamp of CreatedAt
99-
CreatedAt: vol.CreatedAt,
100-
Driver: "local",
101-
Scope: "local",
102-
Name: name,
103-
Mountpoint: fmt.Sprintf("%s/volumes/%s/_data", testEnv.DaemonInfo.DockerRootDir, name),
104-
}
105-
assert.Check(t, is.DeepEqual(vol, expected, cmpopts.EquateEmpty()))
92+
assert.Check(t, is.DeepEqual(inspected, vol, cmpopts.EquateEmpty()))
10693

107-
// comparing CreatedAt field time for the new volume to now. Removing a minute from both to avoid false positive
108-
testCreatedAt, err := time.Parse(time.RFC3339, strings.TrimSpace(vol.CreatedAt))
94+
// comparing CreatedAt field time for the new volume to now. Truncate to 1 minute precision to avoid false positive
95+
createdAt, err := time.Parse(time.RFC3339, strings.TrimSpace(inspected.CreatedAt))
10996
assert.NilError(t, err)
110-
testCreatedAt = testCreatedAt.Truncate(time.Minute)
111-
assert.Check(t, is.Equal(testCreatedAt.Equal(now), true), "Time Volume is CreatedAt not equal to current time")
97+
assert.Check(t, createdAt.Truncate(time.Minute).Equal(now.Truncate(time.Minute)), "CreatedAt (%s) not equal to creation time (%s)", createdAt, now)
11298
}
11399

114100
func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {

0 commit comments

Comments
 (0)