Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

fix: exluded characters in random string generator #111

Merged
merged 4 commits into from
Jun 17, 2020

Conversation

musinit
Copy link
Contributor

@musinit musinit commented Jun 15, 2020

No description provided.

@codecov
Copy link

codecov bot commented Jun 15, 2020

Codecov Report

Merging #111 into master will decrease coverage by 1.57%.
The diff coverage is 67.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #111      +/-   ##
==========================================
- Coverage   95.44%   93.87%   -1.58%     
==========================================
  Files          11       11              
  Lines        1251     1289      +38     
==========================================
+ Hits         1194     1210      +16     
- Misses         32       43      +11     
- Partials       25       36      +11     
Impacted Files Coverage Δ
internet.go 83.33% <59.18%> (-16.67%) ⬇️
faker.go 91.25% <89.47%> (-0.16%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f13091...5a04e04. Read the comment docs.

faker.go Outdated
for i := 0; i < n; {
randRune := rune(rand.Intn(int(lang.end-lang.start)) + int(lang.start))
for slice.ContainsRune(set, randRune) {
if counter++; counter >= maxGenerateStringRetries {
log.Fatal("Can't generate random sequence with exluded letters")
Copy link
Owner

Choose a reason for hiding this comment

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

Can we return an error here?
Using fatal is quite dangerous, so I think, we just return the error, and let the user decide to do what they need to do, like calling fatal, or panic, or just log it?

Copy link
Owner

@bxcodec bxcodec Jun 16, 2020

Choose a reason for hiding this comment

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

based on your if condition, the error message is maybe something related to max-retries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure. I will return an error and the error will indicate info about exhaustion of max-retries

@musinit
Copy link
Contributor Author

musinit commented Jun 16, 2020

@bxcodec The test coverage of internet package decreased significantly in this PR, mainly because I don't know how better to cover cases, where success of randomString method depends on tiny probability that we each time for 1000000 retries we will point on 6 excluded elements from 57

internet.go Outdated
}

// Username get username randomly in string
func Username() string {
return singleFakeData(UserNameTag, func() interface{} {
i := Internet{}
return i.username()
u, _ := i.username()
Copy link
Owner

Choose a reason for hiding this comment

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

This one is not consistent with the others. I see the others is calling panic, but this one is ignored. Let's keep it consistent, either we call panic or ignore it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Owner

@bxcodec bxcodec left a comment

Choose a reason for hiding this comment

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

LGTM thanks for your hard work bro @musinit

@bxcodec bxcodec merged commit 02fc1b2 into bxcodec:master Jun 17, 2020
@bxcodec bxcodec changed the title exluded characters in random string generator fix: exluded characters in random string generator Jun 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants