• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pact-foundation / pact-go / 10729838426

05 Sep 2024 11:30PM UTC coverage: 31.75% (+2.5%) from 29.294%
10729838426

Pull #455

github

YOU54F
ci(win): add PACT_LD_LIBRARY_PATH
Pull Request #455: Feat/purego

397 of 444 new or added lines in 5 files covered. (89.41%)

2 existing lines in 1 file now uncovered.

2045 of 6441 relevant lines covered (31.75%)

16.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.31
/internal/native/verifier.go
1
package native
2

3
import (
4
        "fmt"
5
        "log"
6

7
        "strings"
8
)
9

10
type Verifier struct {
11
        handle uintptr
12
}
13

14
func (v *Verifier) Verify(args []string) error {
12✔
15
        log.Println("[DEBUG] executing verifier FFI with args", args)
12✔
16
        result := pactffi_verify(strings.Join(args, "\n"))
12✔
17
        /// | Error | Description |
12✔
18
        /// |-------|-------------|
12✔
19
        /// | 1 | The verification process failed, see output for errors |
12✔
20
        /// | 2 | A null pointer was received |
12✔
21
        /// | 3 | The method panicked |
12✔
22
        switch int(result) {
12✔
23
        case 0:
×
24
                return nil
×
25
        case 1:
×
26
                return ErrVerifierFailed
×
27
        case 2:
×
28
                return ErrInvalidVerifierConfig
×
29
        case 3:
×
30
                return ErrVerifierPanic
×
31
        default:
12✔
32
                return fmt.Errorf("an unknown error (%d) ocurred when verifying the provider (this indicates a defect in the framework)", int(result))
12✔
33
        }
34
}
35

36
// // Version returns the current semver FFI interface version
37
// func (v *Verifier) Version() string {
38
//         return Version()
39
// }
40

41
var (
42
        // ErrVerifierPanic indicates a panic ocurred when invoking the verifier.
43
        ErrVerifierPanic = fmt.Errorf("a general panic occured when starting/invoking verifier (this indicates a defect in the framework)")
44

45
        // ErrInvalidVerifierConfig indicates an issue configuring the verifier
46
        ErrInvalidVerifierConfig = fmt.Errorf("configuration for the verifier was invalid and an unknown error occurred (this is most likely a defect in the framework)")
47

48
        //ErrVerifierFailed is the standard error if a verification failed (e.g. beacause the pact verification was not successful)
49
        ErrVerifierFailed = fmt.Errorf("the verifier failed to successfully verify the pacts, this indicates an issue with the provider API")
50
        //ErrVerifierFailedToRun indicates the verification process was unable to run
51
        ErrVerifierFailedToRun = fmt.Errorf("the verifier failed to execute (this is most likely a defect in the framework)")
52
)
53

54
func NewVerifier(name string, version string) *Verifier {
60✔
55
        h := pactffi_verifier_new_for_application(name, version)
60✔
56

60✔
57
        return &Verifier{
60✔
58
                handle: h,
60✔
59
        }
60✔
60
}
60✔
61

62
func (v *Verifier) Shutdown() {
12✔
63
        pactffi_verifier_shutdown(v.handle)
12✔
64
}
12✔
65

66
func (v *Verifier) SetProviderInfo(name string, scheme string, host string, port uint16, path string) {
12✔
67
        pactffi_verifier_set_provider_info(v.handle, name, scheme, host, port, path)
12✔
68
}
12✔
69

70
func (v *Verifier) AddTransport(protocol string, port uint16, path string, scheme string) {
×
71
        log.Println("[DEBUG] Adding transport with protocol:", protocol, "port:", port, "path:", path, "scheme:", scheme)
×
72

×
NEW
73
        pactffi_verifier_add_provider_transport(v.handle, protocol, port, path, scheme)
×
74
}
×
75

76
func (v *Verifier) SetFilterInfo(description string, state string, noState bool) {
×
NEW
77
        pactffi_verifier_set_filter_info(v.handle, description, state, boolToCInt(noState))
×
78
}
×
79

80
func (v *Verifier) SetProviderState(url string, teardown bool, body bool) {
×
NEW
81
        pactffi_verifier_set_provider_state(v.handle, url, boolToCInt(teardown), boolToCInt(body))
×
82
}
×
83

