forked from tleyden/open-ocr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ocr_http_handler_test.go
69 lines (53 loc) · 1.59 KB
/
ocr_http_handler_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
package ocrworker
import (
"bytes"
"encoding/json"
"net/http"
"testing"
"time"
"github.com/rs/zerolog/log"
"github.com/couchbaselabs/go.assert"
)
// This test assumes that rabbit mq is running
func DisabledTestOcrHttpHandlerIntegration(t *testing.T) {
rabbitConfig := rabbitConfigForTests()
workerConfig := workerConfigForTests()
err := spawnOcrWorker(&workerConfig)
if err != nil {
log.Panic().Msg("Could not spawn ocr worker")
}
// add a handler to serve up an image from the filesystem.
http.HandleFunc("/img", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "refactoring.png")
})
http.Handle("/ocr", NewOcrHttpHandler(&rabbitConfig))
go http.ListenAndServe(":8081", nil)
log.Info().Str("component", "TEST").Msg("test1")
ocrRequest := OcrRequest{
ImgUrl: "http://localhost:8081/img",
EngineType: EngineMock,
}
jsonBytes, err := json.Marshal(ocrRequest)
if err != nil {
log.Panic().Msg("Could not marshal OcrRequest")
}
reader := bytes.NewReader(jsonBytes)
resp, err := http.Post("http://localhost:8081/ocr", "application/json", reader)
assert.True(t, err == nil)
log.Info().Str("component", "TEST").Interface("resp", resp)
// connect to it via http client
log.Info().Str("component", "TEST").Msg("Sleep for 60s")
time.Sleep(time.Second * 60)
// make sure get expected result
assert.True(t, true)
}
func spawnOcrWorker(workerConfig *WorkerConfig) error {
// kick off a worker
// this would normally happen on a different machine ..
ocrWorker, err := NewOcrRpcWorker(workerConfig)
if err != nil {
return err
}
ocrWorker.Run()
return nil
}