9
9
"net/http"
10
10
"net/url"
11
11
"os"
12
+ "strings"
12
13
"testing"
13
14
14
15
"github.com/pact-foundation/pact-go/v2/consumer"
@@ -21,45 +22,47 @@ import (
21
22
var dir , _ = os .Getwd ()
22
23
23
24
func TestAvroHTTP (t * testing.T ) {
24
- mockProvider , err := consumer .NewV4Pact (consumer.MockHTTPProviderConfig {
25
- Consumer : "AvroConsumer" ,
26
- Provider : "AvroProvider" ,
27
- PactDir : filepath .ToSlash (fmt .Sprintf ("%s/../pacts" , dir )),
28
- })
29
- assert .NoError (t , err )
25
+ if os .Getenv ("SKIP_PLUGIN_AVRO" ) != "1" {
26
+ mockProvider , err := consumer .NewV4Pact (consumer.MockHTTPProviderConfig {
27
+ Consumer : "AvroConsumer" ,
28
+ Provider : "AvroProvider" ,
29
+ PactDir : filepath .ToSlash (fmt .Sprintf ("%s/../pacts" , dir )),
30
+ })
31
+ assert .NoError (t , err )
30
32
31
- dir , _ := os .Getwd ()
32
- path := fmt .Sprintf ("%s/user.avsc" , dir )
33
+ dir , _ := os .Getwd ()
34
+ path := fmt .Sprintf ("%s/user.avsc" , strings . ReplaceAll ( dir , " \\ " , "/" ) )
33
35
34
- avroResponse := `{
36
+ avroResponse := `{
35
37
"pact:avro": "` + path + `",
36
38
"pact:record-name": "User",
37
39
"pact:content-type": "avro/binary",
38
40
"id": "matching(number, 1)",
39
41
"username": "notEmpty('matt')"
40
42
}`
41
43
42
- // Set up our expected interactions.
43
- err = mockProvider .
44
- AddInteraction ().
45
- UponReceiving ("A request to do get some Avro stuff" ).
46
- UsingPlugin (consumer.PluginConfig {
47
- Plugin : "avro" ,
48
- Version : "0.0.5" ,
49
- }).
50
- WithRequest ("GET" , "/avro" ).
51
- WillRespondWith (200 , func (res * consumer.V4InteractionWithPluginResponseBuilder ) {
52
- res .PluginContents ("avro/binary" , avroResponse )
53
- }).
54
- ExecuteTest (t , func (msc consumer.MockServerConfig ) error {
55
- resp , err := callServiceHTTP (msc )
56
-
57
- assert .Equal (t , int64 (1 ), resp .ID )
58
- assert .Equal (t , "matt" , resp .Username ) // ??????!
59
-
60
- return err
61
- })
62
- assert .NoError (t , err )
44
+ // Set up our expected interactions.
45
+ err = mockProvider .
46
+ AddInteraction ().
47
+ UponReceiving ("A request to do get some Avro stuff" ).
48
+ UsingPlugin (consumer.PluginConfig {
49
+ Plugin : "avro" ,
50
+ Version : "0.0.5" ,
51
+ }).
52
+ WithRequest ("GET" , "/avro" ).
53
+ WillRespondWith (200 , func (res * consumer.V4InteractionWithPluginResponseBuilder ) {
54
+ res .PluginContents ("avro/binary" , avroResponse )
55
+ }).
56
+ ExecuteTest (t , func (msc consumer.MockServerConfig ) error {
57
+ resp , err := callServiceHTTP (msc )
58
+
59
+ assert .Equal (t , int64 (1 ), resp .ID )
60
+ assert .Equal (t , "matt" , resp .Username ) // ??????!
61
+
62
+ return err
63
+ })
64
+ assert .NoError (t , err )
65
+ }
63
66
}
64
67
65
68
func callServiceHTTP (msc consumer.MockServerConfig ) (* User , error ) {
0 commit comments