From 5fbef1e517814cbb8d9f96ba16dffe4ab55efc30 Mon Sep 17 00:00:00 2001 From: makeworld Date: Thu, 6 Aug 2020 11:56:36 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Added=20redir=20cache=20tests=20-?= =?UTF-8?q?=20fixes=20#65?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/favicons.go | 7 ------- cache/redir_test.go | 24 ++++++++++++++++++++++++ go.sum | 1 + 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 cache/redir_test.go diff --git a/cache/favicons.go b/cache/favicons.go index a885837..674a8f9 100644 --- a/cache/favicons.go +++ b/cache/favicons.go @@ -1,7 +1,6 @@ package cache import ( - "fmt" "sync" ) @@ -50,9 +49,3 @@ func RemoveFavicon(host string) { delete(favicons, host) favMu.Unlock() } - -func AllFavicons() string { - favMu.RLock() - defer favMu.RUnlock() - return fmt.Sprintf("%v", favicons) -} diff --git a/cache/redir_test.go b/cache/redir_test.go new file mode 100644 index 0000000..3275bab --- /dev/null +++ b/cache/redir_test.go @@ -0,0 +1,24 @@ +package cache + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAddRedir(t *testing.T) { + ClearRedirs() + AddRedir("A", "B") + assert.Equal(t, "B", Redirect("A"), "A redirects to B") + + // Chain + AddRedir("B", "C") + assert.Equal(t, "C", Redirect("B"), "B redirects to C") + assert.Equal(t, "C", Redirect("A"), "A now redirects to C too") + + // Loop + ClearRedirs() + AddRedir("A", "B") + AddRedir("B", "A") + assert.Equal(t, "A", Redirect("B"), "B redirects to A - most recent version of loop is used") +} diff --git a/go.sum b/go.sum index f564142..be1cd19 100644 --- a/go.sum +++ b/go.sum @@ -202,6 +202,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.7.0 h1:xVKxvI7ouOI5I+U9s2eeiUfMaWBVoXA3AWskkrqK0VM= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=