Skip to content

Commit 81c20d0

Browse files
authored
Revert "Feat/add external reference (#592)"
This reverts commit 67d51c1.
1 parent 67d51c1 commit 81c20d0

28 files changed

Lines changed: 439 additions & 447 deletions

command/root_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func captureOutput(action func()) string {
5454

5555
action()
5656

57-
_ = w.Close()
57+
w.Close()
5858
out, _ := io.ReadAll(r)
5959
os.Stderr = rescueStderr
6060

consumer/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (p *httpMockProvider) displayMismatches(t *testing.T, mismatches []native.M
201201
fmt.Println("\t\tDiff:")
202202
log.Println("[INFO] pact validation failed, errors: ")
203203
for _, m := range mismatches {
204-
formattedRequest := fmt.Sprintf("%s %s", m.Method, m.Path)
204+
formattedRequest := fmt.Sprintf("%s %s", m.Request.Method, m.Request.Path)
205205
switch m.Type {
206206
case "missing-request":
207207
fmt.Printf("\t\texpected: \t%s (Expected request that was not received)\n", formattedRequest)

consumer/http_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewV2Pact(config MockHTTPProviderConfig) (*V2HTTPMockProvider, error) {
3535
// AddInteraction to the pact
3636
func (p *V2HTTPMockProvider) AddInteraction() *V2UnconfiguredInteraction {
3737
log.Println("[DEBUG] pact add V2 interaction")
38-
interaction := p.mockserver.NewInteraction("")
38+
interaction := p.httpMockProvider.mockserver.NewInteraction("")
3939

4040
i := &V2UnconfiguredInteraction{
4141
interaction: &Interaction{

consumer/http_v3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewV3Pact(config MockHTTPProviderConfig) (*V3HTTPMockProvider, error) {
3535
// AddInteraction to the pact
3636
func (p *V3HTTPMockProvider) AddInteraction() *V3UnconfiguredInteraction {
3737
log.Println("[DEBUG] pact add V3 interaction")
38-
interaction := p.mockserver.NewInteraction("")
38+
interaction := p.httpMockProvider.mockserver.NewInteraction("")
3939

4040
i := &V3UnconfiguredInteraction{
4141
interaction: &Interaction{

consumer/http_v4.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewV4Pact(config MockHTTPProviderConfig) (*V4HTTPMockProvider, error) {
3636
// AddInteraction to the pact
3737
func (p *V4HTTPMockProvider) AddInteraction() *V4UnconfiguredInteraction {
3838
log.Println("[DEBUG] pact add V4 interaction")
39-
interaction := p.mockserver.NewInteraction("")
39+
interaction := p.httpMockProvider.mockserver.NewInteraction("")
4040

4141
i := &V4UnconfiguredInteraction{
4242
interaction: &Interaction{
@@ -92,15 +92,6 @@ func (i *V4UnconfiguredInteraction) UponReceiving(description string) *V4Unconfi
9292
return i
9393
}
9494

95-
// AddExternalReference records a reference to an external resource (such as a ticket or
96-
// pull request) against the interaction. References appear under
97-
// comments.references[group][name] in the Pact file. May be called multiple times.
98-
func (i *V4UnconfiguredInteraction) AddExternalReference(group, name, value string) *V4UnconfiguredInteraction {
99-
i.interaction.interaction.WithReference(group, name, value)
100-
101-
return i
102-
}
103-
10495
// WithRequest provides a builder for the expected request
10596
func (i *V4UnconfiguredInteraction) WithCompleteRequest(request Request) *V4InteractionWithCompleteRequest {
10697
i.interaction.WithCompleteRequest(request)

consumer/http_v4_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package consumer
22

33
import (
44
"fmt"
5-
"net/http"
65
"os"
76
"strings"
87
"testing"
@@ -86,25 +85,6 @@ func TestHttpV4TypeSystem(t *testing.T) {
8685

8786
}
8887

89-
func TestV4HTTPAddExternalReference(t *testing.T) {
90-
p, err := NewV4Pact(MockHTTPProviderConfig{
91-
Consumer: "consumer",
92-
Provider: "provider",
93-
})
94-
assert.NoError(t, err)
95-
96-
err = p.AddInteraction().
97-
UponReceiving("a request with an external reference").
98-
AddExternalReference("Jira", "TICKET-123", "https://jira.example.com/browse/TICKET-123").
99-
WithRequest("GET", "/", func(b *V4RequestBuilder) {}).
100-
WillRespondWith(200, func(b *V4ResponseBuilder) {}).
101-
ExecuteTest(t, func(msc MockServerConfig) error {
102-
_, err := http.Get(fmt.Sprintf("http://%s:%d/", msc.Host, msc.Port))
103-
return err
104-
})
105-
assert.NoError(t, err)
106-
}
107-
10888
var Like = matchers.Like
10989
var EachLike = matchers.EachLike
11090
var Term = matchers.Term

examples/avro/codec.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package avro
22

33
import (
4+
45
"os"
5-
66
"github.com/linkedin/goavro/v2"
77
)
88

9-
//nolint:unused // Retained as a reusable helper for the example package.
109
func getCodec() *goavro.Codec {
1110
schema, err := os.ReadFile("user.avsc")
1211
if err != nil {

examples/grpc/routeguide/server/server.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ import (
4040
"github.com/pact-foundation/pact-go/v2/examples/grpc/routeguide/data"
4141
"google.golang.org/grpc/codes"
4242
"google.golang.org/grpc/credentials"
43-
"google.golang.org/grpc/status"
44-
"google.golang.org/protobuf/proto"
43+
"google.golang.org/grpc/status"
44+
45+
"github.com/golang/protobuf/proto"
4546

4647
pb "github.com/pact-foundation/pact-go/v2/examples/grpc/routeguide"
4748
)
@@ -54,15 +55,6 @@ var (
5455
port = flag.Int("port", 50051, "The server port")
5556
)
5657

57-
// Keep example flags/entrypoint available for standalone usage.
58-
var (
59-
_ = tls
60-
_ = certFile
61-
_ = keyFile
62-
_ = port
63-
_ = main
64-
)
65-
6658
type routeGuideServer struct {
6759
pb.UnimplementedRouteGuideServer
6860
savedFeatures []*pb.Feature // read-only after initialized
@@ -255,9 +247,7 @@ func main() {
255247
}
256248
grpcServer := grpc.NewServer(opts...)
257249
pb.RegisterRouteGuideServer(grpcServer, NewServer())
258-
if err := grpcServer.Serve(lis); err != nil {
259-
log.Fatalf("failed to serve: %v", err)
260-
}
250+
grpcServer.Serve(lis)
261251
}
262252

263253
// exampleData is a copy of testdata/route_guide_db.json. It's to avoid

installer/installer.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ var setMacOSInstallName = func(file string) error {
302302
return fmt.Errorf("error setting install name on pact lib: %s", err)
303303
}
304304

305-
log.Println("[DEBUG] output from command", string(stdoutStderr))
305+
log.Println("[DEBUG] output from command", stdoutStderr)
306306

307307
return err
308308
}
@@ -388,7 +388,7 @@ const (
388388
var packages = map[string]packageInfo{
389389
FFIPackage: {
390390
libName: "libpact_ffi",
391-
version: "0.5.6",
391+
version: "0.4.28",
392392
semverRange: ">= 0.4.0, < 1.0.0",
393393
},
394394
}
@@ -417,17 +417,13 @@ func (d *defaultDownloader) download(src string, dst string) error {
417417
if err != nil {
418418
return fmt.Errorf("failed to create output file; %w", err)
419419
}
420-
defer func() {
421-
_ = f.Close()
422-
}()
420+
defer f.Close()
423421

424422
resp, err := http.Get(src)
425423
if err != nil {
426424
return fmt.Errorf("failed http call to %s; %w", src, err)
427425
}
428-
defer func() {
429-
_ = resp.Body.Close()
430-
}()
426+
defer resp.Body.Close()
431427

432428
archive, err := gzip.NewReader(resp.Body)
433429
if err != nil {
@@ -527,9 +523,7 @@ func (d *defaultHasher) hash(src string) (string, error) {
527523
if err != nil {
528524
return "", err
529525
}
530-
defer func() {
531-
_ = f.Close()
532-
}()
526+
defer f.Close()
533527

534528
h := md5.New()
535529
if _, err := io.Copy(h, f); err != nil {

internal/native/message_server.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (m *Message) WithContents(part interactionPart, contentType string, body []
232232
defer free(cHeader)
233233

234234
cBody := C.CString(string(body))
235-
defer free(cBody)
235+
defer free(cBody)
236236

237237
res := C.pactffi_with_body(m.handle, C.int(part), cHeader, cBody)
238238
log.Println("[DEBUG] response from pactffi_interaction_contents", (bool(res)))
@@ -264,7 +264,7 @@ func (m *MessageServer) UsingPlugin(pluginName string, pluginVersion string) err
264264
return ErrHandleNotFound
265265
default:
266266
if res != 0 {
267-
return fmt.Errorf("an unknown error (code: %v) occurred when adding a plugin for the test. Received error code", res)
267+
return fmt.Errorf("an unknown error (code: %v) occurred when adding a plugin for the test. Received error code:", res)
268268
}
269269
}
270270

@@ -302,7 +302,7 @@ func (m *Message) WithPluginInteractionContents(part interactionPart, contentTyp
302302
return ErrPluginSpecificError
303303
default:
304304
if res != 0 {
305-
return fmt.Errorf("an unknown error (code: %v) occurred when adding a plugin for the test. Received error code", res)
305+
return fmt.Errorf("an unknown error (code: %v) occurred when adding a plugin for the test. Received error code:", res)
306306
}
307307
}
308308

@@ -543,7 +543,10 @@ func (m *MessageServer) WritePactFile(dir string, overwrite bool) error {
543543
cDir := C.CString(dir)
544544
defer free(cDir)
545545

546-
overwritePact := overwrite
546+
overwritePact := false
547+
if overwrite {
548+
overwritePact = true
549+
}
547550

548551
res := int(C.pactffi_write_message_pact_file(m.messagePact.handle, cDir, C.bool(overwritePact)))
549552

@@ -569,7 +572,10 @@ func (m *MessageServer) WritePactFileForServer(port int, dir string, overwrite b
569572
cDir := C.CString(dir)
570573
defer free(cDir)
571574

572-
overwritePact := overwrite
575+
overwritePact := false
576+
if overwrite {
577+
overwritePact = true
578+
}
573579

574580
res := int(C.pactffi_write_pact_file(C.int(port), cDir, C.bool(overwritePact)))
575581

@@ -590,19 +596,3 @@ func (m *MessageServer) WritePactFileForServer(port int, dir string, overwrite b
590596
return fmt.Errorf("an unknown error ocurred when writing to pact file")
591597
}
592598
}
593-
594-
// WithReference records an external reference (e.g. a ticket or pull request)
595-
// against the interaction. References are stored under comments.references[group][name]
596-
// in the Pact file. This is a V4-only feature.
597-
func (m *Message) WithReference(group, name, value string) *Message {
598-
cGroup := C.CString(group)
599-
defer free(cGroup)
600-
cName := C.CString(name)
601-
defer free(cName)
602-
cValue := C.CString(value)
603-
defer free(cValue)
604-
605-
C.pactffi_add_interaction_reference(m.handle, cGroup, cName, cValue)
606-
607-
return m
608-
}

0 commit comments

Comments
 (0)