diff options
| author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
| commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
| tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/pkg/net/fd_posix_test.go | |
| parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
| download | golang-04b08da9af0c450d645ab7389d1467308cfc2db8.tar.gz | |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/pkg/net/fd_posix_test.go')
| -rw-r--r-- | src/pkg/net/fd_posix_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/pkg/net/fd_posix_test.go b/src/pkg/net/fd_posix_test.go new file mode 100644 index 000000000..8be0335d6 --- /dev/null +++ b/src/pkg/net/fd_posix_test.go @@ -0,0 +1,57 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin freebsd linux netbsd openbsd windows + +package net + +import ( + "testing" + "time" +) + +var deadlineSetTimeTests = []struct { + input time.Time + expected int64 +}{ + {time.Time{}, 0}, + {time.Date(2009, 11, 10, 23, 00, 00, 00, time.UTC), 1257894000000000000}, // 2009-11-10 23:00:00 +0000 UTC +} + +func TestDeadlineSetTime(t *testing.T) { + for _, tt := range deadlineSetTimeTests { + var d deadline + d.setTime(tt.input) + actual := d.value() + expected := int64(0) + if !tt.input.IsZero() { + expected = tt.input.UnixNano() + } + if actual != expected { + t.Errorf("set/value failed: expected %v, actual %v", expected, actual) + } + } +} + +var deadlineExpiredTests = []struct { + deadline time.Time + expired bool +}{ + // note, times are relative to the start of the test run, not + // the start of TestDeadlineExpired + {time.Now().Add(5 * time.Minute), false}, + {time.Now().Add(-5 * time.Minute), true}, + {time.Time{}, false}, // no deadline set +} + +func TestDeadlineExpired(t *testing.T) { + for _, tt := range deadlineExpiredTests { + var d deadline + d.set(tt.deadline.UnixNano()) + expired := d.expired() + if expired != tt.expired { + t.Errorf("expire failed: expected %v, actual %v", tt.expired, expired) + } + } +} |
