-
Notifications
You must be signed in to change notification settings - Fork 0
/
orgprinterapi_test.go
149 lines (130 loc) · 2.99 KB
/
orgprinterapi_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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package main
import (
"fmt"
"testing"
"golang.org/x/net/context"
gdpb "github.com/brotherlogic/godiscogs/proto"
rcpb "github.com/brotherlogic/recordcollection/proto"
ropb "github.com/brotherlogic/recordsorganiser/proto"
rpb "github.com/brotherlogic/reminders/proto"
)
type testOrg struct {
failLists bool
failList bool
failLow bool
failHigh bool
}
func (t *testOrg) listLocations(ctx context.Context) ([]*ropb.Location, error) {
if t.failLists {
return nil, fmt.Errorf("Built to fail")
}
return []*ropb.Location{
&ropb.Location{
Name: "Records",
Slots: 2,
InPlay: ropb.Location_IN_PLAY,
},
}, nil
}
func (t *testOrg) listLocation(ctx context.Context, location string) (*ropb.Location, error) {
if t.failList {
return nil, fmt.Errorf("Built to fail")
}
return &ropb.Location{
ReleasesLocation: []*ropb.ReleasePlacement{
&ropb.ReleasePlacement{
Index: 1,
Slot: 0,
InstanceId: 1,
},
&ropb.ReleasePlacement{
Index: 2,
Slot: 0,
InstanceId: 2,
},
&ropb.ReleasePlacement{
Index: 1,
Slot: 1,
InstanceId: 1,
},
&ropb.ReleasePlacement{
Index: 2,
Slot: 1,
InstanceId: 2,
},
},
}, nil
}
func (t *testOrg) getRecord(ctx context.Context, iid int32) (*rcpb.Record, error) {
if iid == 2 {
if t.failHigh {
return nil, fmt.Errorf("Built to fail")
}
return &rcpb.Record{
Release: &gdpb.Release{
Title: "Last",
},
}, nil
}
if t.failLow {
return nil, fmt.Errorf("Built to fail")
}
return &rcpb.Record{
Release: &gdpb.Release{
Title: "First",
Artists: []*gdpb.Artist{
&gdpb.Artist{
Name: "Artist",
},
},
},
}, nil
}
func TestIntegration(t *testing.T) {
s := InitTest()
_, err := s.Receive(context.Background(), &rpb.ReceiveRequest{})
if err != nil {
t.Fatalf("Unable to run basic process: %v", err)
}
if len(s.lastprint) != 8 {
t.Fatalf("Not the right number of lines: %v", len(s.lastprint))
}
if s.lastprint[0] != "Records" ||
s.lastprint[1] != " Slot 1:" ||
s.lastprint[2] != " Artist - First" ||
s.lastprint[3] != " Unknown - Last" {
t.Errorf("Bad print request: %v", s.lastprint)
}
}
func TestFailLists(t *testing.T) {
s := InitTest()
s.org = &testOrg{failLists: true}
_, err := s.Receive(context.Background(), &rpb.ReceiveRequest{})
if err == nil {
t.Fatalf("Failure did not fail")
}
}
func TestFailList(t *testing.T) {
s := InitTest()
s.org = &testOrg{failList: true}
_, err := s.Receive(context.Background(), &rpb.ReceiveRequest{})
if err == nil {
t.Fatalf("Failure did not fail")
}
}
func TestFailListLow(t *testing.T) {
s := InitTest()
s.org = &testOrg{failLow: true}
_, err := s.Receive(context.Background(), &rpb.ReceiveRequest{})
if err == nil {
t.Fatalf("Failure did not fail")
}
}
func TestFailListHigh(t *testing.T) {
s := InitTest()
s.org = &testOrg{failHigh: true}
_, err := s.Receive(context.Background(), &rpb.ReceiveRequest{})
if err == nil {
t.Fatalf("Failure did not fail")
}
}