-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ada66
commit 0397cd6
Showing
1 changed file
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,11 +64,367 @@ func TestCachingWorks(t *testing.T) { | |
|
||
tpuser, err = thirdparty.GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, tpuser) | ||
assert.False(t, calledCore) | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.False(t, calledCore) | ||
} | ||
|
||
func TestNoCachingIfDisabledByUser(t *testing.T) { | ||
calledCore := false | ||
|
||
config := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(r *http.Request, uc supertokens.UserContext) *http.Request { | ||
calledCore = true | ||
return r | ||
}, | ||
DisableCoreCallCache: true, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "ST", | ||
WebsiteDomain: "http://supertokens.io", | ||
APIDomain: "http://api.supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
session.Init(nil), | ||
Init(nil), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(config) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
userContext := map[string]interface{}{} | ||
user, err := GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
} | ||
|
||
func TestNoCachingIfHeadersAreDifferent(t *testing.T) { | ||
calledCore := false | ||
|
||
config := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(r *http.Request, uc supertokens.UserContext) *http.Request { | ||
calledCore = true | ||
return r | ||
}, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "ST", | ||
WebsiteDomain: "http://supertokens.io", | ||
APIDomain: "http://api.supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
session.Init(nil), | ||
Init(nil), | ||
thirdparty.Init(nil), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(config) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
userContext := map[string]interface{}{} | ||
user, err := GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.False(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
tpuser, err := thirdparty.GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, tpuser) | ||
assert.True(t, calledCore) | ||
} | ||
|
||
func TestCachingGetsClearWhenQueryWithoutUserContext(t *testing.T) { | ||
calledCore := false | ||
|
||
config := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(r *http.Request, uc supertokens.UserContext) *http.Request { | ||
calledCore = true | ||
return r | ||
}, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "ST", | ||
WebsiteDomain: "http://supertokens.io", | ||
APIDomain: "http://api.supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
session.Init(nil), | ||
Init(nil), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(config) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
userContext := map[string]interface{}{} | ||
user, err := GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
_, err = SignUp("public", "[email protected]", "abcd1234") | ||
assert.Nil(t, err) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
} | ||
|
||
func TestCachingDoesNotGetClearWithNonGetIfKeepAlive(t *testing.T) { | ||
calledCore := false | ||
|
||
config := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(r *http.Request, uc supertokens.UserContext) *http.Request { | ||
calledCore = true | ||
return r | ||
}, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "ST", | ||
WebsiteDomain: "http://supertokens.io", | ||
APIDomain: "http://api.supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
session.Init(nil), | ||
Init(nil), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(config) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
userContext := map[string]interface{}{ | ||
"_default": map[string]interface{}{ | ||
"keepCacheAlive": true, | ||
}, | ||
} | ||
userContext2 := map[string]interface{}{} | ||
|
||
user, err := GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext2) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
_, err = SignUp("public", "[email protected]", "abcd1234", &userContext) | ||
assert.Nil(t, err) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.False(t, calledCore) | ||
|
||
user, err = GetUserByID("random", &userContext2) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.False(t, calledCore) | ||
} | ||
|
||
func TestCachingGetsClearWithNonGetIfKeepAliveIsFalse(t *testing.T) { | ||
calledCore := false | ||
|
||
config := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(r *http.Request, uc supertokens.UserContext) *http.Request { | ||
calledCore = true | ||
return r | ||
}, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "ST", | ||
WebsiteDomain: "http://supertokens.io", | ||
APIDomain: "http://api.supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
session.Init(nil), | ||
Init(nil), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(config) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
userContext := map[string]interface{}{ | ||
"_default": map[string]interface{}{ | ||
"keepCacheAlive": false, | ||
}, | ||
} | ||
userContext2 := map[string]interface{}{} | ||
|
||
user, err := GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext2) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
_, err = SignUp("public", "[email protected]", "abcd1234", &userContext) | ||
assert.Nil(t, err) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.False(t, calledCore) | ||
|
||
user, err = GetUserByID("random", &userContext2) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
} | ||
|
||
func TestCachingGetsClearWithNonGetIfKeepAliveIsNotSet(t *testing.T) { | ||
calledCore := false | ||
|
||
config := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
NetworkInterceptor: func(r *http.Request, uc supertokens.UserContext) *http.Request { | ||
calledCore = true | ||
return r | ||
}, | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "ST", | ||
WebsiteDomain: "http://supertokens.io", | ||
APIDomain: "http://api.supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
session.Init(nil), | ||
Init(nil), | ||
}, | ||
} | ||
|
||
BeforeEach() | ||
unittesting.StartUpST("localhost", "8080") | ||
defer AfterEach() | ||
err := supertokens.Init(config) | ||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
userContext := map[string]interface{}{} | ||
userContext2 := map[string]interface{}{} | ||
|
||
user, err := GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext2) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
_, err = SignUp("public", "[email protected]", "abcd1234", &userContext) | ||
assert.Nil(t, err) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
|
||
calledCore = false | ||
|
||
user, err = GetUserByID("random", &userContext) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.False(t, calledCore) | ||
|
||
user, err = GetUserByID("random", &userContext2) | ||
assert.Nil(t, err) | ||
assert.Nil(t, user) | ||
assert.True(t, calledCore) | ||
} |