-
Notifications
You must be signed in to change notification settings - Fork 1
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
Don't Crash on Map Update #22
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
defmodule ChannelSpec.SocketTest.LotsOfRefsSchema do | ||
@moduledoc """ | ||
This specific setup causes `__unresolved_refs` to get into a state that makes the schema | ||
fail to compile. The PR in which this file was introduced switches from `Map.update!` to | ||
`Map.update` with a default and generates a valid schema. | ||
""" | ||
|
||
defmodule Base do | ||
@behaviour ChannelSpec.Schema | ||
|
||
def schema() do | ||
%{ | ||
type: :object, | ||
properties: %{ | ||
foo: %{"$ref": ChannelSpec.SocketTest.LotsOfRefsSchema.Foo}, | ||
bar: %{type: :array, items: [%{"$ref": ChannelSpec.SocketTest.LotsOfRefsSchema.Bar}]}, | ||
flim: %{ type: :array, items: [%{"$ref": ChannelSpec.SocketTest.LotsOfRefsSchema.Flim}] } | ||
}, | ||
additionalProperties: false | ||
} | ||
end | ||
end | ||
|
||
defmodule Flim do | ||
@behaviour ChannelSpec.Schema | ||
|
||
def schema() do | ||
%{ | ||
type: :object, | ||
properties: %{ | ||
flam: %{ | ||
oneOf: [ | ||
%{type: :null}, | ||
%{"$ref": ChannelSpec.SocketTest.LotsOfRefsSchema.Flam} | ||
] | ||
} | ||
}, | ||
additionalProperties: false | ||
} | ||
end | ||
end | ||
|
||
defmodule Foo do | ||
def schema() do | ||
%{ oneOf: [ %{type: :null}, %{type: :string} ] } | ||
end | ||
end | ||
|
||
defmodule Bar do | ||
def schema() do | ||
%{type: :object, properties: %{baz: %{"$ref": ChannelSpec.SocketTest.LotsOfRefsSchema.Baz}}} | ||
end | ||
end | ||
|
||
defmodule Baz do | ||
def schema() do | ||
%{oneOf: [%{type: :string}, %{type: :null}]} | ||
end | ||
end | ||
end | ||
|
||
defmodule ChannelSpec.SocketTest.LotsOfRefsSchema.Flam do | ||
def schema() do | ||
%{ | ||
type: :object, | ||
properties: %{ | ||
whatever: %{ | ||
type: :array, | ||
items: [ %{ type: :array, items: [%{type: :string}] } | ||
] | ||
} | ||
}, | ||
additionalProperties: false | ||
} | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest creating modules in-place in the tests instead of helper modules, like here: https://github.com/felt/channel_spec/blob/main/test/channel_spec/socket_test.exs#L51-L69
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 ! Any specific reason? I broke it out since it was 75+ lines of code and that seemed like a lot to put in a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it easier to have the whole setup in the test itself in macro heavy code to both have the full picture and making sure unrelated code is not affecting the generated code.
It's a matter of preference, but macros don't always produce helpful stacktraces so I'd rather avoid sharing modules in tests, and at least have the certainty that I know exactly which test is causing issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. However, the nested nature of the setup for this test doesn't allow us to make nested modules with refs. Example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm that's a good point. You could move the
defmodule Foo
insidedefmodule Base
and use__MODULE__.Foo
instead, or not nest them(you'd repeat.LotsofRefsSchema
quite a bit) but it's a good point still.I'm fine with either approach seeing a helper module may be easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a commit. I was able to get it to work with a
@mod_base Module.split(__MODULE__) |> Enum.drop(-1) |> Module.concat()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice trick! 💜