Skip to content

expose Token.Raw unmarshalling to allow for easier testing #197

Closed as not planned
@jmhodges

Description

@jmhodges

This is a nice-to-have ticket.

So, the oauth2.Token that Slack returns contains data found in Token.Extra. I convert that oauth2.Token to a nicer to use Token-like struct by pulling the data out of Extra and checking the types and so on.

However, in order to test that, I can't just take the example response from their OAuth docs, json.Unmarshal it into the oauth2.Token and then run my conversion func on the returned oauth2.Token. That's because the oauth2.Token's raw field isn't set by simply unmarshalling the JSON and the conversion func using Extra will fail to see the data set. Instead, the raw field is set up by code inside a package internal to the oauth2 that the test code can't reach but is used by oauth2.Config.Exchange.

This is a bummer because that means my tests for deserialization need explicit calls to SetExtra in order to test the behavior correctly instead of being able to reuse the same string of testdata I was using for testing serialization.

It seems like moving an explicit UnmarshalJSON on to oauth2.Token would help. The code that's in the internal package would remain private, but the JSON unmarshalling would be easier to manage.

But maybe there was a reason for not having done so already that I'm not aware of. Let me know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions