-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcats_test.go
More file actions
86 lines (79 loc) · 2.44 KB
/
Copy pathlcats_test.go
File metadata and controls
86 lines (79 loc) · 2.44 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package tango
import (
"context"
"errors"
"testing"
)
func TestListLcatsRequiresOwner(t *testing.T) {
cases := []struct {
name string
opts *ListLcatsOptions
}{
{"nil opts", nil},
{"empty opts", &ListLcatsOptions{}},
{"both blank", &ListLcatsOptions{UEI: "", IDVKey: ""}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
c, _ := newTestClient(t, emptyListHandler)
_, err := c.ListLcats(context.Background(), tc.opts)
var ve *ValidationError
if !errors.As(err, &ve) {
t.Fatalf("expected *ValidationError, got %T: %v", err, err)
}
})
}
}
func TestListLcatsDispatchesByOwner(t *testing.T) {
t.Run("UEI dispatches to entity endpoint", func(t *testing.T) {
var capturedURL string
c, _ := newTestClient(t, captureURLHandler(&capturedURL))
_, _ = c.ListLcats(context.Background(), &ListLcatsOptions{UEI: "UEI123"})
assertPathContains(t, capturedURL, "/api/entities/UEI123/lcats/")
})
t.Run("IDVKey dispatches to IDV endpoint", func(t *testing.T) {
var capturedURL string
c, _ := newTestClient(t, captureURLHandler(&capturedURL))
_, _ = c.ListLcats(context.Background(), &ListLcatsOptions{IDVKey: "IDV-001"})
assertPathContains(t, capturedURL, "/api/idvs/IDV-001/lcats/")
})
t.Run("both set: UEI wins", func(t *testing.T) {
var capturedURL string
c, _ := newTestClient(t, captureURLHandler(&capturedURL))
_, _ = c.ListLcats(context.Background(), &ListLcatsOptions{UEI: "U1", IDVKey: "I1"})
assertPathContains(t, capturedURL, "/api/entities/U1/lcats/")
})
}
func TestListLcatsForwardsFilters(t *testing.T) {
var capturedURL string
c, _ := newTestClient(t, captureURLHandler(&capturedURL))
_, _ = c.ListLcats(context.Background(), &ListLcatsOptions{
UEI: "UEI123",
EntityLcatsOptions: EntityLcatsOptions{
Ordering: "labor_category",
Search: "software engineer",
},
})
assertQueryContains(t, capturedURL,
map[string]string{
"ordering": "labor_category",
"search": "software engineer",
},
nil,
)
}
func TestIterateLcatsNilOpts(t *testing.T) {
c, _ := newTestClient(t, emptyListHandler)
it := c.IterateLcats(context.Background(), nil)
if it == nil {
t.Fatal("expected non-nil iterator")
}
// Iterator.Next() should surface the validation error.
if it.Next() {
t.Error("expected Next() to return false on missing owner")
}
var ve *ValidationError
if !errors.As(it.Err(), &ve) {
t.Errorf("expected *ValidationError from iter.Err(), got %T: %v", it.Err(), it.Err())
}
}