-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy patherrors_test.go
51 lines (46 loc) · 1.38 KB
/
errors_test.go
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
package opslevel_test
import (
"fmt"
"testing"
ol "github.com/opslevel/opslevel-go/v2025"
"github.com/rocktavious/autopilot/v2023"
)
func TestHasAPIErrorsWorks(t *testing.T) {
// Arrange
errs := []ol.Error{
{Message: "can't be blank", Path: []string{"resource", "id"}},
{Message: "is not a valid input", Path: []string{"id"}},
}
// Act
output := ol.HasAPIErrors(errs)
// Assert
autopilot.Equals(t, true, ol.ErrIs(output, ol.ErrorAPIError))
autopilot.Equals(t, `OpsLevel API Errors:
- 'resource.id' can't be blank
- 'id' is not a valid input`,
output.Error())
}
func TestHasAPIErrorsNoPath(t *testing.T) {
// Arrange
errs := []ol.Error{
{Message: "can't be blank", Path: []string{"base"}},
{Message: "is not a valid input", Path: []string{""}},
}
// Act
output := ol.HasAPIErrors(errs)
// Assert
autopilot.Equals(t, true, ol.ErrIs(output, ol.ErrorAPIError))
autopilot.Equals(t, `OpsLevel API Errors:
- '' can't be blank
- '' is not a valid input`,
output.Error())
}
func TestIsResourceFoundError(t *testing.T) {
// Arrange
err1 := ol.NewClientError(ol.ErrorResourceNotFound, fmt.Errorf("resource 'Example' not found"))
err2 := ol.NewClientError(ol.ErrorAPIError, fmt.Errorf("resource 'Example' not found"))
// Act
// Assert
autopilot.Equals(t, true, ol.ErrIs(err1, ol.ErrorResourceNotFound))
autopilot.Equals(t, false, ol.ErrIs(err2, ol.ErrorResourceNotFound))
}