Closed eduncan911 closed 4 years ago
By assigning it to a variable, it allows me to assign custom functionality during tests - e.g. to purposely break or purposely cause an invalid result - to see how the caller would react.
ParseDurationFunc
where it is needed. var parseDuration
is now just a implementation of that function.
When I originally write
podcast.go
, everything was in that one file.As I started to add more and more functionality, it started to make sense to break out that extra functionality to dedicated files. E.g.
item.go
.However, I forgot to move the required private methods used in such files from
podcast.go
out to their usage.Example:
var parseDuration = func(duration int64) string
needs to be moved to where it is being used,item.go
.Off Topic: You may be wondering why I use
var parseDuration = func(duration int64) string
to define my functions, instead offunc parseDuration(duration int64) string
. The reason is because of testability. By assigning it to a variable, it allows me to assign custom functionality during tests - e.g. to purposely break or purposely cause an invalid result - to see how the caller would react.