| 1 | package statement |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func TestTimestampTime(t *testing.T) { |
| 9 | tstp := newTestTimestamp() |
| 10 | function := tstp.Time("2016-01-01", 100, "s") |
| 11 | expected := int64(1451606400) |
| 12 | got := function() |
| 13 | if expected != got { |
| 14 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 15 | } |
| 16 | function = tstp.Time("now", 100, "ns") |
| 17 | expected = time.Now().UnixNano() |
| 18 | got = function() |
| 19 | if expected < got { |
| 20 | t.Errorf("expected: %v\ngot: %v\n", expected, got) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func newTestTimestamp() *Timestamp { |
| 25 | duration, _ := time.ParseDuration("10s") |
| 26 | return &Timestamp{ |
| 27 | Count: 5001, |
| 28 | Duration: duration, |
| 29 | Jitter: false, |
| 30 | } |
| 31 | } |