File: executor_test.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (65 lines) | stat: -rw-r--r-- 1,426 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//go:build !integration
// +build !integration

package common

import (
	"errors"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestBuildErrorIs(t *testing.T) {
	tests := map[string]struct {
		err    error
		target error
		is     bool
	}{
		"two build errors with the same failure reason": {
			err:    &BuildError{FailureReason: ScriptFailure},
			target: &BuildError{FailureReason: ScriptFailure},
			is:     true,
		},
		"different failure reasons": {
			err:    &BuildError{FailureReason: ScriptFailure},
			target: &BuildError{FailureReason: RunnerSystemFailure},
			is:     false,
		},
		"not matching errors": {
			err:    &BuildError{},
			target: errors.New("mysterious error"),
			is:     false,
		},
	}

	for tn, tt := range tests {
		t.Run(tn, func(t *testing.T) {
			if tt.is {
				assert.ErrorIs(t, tt.err, tt.target)
				return
			}

			assert.NotErrorIs(t, tt.err, tt.target)
		})
	}
}

func TestUnwrapBuildError(t *testing.T) {
	err := &BuildError{Inner: assert.AnError}
	// Unwraps inner error
	assert.ErrorIs(t, err, assert.AnError)

	// Stop unwrapping until BuildError is found.
	assert.ErrorIs(t, err, &BuildError{})
	var buildErr *BuildError
	assert.ErrorAs(t, err, &buildErr)

	err = &BuildError{}
	// Unwraps inner error
	assert.NotErrorIs(t, err, assert.AnError)

	// Stop unwrapping until BuildError is found.
	assert.ErrorIs(t, err, &BuildError{})
	assert.ErrorAs(t, err, &buildErr)
}