File: timeout_error_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 (46 lines) | stat: -rw-r--r-- 1,026 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
38
39
40
41
42
43
44
45
46
package retry

import (
	"fmt"
	"testing"

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

type mockTimeoutErr struct{ timeout bool }

func (m mockTimeoutErr) Timeout() bool { return m.timeout }
func (m mockTimeoutErr) Error() string {
	return fmt.Sprintf("mock timeout, %t", m.timeout)
}

func TestIsTimeoutError(t *testing.T) {
	cases := map[string]struct {
		Err    error
		Check  IsErrorTimeout
		Expect aws.Ternary
	}{
		"TimeouterError true": {
			Err:    fmt.Errorf("nested error, %w", mockTimeoutErr{timeout: true}),
			Check:  TimeouterError{},
			Expect: aws.TrueTernary,
		},
		"TimeouterError false": {
			Err:    fmt.Errorf("nested error, %w", mockTimeoutErr{timeout: false}),
			Check:  TimeouterError{},
			Expect: aws.FalseTernary,
		},
		"other error": {
			Err:   fmt.Errorf("some other error"),
			Check: TimeouterError{},
		},
	}

	for name, c := range cases {
		t.Run(name, func(t *testing.T) {
			if e, a := c.Expect, c.Check.IsErrorTimeout(c.Err); e != a {
				t.Errorf("expect %v, got %v", e, a)
			}
		})
	}
}