File: time_test.go

package info (click to toggle)
golang-github-mesos-mesos-go 0.0.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,724 kB
  • sloc: makefile: 163
file content (47 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package time_test

import (
	"testing"
	"time"

	. "github.com/mesos/mesos-go/api/v1/lib/time"
)

func TestParseDuration(t *testing.T) {
	for i, tc := range []struct {
		input      string
		output     time.Duration
		wantsError bool
	}{
		{wantsError: true},
		{input: "1ns", output: time.Duration(1)},
		{input: "1.5ns", output: time.Duration(1)},
		{input: "1.9ns", output: time.Duration(1)},
		{input: "1us", output: 1 * time.Microsecond},
		{input: "1.5us", output: 1*time.Microsecond + 500},
		{input: "1ms", output: 1 * time.Millisecond},
		{input: "1secs", output: 1 * time.Second},
		{input: "1mins", output: 1 * time.Minute},
		{input: "1hrs", output: 1 * time.Hour},
		{input: "1days", output: 1 * time.Hour * 24},
		{input: "1weeks", output: 1 * time.Hour * 24 * 7},
		{input: "1", wantsError: true},
		{input: "1.0", wantsError: true},
		{input: "1.0.0ns", wantsError: true},
		{input: "a1ns", wantsError: true},
		{input: "ns", wantsError: true},
		{input: "1ms1ns", wantsError: true},
	} {
		d, err := ParseDuration(tc.input)
		if err != nil && tc.wantsError {
			continue
		}
		if err != nil {
			t.Errorf("test case %d failed: unexpected error %+v", i, err)
		} else if tc.wantsError {
			t.Errorf("test case %d failed: expected error for input %q", i, tc.input)
		} else if tc.output != d {
			t.Errorf("test case %d failed: expected output %v instead of %v", i, tc.output, d)
		}
	}
}