diff options
Diffstat (limited to 'api/context_test.go')
-rw-r--r-- | api/context_test.go | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/api/context_test.go b/api/context_test.go index a9e2afa0f..c3c7a9768 100644 --- a/api/context_test.go +++ b/api/context_test.go @@ -8,32 +8,6 @@ import ( "testing" ) -var ipAddressTests = []struct { - address string - expected bool -}{ - {"126.255.255.255", false}, - {"127.0.0.1", true}, - {"127.0.0.4", false}, - {"9.255.255.255", false}, - {"10.0.0.1", true}, - {"11.0.0.1", false}, - {"176.15.155.255", false}, - {"176.16.0.1", true}, - {"176.31.0.1", false}, - {"192.167.255.255", false}, - {"192.168.0.1", true}, - {"192.169.0.1", false}, -} - -func TestIpAddress(t *testing.T) { - for _, v := range ipAddressTests { - if IsPrivateIpAddress(v.address) != v.expected { - t.Errorf("expect %v as %v", v.address, v.expected) - } - } -} - func TestContext(t *testing.T) { context := Context{} @@ -52,9 +26,26 @@ func TestContext(t *testing.T) { if !context.HasPermissionsToUser("6", "") { t.Fatal("should have permissions") } +} - // context.IpAddress = "125.0.0.1" - // if context.HasPermissionsToUser("6", "") { - // t.Fatal("shouldn't have permissions") - // } +func TestCache(t *testing.T) { + session := &model.Session{ + Id: model.NewId(), + Token: model.NewId(), + UserId: model.NewId(), + } + + sessionCache.AddWithExpiresInSecs(session.Token, session, 5*60) + + keys := sessionCache.Keys() + if len(keys) <= 0 { + t.Fatal("should have items") + } + + RemoveAllSessionsForUserId(session.UserId) + + rkeys := sessionCache.Keys() + if len(rkeys) != len(keys)-1 { + t.Fatal("should have one less") + } } |