15
15
package main
16
16
17
17
import (
18
- "bytes"
19
18
"context"
20
- "fmt"
21
19
"strings"
22
20
"testing"
23
21
22
+ vision "cloud.google.com/go/vision/apiv1"
23
+ "google.golang.org/api/option"
24
24
visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1"
25
25
)
26
26
@@ -29,10 +29,17 @@ func TestSetEndpoint(t *testing.T) {
29
29
30
30
const endpoint = "eu-vision.googleapis.com:443"
31
31
32
- client , err := setEndpoint (ctx , endpoint )
32
+ // Run the code sample to check for errors.
33
+ err := setEndpoint (endpoint )
33
34
if err != nil {
34
35
t .Fatalf ("setEndpoint: %v" , err )
35
36
}
37
+
38
+ // Since we're not returning the client from the code sample, we create an equivalent client here.
39
+ client , err := vision .NewImageAnnotatorClient (ctx , option .WithEndpoint (endpoint ))
40
+ if err != nil {
41
+ t .Fatalf ("NewImageAnnotatorClient: %v" , err )
42
+ }
36
43
defer client .Close ()
37
44
38
45
image := & visionpb.Image {
@@ -45,19 +52,11 @@ func TestSetEndpoint(t *testing.T) {
45
52
t .Fatalf ("DetectTexts: %v" , err )
46
53
}
47
54
48
- var buf bytes.Buffer
49
- fmt .Fprintf (& buf , "Texts:\n " )
50
- for _ , text := range texts {
51
- fmt .Fprintf (& buf , "%v\n " , text .GetDescription ())
52
- for _ , vertex := range text .GetBoundingPoly ().GetVertices () {
53
- fmt .Fprintf (& buf , " bounding vertex: %v, %v\n " , vertex .GetX (), vertex .GetY ())
54
- }
55
- }
56
-
57
- if got , want := buf .String (), "System" ; ! strings .Contains (got , want ) {
58
- t .Errorf ("setEndpoint got:\n ----\n %s----\n Want to contain:\n ----\n %s\n ----" , got , want )
55
+ text := texts [0 ]
56
+ if got , want := text .GetDescription (), "System" ; ! strings .Contains (got , want ) {
57
+ t .Errorf ("text.GetDescription() got:\n ----\n %s----\n Want to contain:\n ----\n %s\n ----" , got , want )
59
58
}
60
- if got , want := buf . String (), "bounding vertex:" ; ! strings . Contains ( got , want ) {
61
- t .Errorf ("setEndpoint got: \n ---- \n %s---- \n Want to contain: \n ---- \n %s \n ----" , got , want )
59
+ if len ( text . GetBoundingPoly (). GetVertices ()) == 0 {
60
+ t .Errorf ("text.GetBoundingPoly().getVertices() must have at least one vertex" )
62
61
}
63
62
}
0 commit comments