-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFM-2514 add function to convert various types to string
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package analyticsservice | ||
|
||
import "testing" | ||
|
||
func Test_convertInterfaceToString(t *testing.T) { | ||
testCases := map[string]struct { | ||
input interface{} | ||
expected string | ||
}{ | ||
"Given I input a string": { | ||
input: "123", | ||
expected: "123", | ||
}, | ||
"Given I input a bool with the value false": { | ||
input: false, | ||
expected: "false", | ||
}, | ||
"Given I input a bool with the value true": { | ||
input: true, | ||
expected: "true", | ||
}, | ||
"Given I input an int64": { | ||
input: int64(123), | ||
expected: "123", | ||
}, | ||
"Given I input an int": { | ||
input: 123, | ||
expected: "123", | ||
}, | ||
"Given I input a float64": { | ||
input: float64(2.5), | ||
expected: "2.5", | ||
}, | ||
"Given I input a float32": { | ||
input: float32(2.5), | ||
expected: "2.5", | ||
}, | ||
"Given I input a nil value": { | ||
input: nil, | ||
expected: "nil", | ||
}, | ||
} | ||
|
||
for desc, tc := range testCases { | ||
tc := tc | ||
t.Run(desc, func(t *testing.T) { | ||
|
||
actual := convertInterfaceToString(tc.input) | ||
if actual != tc.expected { | ||
t.Errorf("(%s): expected %s, actual %s", desc, tc.expected, actual) | ||
} | ||
}) | ||
} | ||
} |