-
Notifications
You must be signed in to change notification settings - Fork 12
/
client_test.go
74 lines (62 loc) · 1.63 KB
/
client_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
package pigeon
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
vision "google.golang.org/api/vision/v1"
)
func TestClient(t *testing.T) {
os.Clearenv()
assert := assert.New(t)
cfg := NewConfig()
client, err := New(cfg)
assert.Nil(client)
assert.Error(err)
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "credentials/example.json")
cfg = NewConfig()
client, err = New(cfg)
assert.NotNil(client)
assert.NoError(err)
assert.NotNil(client.service)
assert.NotNil(client.ImagesService())
}
func TestNewAnnotateImageRequest(t *testing.T) {
assert := assert.New(t)
var (
req *vision.AnnotateImageRequest
err error
)
const (
gcsImageURI = "gs://bucket/sample.png"
fp = "assets/lenna.jpg"
imageURI = "https://httpbin.org/image/jpeg"
imageURINoExists = "https://httpbin.org/image/jpeg/none"
)
features := NewFeature(LabelDetection)
client, err := New(nil)
assert.NoError(err)
// GCS
req, err = client.NewAnnotateImageRequest(gcsImageURI, features)
assert.NoError(err)
if assert.NotNil(req) {
assert.Equal("", req.Image.Content)
assert.Equal(gcsImageURI, req.Image.Source.GcsImageUri)
}
// Filepath
req, err = client.NewAnnotateImageRequest(fp, features)
assert.NoError(err)
if assert.NotNil(req) {
assert.NotEqual("", req.Image.Content)
assert.Nil(req.Image.Source)
}
// Image URI
req, err = client.NewAnnotateImageRequest(imageURI, features)
assert.NoError(err)
if assert.NotNil(req) {
assert.NotEqual("", req.Image.Content)
assert.Nil(req.Image.Source)
}
req, err = client.NewAnnotateImageRequest(imageURINoExists, features)
assert.Error(err)
assert.Nil(req)
}