File: time_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (32 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (5)
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
package sdk

import (
	"context"
	"strings"
	"testing"
	"time"
)

func TestSleepWithContext(t *testing.T) {
	ctx, cancelFn := context.WithCancel(context.Background())
	defer cancelFn()

	err := sleepWithContext(ctx, 1*time.Millisecond)
	if err != nil {
		t.Errorf("expect context to not be canceled, got %v", err)
	}
}

func TestSleepWithContext_Canceled(t *testing.T) {
	ctx, cancelFn := context.WithCancel(context.Background())
	cancelFn()

	err := sleepWithContext(ctx, 10*time.Second)
	if err == nil {
		t.Fatalf("expect error, did not get one")
	}

	if e, a := "context canceled", err.Error(); !strings.Contains(a, e) {
		t.Errorf("expect %v error, got %v", e, a)
	}
}