Giter Club home page Giter Club logo

Comments (6)

krystalcode avatar krystalcode commented on July 20, 2024 1

I also have a similar scenario where I want to be able to test whether a message is created with the right information by my application e.g. from, to, subject, body etc. The problem is that all fields are private and can't be accessed by the test function. Using reflection might work, but it would more straightforward if getter functions were provided.

from mailgun-go.

mbanzon avatar mbanzon commented on July 20, 2024 1

@thrawn01 it sounds too easy not to do 😏

from mailgun-go.

tleyden avatar tleyden commented on July 20, 2024

Here's my workaround to introspect the headers field in case it's useful for anyone:


func (mmg *MockMailGun) getHeaderViaReflection(message *mailgun.Message, headerKey string) (string, error) {

    val := reflect.ValueOf(*message)
    headers := val.FieldByName("headers")

    switch headers.Kind() {
    case reflect.Map:
        for _, key := range headers.MapKeys() {
            mapVal := headers.MapIndex(key)
            switch mapVal.Kind() {
            case reflect.String:
                return fmt.Sprintf("%s", mapVal), nil
            default:
                return "error", fmt.Errorf("Unexpected type for value at key: %s", headerKey)
            }
        }

    default:
        return "error", fmt.Errorf("Unexpected type for mailgun message headers field")
    }

    return "error", fmt.Errorf("Did not find headerKey")

}

from mailgun-go.

mbanzon avatar mbanzon commented on July 20, 2024

Sorry for the long response time.

Glad you figured out how to get the information you needed.

Could this have been solved easier at the HTTP level?

from mailgun-go.

mbanzon avatar mbanzon commented on July 20, 2024

@thrawn01 is this more easy now with the mock API you've made? Should this be implemented?

from mailgun-go.

thrawn01 avatar thrawn01 commented on July 20, 2024

We could expose the headers via a GetHeaders() call. I think that would do the trick.

from mailgun-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.