Skip to content

Commit 1fdb725

Browse files
committedNov 4, 2020
Cover unsupported method with logging
1 parent e4d0862 commit 1fdb725

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
 

‎src/provider.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func (p Provider) raw (s string) string {
113113

114114
className, ok := rawProviders[parts[1]]
115115
if !ok {
116-
logger.Error(parts[1] + " is not a supported")
116+
logger.Error(parts[1] + " is not a supported provider")
117117
return ""
118118
}
119119

120120
class := reflect.ValueOf(className)
121121
methodName := strings.Split(parts[2], "(")[0]
122122
method := class.MethodByName(methodName)
123123
if !method.IsValid() {
124-
// TODO: Cover this with logging
124+
logger.Error(parts[2] + " is not a valid method")
125125
return ""
126126
}
127127

‎src/provider_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ func TestGet(t *testing.T) {
3737
}
3838

3939
_ = provider.Get("faker.Whoops1")
40-
if hook.LastEntry().Message != "Whoops1 is not a supported" {
40+
if hook.LastEntry().Message != "Whoops1 is not a supported provider" {
4141
t.Errorf("Unsupported provider not handled correctly")
4242
}
4343

44-
r6 := provider.Get("faker.Number().Whoops2()")
45-
if r6 != "" {
46-
t.Errorf("Got a value and was expecting empty string")
44+
_ = provider.Get("faker.Number().Whoops2()")
45+
if hook.LastEntry().Message != "Whoops2() is not a valid method" {
46+
t.Errorf("Unsupported method not handled correctly")
4747
}
4848

4949
r7 := provider.Get("faker.Internet().Slug")

0 commit comments

Comments
 (0)