-
-
Notifications
You must be signed in to change notification settings - Fork 148
fix: exluded characters in random string generator #111
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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") |
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.
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?
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.
based on your if condition
, the error message is maybe something related to max-retries?
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.
Yes, sure. I will return an error and the error will indicate info about exhaustion of max-retries
@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() |
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.
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.
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.
Fixed!
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.
LGTM thanks for your hard work bro @musinit
No description provided.