github.com/lmars/docker@v1.6.0-rc2/pkg/units/duration_test.go (about)

     1  package units
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestHumanDuration(t *testing.T) {
     9  	// Useful duration abstractions
    10  	day := 24 * time.Hour
    11  	week := 7 * day
    12  	month := 30 * day
    13  	year := 365 * day
    14  
    15  	assertEquals(t, "Less than a second", HumanDuration(450*time.Millisecond))
    16  	assertEquals(t, "47 seconds", HumanDuration(47*time.Second))
    17  	assertEquals(t, "About a minute", HumanDuration(1*time.Minute))
    18  	assertEquals(t, "3 minutes", HumanDuration(3*time.Minute))
    19  	assertEquals(t, "35 minutes", HumanDuration(35*time.Minute))
    20  	assertEquals(t, "35 minutes", HumanDuration(35*time.Minute+40*time.Second))
    21  	assertEquals(t, "About an hour", HumanDuration(1*time.Hour))
    22  	assertEquals(t, "About an hour", HumanDuration(1*time.Hour+45*time.Minute))
    23  	assertEquals(t, "3 hours", HumanDuration(3*time.Hour))
    24  	assertEquals(t, "3 hours", HumanDuration(3*time.Hour+59*time.Minute))
    25  	assertEquals(t, "4 hours", HumanDuration(3*time.Hour+60*time.Minute))
    26  	assertEquals(t, "24 hours", HumanDuration(24*time.Hour))
    27  	assertEquals(t, "36 hours", HumanDuration(1*day+12*time.Hour))
    28  	assertEquals(t, "2 days", HumanDuration(2*day))
    29  	assertEquals(t, "7 days", HumanDuration(7*day))
    30  	assertEquals(t, "13 days", HumanDuration(13*day+5*time.Hour))
    31  	assertEquals(t, "2 weeks", HumanDuration(2*week))
    32  	assertEquals(t, "2 weeks", HumanDuration(2*week+4*day))
    33  	assertEquals(t, "3 weeks", HumanDuration(3*week))
    34  	assertEquals(t, "4 weeks", HumanDuration(4*week))
    35  	assertEquals(t, "4 weeks", HumanDuration(4*week+3*day))
    36  	assertEquals(t, "4 weeks", HumanDuration(1*month))
    37  	assertEquals(t, "6 weeks", HumanDuration(1*month+2*week))
    38  	assertEquals(t, "8 weeks", HumanDuration(2*month))
    39  	assertEquals(t, "3 months", HumanDuration(3*month+1*week))
    40  	assertEquals(t, "5 months", HumanDuration(5*month+2*week))
    41  	assertEquals(t, "13 months", HumanDuration(13*month))
    42  	assertEquals(t, "23 months", HumanDuration(23*month))
    43  	assertEquals(t, "24 months", HumanDuration(24*month))
    44  	assertEquals(t, "2.010959 years", HumanDuration(24*month+2*week))
    45  	assertEquals(t, "3.164384 years", HumanDuration(3*year+2*month))
    46  }