Skip to content

Commit

Permalink
chore: remove dead / commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jul 10, 2023
1 parent 9f275ea commit 55c1356
Showing 1 changed file with 0 additions and 163 deletions.
163 changes: 0 additions & 163 deletions message/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,172 +11,11 @@ import (
"github.com/pact-foundation/pact-go/v2/proxy"
)

// VerifyMessageProviderRaw runs provider message verification.
//
// A Message Producer is analagous to Consumer in the HTTP Interaction model.
// It is the initiator of an interaction, and expects something on the other end
// of the interaction to respond - just in this case, not immediately.
// func (v *Verifier) verifyMessageProviderRaw(request VerifyMessageRequest, writer outputWriter) error {
// // request.handle = native.NewVerifier("pact-go", command.Version)

// err := v.validateConfig()

// if err != nil {
// return err
// }

// // Starts the message wrapper API with hooks back to the message handlers
// // This maps the 'description' field of a message pact, to a function handler
// // that will implement the message producer. This function must return an object and optionally
// // and error. The object will be marshalled to JSON for comparison.
// mux := http.NewServeMux()

// port, err := utils.GetFreePort()
// if err != nil {
// return fmt.Errorf("unable to allocate a port for verification: %v", err)
// }

// // Construct verifier request
// verificationRequest := provider.VerifyRequest{
// ProviderBaseURL: fmt.Sprintf("http://localhost:%d", port),
// PactURLs: request.PactURLs,
// PactFiles: request.PactFiles,
// PactDirs: request.PactDirs,
// BrokerURL: request.BrokerURL,
// Tags: request.Tags,
// BrokerUsername: request.BrokerUsername,
// BrokerPassword: request.BrokerPassword,
// BrokerToken: request.BrokerToken,
// PublishVerificationResults: request.PublishVerificationResults,
// ProviderVersion: request.ProviderVersion,
// Provider: request.Provider,
// ProviderTags: request.ProviderTags,
// // CustomProviderHeaders: request.CustomProviderHeaders,
// ConsumerVersionSelectors: request.ConsumerVersionSelectors,
// EnablePending: request.EnablePending,
// FailIfNoPactsFound: request.FailIfNoPactsFound,
// IncludeWIPPactsSince: request.IncludeWIPPactsSince,
// ProviderStatesSetupURL: fmt.Sprintf("http://localhost:%d%s", port, providerStatesSetupPath),
// }

// mux.HandleFunc(providerStatesSetupPath, messageStateHandler(request.StateHandlers))
// mux.HandleFunc("/", messageVerificationHandler(request.MessageHandlers))

// ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
// if err != nil {
// log.Fatal(err)
// }
// defer ln.Close()

// log.Printf("[DEBUG] API handler starting: port %d (%s)", port, ln.Addr())
// go http.Serve(ln, mux)

// portErr := provider.WaitForPort(port, "tcp", "localhost", v.ClientTimeout,
// fmt.Sprintf(`Timed out waiting for pact proxy on port %d - check for errors`, port))

// if portErr != nil {
// log.Fatal("Error:", err)
// return portErr
// }

// log.Println("[DEBUG] pact provider verification")

// return verificationRequest.Verify(writer)
// }

type messageVerificationHandlerRequest struct {
Description string `json:"description"`
States []models.ProviderState `json:"providerStates"`
}

// type messageStateHandlerRequest struct {
// State string `json:"state"`
// Params map[string]interface{} `json:"params"`
// Action string `json:"action"`
// }

// TODO: is this different to HTTP?
// var MessageStateHandler = func(stateHandlers models.StateHandlers) http.HandlerFunc {
// return func(w http.ResponseWriter, r *http.Request) {
// w.Header().Set("Content-Type", "application/json; charset=utf-8")

// log.Printf("[TRACE] message state handler %+v", r)

// // Extract message
// var message messageStateHandlerRequest
// body, err := ioutil.ReadAll(r.Body)
// r.Body.Close()
// log.Printf("[TRACE] message state handler received request: %s, %s", string(body), r.URL.Path)

// if err != nil {
// w.WriteHeader(http.StatusBadRequest)
// return
// }

// err = json.Unmarshal(body, &message)

// if err != nil {
// w.WriteHeader(http.StatusBadRequest)
// return
// }

// log.Println("[TRACE] message verification - setting up state for message", message)
// sf, stateFound := stateHandlers[message.State]

// if !stateFound {
// log.Printf("[WARN] state handler not found for state: %v", message.State)
// } else {
// // Execute state handler
// res, err := sf(message.Action == "setup", models.ProviderState{
// Name: message.State,
// Parameters: message.Params,
// })

// if err != nil {
// log.Printf("[WARN] state handler for '%v' return error: %v", message.State, err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }

// // Return provider state values for generator
// if res != nil {
// resBody, err := json.Marshal(res)

// if err != nil {
// log.Printf("[ERROR] state handler for '%v' errored: %v", message.State, err)
// w.WriteHeader(http.StatusInternalServerError)

// return
// }

// log.Printf("[INFO] state handler for '%v' finished", message.State)
// w.Write(resBody)
// }

// }

// // w.WriteHeader(http.StatusOK)
// }
// }

type messageWithMetadata struct {
Contents []byte `json:"pactMessageContents"`
Metadata Metadata `json:"pactMessageMetadata"`
}

func appendMetadataToResponse(res interface{}, metadata Metadata) ([]byte, error) {
data, err := json.Marshal(res)
if err != nil {
return nil, err
}
withMetadata := &messageWithMetadata{
Contents: data,
Metadata: metadata,
}

return json.Marshal(withMetadata)
}

var PACT_MESSAGE_METADATA_HEADER = "PACT_MESSAGE_METADATA"
var PACT_MESSAGE_METADATA_HEADER2 = "Pact-Message-Metadata"

Expand Down Expand Up @@ -268,5 +107,3 @@ func CreateMessageHandler(messageHandlers Handlers) proxy.Middleware {
})
}
}

const providerStatesSetupPath = "/__setup"

0 comments on commit 55c1356

Please sign in to comment.