forked from google/gopacket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time: Add tests + fix Micro vs Milli error
- Loading branch information
Showing
4 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2019 The GoPacket Authors. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file in the root of the source | ||
// tree. | ||
|
||
package gopacket | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestToDuration(t *testing.T) { | ||
for i, test := range []struct { | ||
r TimestampResolution | ||
d time.Duration | ||
}{ | ||
{ | ||
TimestampResolutionMillisecond, | ||
time.Millisecond, | ||
}, | ||
{ | ||
TimestampResolutionMicrosecond, | ||
time.Microsecond, | ||
}, | ||
{ | ||
TimestampResolutionNanosecond, | ||
time.Nanosecond, | ||
}, | ||
{ | ||
TimestampResolutionNTP, | ||
0, // this is not representable since it's ~0.233 nanoseconds | ||
}, | ||
{ | ||
TimestampResolution{2, -16}, | ||
15258, | ||
}, | ||
{ | ||
TimestampResolution{2, 1}, | ||
2 * time.Second, | ||
}, | ||
{ | ||
TimestampResolution{10, 1}, | ||
10 * time.Second, | ||
}, | ||
{ | ||
TimestampResolution{10, 0}, | ||
time.Second, | ||
}, | ||
{ | ||
TimestampResolution{2, 0}, | ||
time.Second, | ||
}, | ||
{ | ||
TimestampResolution{0, 0}, | ||
0, | ||
}, | ||
{ | ||
TimestampResolution{3, 2}, | ||
9 * time.Second, | ||
}, | ||
{ | ||
TimestampResolution{3, -2}, | ||
111111111, | ||
}, | ||
} { | ||
d := test.r.ToDuration() | ||
if d != test.d { | ||
t.Errorf("%d: resolution: %s want: %d got: %d", i, test.r, test.d, d) | ||
} | ||
} | ||
} |