Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for array of interface implementations #14

Merged
merged 4 commits into from
Dec 20, 2018
Merged

Conversation

hwshadow
Copy link
Contributor

@hwshadow hwshadow commented Dec 20, 2018

I ran into what I think is a bug in sheriff. It doesn't seem to be able to handle arrays of interface implementations, I added code and a test case which appears to confirm this.

Regards

type InterfaceableBeta struct {
	Integer int    `json:"integer" groups:"safe"`
	Secret  string `json:"secret"`
}
type InterfaceableCharlie struct {
	Integer int    `json:"integer" groups:"safe"`
	Secret  string `json:"secret"`
}
type ArrayOfInterfaceable []CanHazInterface
type CanHazInterface interface {
}
type InterfacerAlpha struct {
	Plaintext     string               `json:"plaintext" groups:"safe"`
	Secret        string               `json:"secret"`
	Nested        InterfaceableBeta    `json:"nested" groups:"safe"`
	Interfaceable ArrayOfInterfaceable `json:"interfaceable" groups:"safe"`
}
	a := InterfacerAlpha{
		"I am plaintext",
		"I am a secret",
		InterfaceableBeta{
			100,
			"Still a secret",
		},
		ArrayOfInterfaceable{
			InterfaceableBeta{200, "Still a secret good"},
			InterfaceableCharlie{300, "Still a secret exellect"},
		}}
--- FAIL: TestMarshal_ArrayOfInterfaceable (0.00s)
	sheriff_test.go:459:
			Error Trace:	sheriff_test.go:459
			Error:      	Not equal:
			            	expected: "{\"interfaceable\":[{\"integer\":200},{\"integer\":300}],\"nested\":{\"integer\":100},\"plaintext\":\"I am plaintext\"}"
			            	actual  : "{\"interfaceable\":[{\"integer\":200,\"secret\":\"Still a secret good\"},{\"integer\":300,\"secret\":\"Still a secret exellect\"}],\"nested\":{\"integer\":100},\"plaintext\":\"I am plaintext\"}"

			            	Diff:
			            	--- Expected
			            	+++ Actual
			            	@@ -1 +1 @@
			            	-{"interfaceable":[{"integer":200},{"integer":300}],"nested":{"integer":100},"plaintext":"I am plaintext"}
			            	+{"interfaceable":[{"integer":200,"secret":"Still a secret good"},{"integer":300,"secret":"Still a secret exellect"}],"nested":{"integer":100},"plaintext":"I am plaintext"}
			Test:       	TestMarshal_ArrayOfInterfaceable

see c0b2fa2 for the struct that showcases the bug.

Support for interface type
Test cases for the previous change
spell check and style
@hwshadow hwshadow changed the title Fix for array of interfaces Fix for array of interface implementations Dec 20, 2018
@coveralls
Copy link

coveralls commented Dec 20, 2018

Coverage Status

Coverage remained the same at 82.353% when pulling 1502d8d on hwshadow:master into c385ca6 on liip:master.

Copy link
Collaborator

@mweibel mweibel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix, that looks decent. Just a small nitpick but otherwise that's all fine.
I'll take care about the travis CI issues with older go versions afterwards.

sheriff.go Outdated Show resolved Hide resolved
style update, no functional change
@mweibel mweibel merged commit bb4d97c into liip:master Dec 20, 2018
@mweibel
Copy link
Collaborator

mweibel commented Dec 20, 2018

Thanks! that's merged in.

@hwshadow
Copy link
Contributor Author

hwshadow commented Dec 20, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants