github.com/gavv/monotime@v0.0.0-20190418164738-30dba4353424/monotime_test.go (about)

     1  // Copyright (C) 2016  Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package monotime
     6  
     7  import "testing"
     8  
     9  func TestNow(t *testing.T) {
    10  	for i := 0; i < 100; i++ {
    11  		t1 := Now()
    12  		t2 := Now()
    13  		// I honestly thought that we needed >= here, but in some environments
    14  		// two consecutive calls can return the same value!
    15  		if t1 > t2 {
    16  			t.Fatalf("t1=%d should have been less than or equal to t2=%d", t1, t2)
    17  		}
    18  	}
    19  }
    20  
    21  func TestSince(t *testing.T) {
    22  	for i := 0; i < 100; i++ {
    23  		ts := Now()
    24  		d := Since(ts)
    25  		if d < 0 {
    26  			t.Fatalf("d=%d should be greater than or equal to zero", d)
    27  		}
    28  	}
    29  }