File: context_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.21.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 104,556 kB
  • sloc: ruby: 193; makefile: 171; xml: 11
file content (37 lines) | stat: -rw-r--r-- 775 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
33
34
35
36
37
package aws_test

import (
	"fmt"
	"testing"
	"time"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/awstesting"
)

func TestSleepWithContext(t *testing.T) {
	ctx := &awstesting.FakeContext{DoneCh: make(chan struct{})}

	err := aws.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 := &awstesting.FakeContext{DoneCh: make(chan struct{})}

	expectErr := fmt.Errorf("context canceled")

	ctx.Error = expectErr
	close(ctx.DoneCh)

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

	if e, a := expectErr, err; e != a {
		t.Errorf("expect %v error, got %v", e, a)
	}
}