From b22f0551fa63c8485ebfa4deb37cd1a91d03f681 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 13 Apr 2017 14:20:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D0=BC=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BA=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA=D0=B5=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BA=D0=B8=D0=BD,=20=D0=B5=D1=81=D0=BB=D0=B8=20=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD=20=D1=83=D0=B6=D0=B5=20=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tools/tools.go | 7 ++++++- lib/tools/tools_test.go | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tools/tools.go b/lib/tools/tools.go index 7e5158b..96ad886 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -30,7 +30,12 @@ func BuildKey(username string) string { } func BuildElyUrl(route string) string { - return "http://ely.by" + route + prefix := "http://ely.by" + if !strings.HasPrefix(route, prefix) { + route = prefix + route + } + + return route } func getCurrentHour() int64 { diff --git a/lib/tools/tools_test.go b/lib/tools/tools_test.go index bf7b7f1..cb6fd37 100644 --- a/lib/tools/tools_test.go +++ b/lib/tools/tools_test.go @@ -20,3 +20,13 @@ func TestBuildKey(t *testing.T) { t.Error("Function shound convert string to lower case and concatenate it with usernmae:") } } + +func TestBuildElyUrl(t *testing.T) { + if BuildElyUrl("/route") != "http://ely.by/route" { + t.Error("Function should add prefix to the provided relative url.") + } + + if BuildElyUrl("http://ely.by/test/route") != "http://ely.by/test/route" { + t.Error("Function should do not add prefix to the provided prefixed url.") + } +}