Comments (6)
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.
@thrawn01 it sounds too easy not to do
from mailgun-go.
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.
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.
@thrawn01 is this more easy now with the mock API you've made? Should this be implemented?
from mailgun-go.
We could expose the headers via a GetHeaders() call. I think that would do the trick.
from mailgun-go.
Related Issues (20)
- HTML Formatted Email with href Doesn't Work HOT 1
- Templates - Passing nested values as X-Mailgun-Variables HOT 1
- How to send LinkedResources? HOT 1
- AddAttachment not sending multiple attachments HOT 3
- ListMembers: vars duplicated on subsequent pages HOT 1
- Remove dependancy on Chi
- Make fields public in struct `mailgun.Message`. HOT 3
- SetDeliveryTime Ignored HOT 1
- Change response for `VerifyDomain` method from (string, error) to (DomainResponse, error) HOT 2
- How to convert json stored messages to url.Values HOT 1
- Make properties on Message struct publicly accessible HOT 2
- missing `result` in email validation response HOT 4
- VerifyAndReturnDomain is missing from the Mailgun interface
- Validate domain in mg.Send()
- Allow to use : in domain for testing HOT 2
- Inline image example should have img tag in html input HOT 1
- events.ClientInfo is missing the `bot` field HOT 2
- Add 'web_scheme' as a primary attribute to Domain HOT 3
- Set preferred reply method for mailing lists missing HOT 1
- [Feature Request] Add Send Time Optimization (STO) Feature HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailgun-go.