From be8346996f29f12831640d9106025d30c2ad6bef Mon Sep 17 00:00:00 2001 From: MakroCow Date: Sun, 27 Oct 2019 10:27:14 +0100 Subject: [PATCH] added unit tests to utils --- utils/utils_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 utils/utils_test.go diff --git a/utils/utils_test.go b/utils/utils_test.go new file mode 100644 index 0000000..30ab52d --- /dev/null +++ b/utils/utils_test.go @@ -0,0 +1,29 @@ +package utils + +import ( + "fmt" + "testing" +) + +func TestGetRedirectUrl_basepage(t *testing.T) { + var redir_url = GetRedirectUrl("https://www.google.com/search?sxsrf=ACYBGNRZr5M9ppUzFZQKPuaYOQtQL5EMtQ%3A1572167872215&source=hp&ei=wGC1XYDPCoWRmwWZh4b4Bg&q=how+to+write+go+unit+tests&oq=how+to+write+go+unit+tests&gs_l=psy-ab.3..0i22i30l2.1869.6449..6577...4.0..0.125.2231.25j5......0....1..gws-wiz.......0i131j0j35i39i19j0i10j0i203j0i22i10i30j0i19j0i13i30i19j0i8i13i30i19j33i22i29i30j0i13i30.jSyRCAg_ZBE&ved=0ahUKEwiAr7HcjbzlAhWFyKYKHZmDAW8Q4dUDCAc&uact=5") + if redir_url != "/" { + t.Fail() + } +} + +func TestGetRedirectUrl_maps(t *testing.T) { + var redir_url = GetRedirectUrl("https://www.google.com/maps/place/New+York+City,+New+York,+USA/@40.6974034,-74.119763,11z/data=!3m1!4b1!4m5!3m4!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62!8m2!3d40.7127753!4d-74.0059728") + fmt.Println(redir_url) + if redir_url != "/maps/place/New+York+City,+New+York,+USA/@40.6974034,-74.119763,11z/data=!3m1!4b1!4m5!3m4!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62!8m2!3d40.7127753!4d-74.0059728" { + t.Fail() + } +} + +func TestGetRedirectUrl_malformedUrl(t *testing.T) { + var redir_url = GetRedirectUrl("this_is_no_url") + fmt.Println(redir_url) + if redir_url != "/" { + t.Fail() + } +}