MCPcopy Create free account
hub / github.com/prometheus/common / TestTimeConversions

Function TestTimeConversions

model/time_test.go:40–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestTimeConversions(t *testing.T) {
41 unixSecs := int64(1136239445)
42 unixNsecs := int64(123456789)
43 unixNano := unixSecs*1e9 + unixNsecs
44
45 t1 := time.Unix(unixSecs, unixNsecs-unixNsecs%nanosPerTick)
46 t2 := time.Unix(unixSecs, unixNsecs)
47
48 ts := TimeFromUnixNano(unixNano)
49 require.Truef(t, ts.Time().Equal(t1), "Expected %s, got %s", t1, ts.Time())
50
51 // Test available precision.
52 ts = TimeFromUnixNano(t2.UnixNano())
53 require.Truef(t, ts.Time().Equal(t1), "Expected %s, got %s", t1, ts.Time())
54
55 require.Equalf(t, ts.UnixNano(), unixNano-unixNano%nanosPerTick, "Expected %d, got %d", unixNano, ts.UnixNano())
56}
57
58func TestDuration(t *testing.T) {
59 duration := time.Second + time.Minute + time.Hour

Callers

nothing calls this directly

Calls 5

TimeFromUnixNanoFunction · 0.85
UnixMethod · 0.80
TimeMethod · 0.80
UnixNanoMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…