This repository has been archived by the owner on Nov 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipeline_test.go
72 lines (60 loc) · 1.6 KB
/
pipeline_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
package processor
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func TestPipelineFixture(t *testing.T) {
gunit.Run(new(PipelineFixture), t)
}
type PipelineFixture struct {
*gunit.Fixture
reader *ReadWriteSpyBuffer
writer *ReadWriteSpyBuffer
client *IntegrationHTTPClient
pipeline *Pipeline
}
func (this *PipelineFixture) Setup() {
this.reader = NewReadWriteSpyBuffer("")
this.writer = NewReadWriteSpyBuffer("")
this.client = &IntegrationHTTPClient{}
this.pipeline = NewPipeline(ioutil.NopCloser(this.reader), this.writer, this.client, 2)
}
func (this *PipelineFixture) LongTestPipeline() {
fmt.Fprintln(this.reader, "Street1,City,State,ZIPCode")
fmt.Fprintln(this.reader, "A,B,C,D")
fmt.Fprintln(this.reader, "A,B,C,D")
err := this.pipeline.Process()
this.So(this.writer.String(), should.Equal,
"Status,DeliveryLine1,LastLine,City,State,ZIPCode\n"+
"Deliverable,AA,BB,CC,DD,EE\n"+
"Deliverable,AA,BB,CC,DD,EE\n")
this.So(err, should.BeNil)
}
type IntegrationHTTPClient struct{}
func (this *IntegrationHTTPClient) Do(request *http.Request) (*http.Response, error) {
return &http.Response{
Body: NewReadWriteSpyBuffer(integrationJSONOutput),
StatusCode: http.StatusOK,
}, nil
}
const integrationJSONOutput = `
[
{
"delivery_line_1": "AA",
"last_line": "BB",
"components": {
"city_name": "CC",
"state_abbreviation": "DD",
"zipcode": "EE"
},
"analysis": {
"dpv_match_code": "Y",
"dpv_vacant": "N",
"active": "Y"
}
}
]`