mirror of https://github.com/status-im/fathom.git
add tests for parseMajorMinor func
This commit is contained in:
parent
d8f1eb20ef
commit
7104397afa
|
@ -4,6 +4,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -42,3 +43,11 @@ func getRequestedPeriods(r *http.Request) (int64, int64) {
|
|||
|
||||
return before, after
|
||||
}
|
||||
|
||||
func parseMajorMinor(v string) string {
|
||||
parts := strings.SplitN(v, ".", 3)
|
||||
if len(parts) > 1 {
|
||||
v = parts[0] + "." + parts[1]
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
|
|
@ -48,3 +48,17 @@ func TestGetRequestIp(t *testing.T) {
|
|||
t.Errorf("Expected IP address of %s does not match %s", ipAddress, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMajorMinor(t *testing.T) {
|
||||
actual := parseMajorMinor("50.0.0")
|
||||
expected := "50.0"
|
||||
if actual != expected {
|
||||
t.Errorf("Return value should be %s, is %s instead", expected, actual)
|
||||
}
|
||||
|
||||
actual = parseMajorMinor("1.1")
|
||||
expected = "1.1"
|
||||
if actual != expected {
|
||||
t.Errorf("Return value should be %s is %s instead", expected, actual)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,7 @@ func CollectHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// add browser details
|
||||
visitor.BrowserName, visitor.BrowserVersion = ua.Browser()
|
||||
versionParts := strings.SplitN(visitor.BrowserVersion, ".", 3)
|
||||
if len(versionParts) > 1 {
|
||||
visitor.BrowserVersion = versionParts[0] + "." + versionParts[1]
|
||||
}
|
||||
visitor.BrowserName = parseMajorMinor(visitor.BrowserName)
|
||||
|
||||
// query by unique visitor key
|
||||
visitor.GenerateKey()
|
||||
|
|
Loading…
Reference in New Issue