84
func (v *Verifier) SetVerificationOptions(disableSSLVerification bool, requestTimeout int64) {
×
85
        // TODO: this returns an int and therefore can error. We should have all of these functions return values??
×
NEW
86
        pactffi_verifier_set_verification_options(v.handle, boolToCInt(disableSSLVerification), uint64(requestTimeout))
×
87
}
×
88

89
func (v *Verifier) SetConsumerFilters(consumers []string) {
12✔
90
        pactffi_verifier_set_consumer_filters(v.handle, stringArrayToCByteArray(consumers), uint16(len(consumers)))
12✔
91
}
12✔
92

93
func (v *Verifier) AddCustomHeader(name string, value string) {
×
NEW
94
        pactffi_verifier_add_custom_header(v.handle, name, value)
×
95
}
×
96

97
func (v *Verifier) AddFileSource(file string) {
×
NEW
98
        pactffi_verifier_add_file_source(v.handle, file)
×
99
}
×
100

101
func (v *Verifier) AddDirectorySource(directory string) {
×
NEW
102
        pactffi_verifier_add_directory_source(v.handle, directory)
×
103
}
×
104

105
func (v *Verifier) AddURLSource(url string, username string, password string, token string) {
×
NEW
106
        pactffi_verifier_url_source(v.handle, url, username, password, token)
×
107
}
×
108

109
func (v *Verifier) BrokerSourceWithSelectors(url string, username string, password string, token string, enablePending bool, includeWipPactsSince string, providerTags []string, providerBranch string, selectors []string, consumerVersionTags []string) {
×
NEW
110
        pactffi_verifier_broker_source_with_selectors(v.handle, url, username, password, token, boolToCInt(enablePending), includeWipPactsSince, stringArrayToCByteArray(providerTags), uint16(len(providerTags)), providerBranch, stringArrayToCByteArray(selectors), uint16(len(selectors)), stringArrayToCByteArray(consumerVersionTags), uint16(len(consumerVersionTags)))
×
111
}
×
112

113
func (v *Verifier) SetPublishOptions(providerVersion string, buildUrl string, providerTags []string, providerBranch string) {
×
NEW
114
        pactffi_verifier_set_publish_options(v.handle, providerVersion, buildUrl, stringArrayToCByteArray(providerTags), uint16(len(providerTags)), providerBranch)
×
115
}
×
116

117
func (v *Verifier) Execute() error {
12✔
118
        // TODO: Validate
12✔
119
        result := pactffi_verifier_execute(v.handle)
12✔
120
        /// | Error | Description |
12✔
121
        /// |-------|-------------|
12✔
122
        /// | 1     | The verification process failed, see output for errors |
12✔
123
        switch int(result) {
12✔
124
        case 0:
12✔
125
                return nil
12✔
126
        case 1:
×
127
                return ErrVerifierFailed
×
128
        case 2:
×
129
                return ErrVerifierFailedToRun
×
130
        default:
×
131
                return fmt.Errorf("an unknown error (%d) ocurred when verifying the provider (this indicates a defect in the framework)", int(result))
×
132
        }
133
}
134

135
func (v *Verifier) SetNoPactsIsError(isError bool) {
×
NEW
136
        pactffi_verifier_set_no_pacts_is_error(v.handle, boolToCInt(isError))
×
137
}
×
138

139
func (v *Verifier) SetColoredOutput(isColoredOutput bool) {
×
NEW
140
        pactffi_verifier_set_coloured_output(v.handle, boolToCInt(isColoredOutput))
×
141
}
×
142

143
func stringArrayToCByteArray(inputs []string) []*byte {
12✔
144
        if len(inputs) == 0 {
12✔
145
                return nil
×
146
        }
×
147

148
        output := make([]*byte, len(inputs))
12✔
149

12✔
150
        for i, consumer := range inputs {
36✔
151
                output[i] = CString(consumer)
24✔
152
        }
24✔
153

154
        return ([]*byte)(output)
12✔
155
}
156

NEW
157
func boolToCInt(val bool) uint8 {
×
158
        if val {
×
NEW
159
                return uint8(1)
×
160
        }
×
NEW
161
        return uint8(0)
×
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc