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

Add URL and DomainName generators #17

Open
wfscheper opened this issue Oct 2, 2020 · 5 comments · May be fixed by #18
Open

Add URL and DomainName generators #17

wfscheper opened this issue Oct 2, 2020 · 5 comments · May be fixed by #18
Labels
enhancement New feature or request

Comments

@wfscheper
Copy link

Generating proper URLs is tricky, and seems like something a library like rapid should provide. The implementation in hypothesis seems like a good starting point, though the URL generator is limited to http(s) schemes.

@flyingmutant flyingmutant added the enhancement New feature or request label Oct 2, 2020
@flyingmutant
Copy link
Owner

Can you please tell what is your use case, and how configurable the generation should be, in your opinion? I don't have much experience using the hypothesis domain/URL generators.

@wfscheper
Copy link
Author

I want to test some code that parses a string as a URL in order to separate the scheme/host/port from the path, dropping any queries or fragments. I used the hypothesis URL strategy in another project, and thought it would make a reasonable addition to rapid.

As for an API, the domain strategy takes arguments for maximum length (total characters) and maximum elements (total domain segments), which seems reasonable. If a user needed to enforce a minimum for either property, writing a Filter wouldn't be hard.

For the URL generator, I was thinking it should return a *url.URL. That gives users a nice interface for Maps and Filters to work with. Conceivably, someone might want a generator for invalid URLs, but I don't think url.URLs do any validation beyond url.Parse so I think that use-case can be satisfied with a Map.

So in very rough pseudocode:

func Domain(maxLength, maxElements int) *Generator // cast generated values to string

func URL() *Generator // cast generated values to *url.URL

I can't think of any customizations for URL generation or alternative generators that wouldn't be easily done via a Map or a Filter. Maybe a URL generator that took a slice of schemes to sample from for applications that only deal with http URLs?

@wfscheper
Copy link
Author

Does this seem reasonable? I can start a pull request so we can look at some actual code.

@flyingmutant
Copy link
Owner

Looks reasonable, PR would be great!

I'd avoid any parameters in Domain for now: RFC 1035 specifies same limits as hypothesis defaults, and I can't come up with a common scenario when someone would want to change them.

For URL, I'd stick with HTTP/HTTPS schemes, just like Hypothesis does.

wfscheper added a commit to wfscheper/rapid that referenced this issue Nov 1, 2020
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes flyingmutant#17

Signed-off-by: Walter Scheper <ratlaw@gmail.com>
@wfscheper wfscheper linked a pull request Nov 1, 2020 that will close this issue
@wfscheper
Copy link
Author

Finally got around to trying to implement this. Not completely sure I'm using the best implementation here, as I'm not completely sure how to use some of the internal bits of rapid. Any suggestions for improvement are welcome.

I opted for Domain and DomainOf, since it wasn't that much harder to implement those two parameters.

The option to generate URLs with schemes other than http/https is available in the private implementation, but I didn't bother to expose it through a public API.

If you prefer the Domain generator follow that pattern, I can easily remove the DomainOf public function.

wfscheper added a commit to wfscheper/rapid that referenced this issue Nov 3, 2020
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes flyingmutant#17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
wfscheper added a commit to wfscheper/rapid that referenced this issue Nov 13, 2020
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes flyingmutant#17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
flyingmutant pushed a commit that referenced this issue Nov 17, 2020
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes #17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
wfscheper added a commit to wfscheper/rapid that referenced this issue Nov 19, 2020
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes flyingmutant#17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
flyingmutant pushed a commit that referenced this issue Mar 9, 2021
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes #17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
wfscheper added a commit to wfscheper/rapid that referenced this issue Sep 2, 2021
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes flyingmutant#17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
wfscheper added a commit to wfscheper/rapid that referenced this issue Sep 25, 2022
This adds a Generator for RFC 3986 compliant URLs, and two generators
for RFC 1035 compliant domain names.

Closes flyingmutant#17

Signed-off-by: Walter Scheper <walter.scheper@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants