-
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.
feat: added debug flag in the SuperTokenConfig in the init() for logging
- Loading branch information
1 parent
470866b
commit 1003a57
Showing
3 changed files
with
139 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package session | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/supertokens/supertokens-golang/supertokens" | ||
"github.com/supertokens/supertokens-golang/test/unittesting" | ||
) | ||
|
||
func TestLogDebugMessageWhenDebugTrue(t *testing.T) { | ||
var logMessage = "test log message" | ||
var buf bytes.Buffer | ||
|
||
debug := true | ||
supertokens.Logger = log.New(&buf, "", 0) | ||
|
||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "SuperTokens", | ||
APIDomain: "api.supertokens.io", | ||
WebsiteDomain: "supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
Init(nil), | ||
}, | ||
Debug: &debug, | ||
} | ||
BeforeEach() | ||
|
||
unittesting.StartUpST("localhost", "8080") | ||
|
||
defer AfterEach() | ||
|
||
err := supertokens.Init(configValue) | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
supertokensInstance, err := supertokens.GetInstanceOrThrowError() | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
supertokens.LogDebugMessage(logMessage) | ||
assert.Equal(t, &debug, supertokensInstance.Debug) | ||
assert.Contains(t, buf.String(), logMessage, "checking log message in logs") | ||
} | ||
|
||
func TestLogDebugMessageWhenDebugFalse(t *testing.T) { | ||
var logMessage = "test log message" | ||
var buf bytes.Buffer | ||
|
||
debug := false | ||
supertokens.Logger = log.New(&buf, "", 0) | ||
|
||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "SuperTokens", | ||
APIDomain: "api.supertokens.io", | ||
WebsiteDomain: "supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
Init(nil), | ||
}, | ||
Debug: &debug, | ||
} | ||
BeforeEach() | ||
|
||
unittesting.StartUpST("localhost", "8080") | ||
|
||
defer AfterEach() | ||
|
||
err := supertokens.Init(configValue) | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
supertokensInstance, err := supertokens.GetInstanceOrThrowError() | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
supertokens.LogDebugMessage(logMessage) | ||
assert.Equal(t, &debug, supertokensInstance.Debug) | ||
assert.NotContains(t, buf.String(), logMessage, "checking log message in logs") | ||
} | ||
|
||
func TestLogDebugMessageWithEnvVar(t *testing.T) { | ||
var logMessage = "test log message" | ||
var buf bytes.Buffer | ||
|
||
supertokens.Logger = log.New(&buf, "", 0) | ||
os.Setenv("SUPERTOKENS_DEBUG", "1") | ||
|
||
configValue := supertokens.TypeInput{ | ||
Supertokens: &supertokens.ConnectionInfo{ | ||
ConnectionURI: "http://localhost:8080", | ||
}, | ||
AppInfo: supertokens.AppInfo{ | ||
AppName: "SuperTokens", | ||
APIDomain: "api.supertokens.io", | ||
WebsiteDomain: "supertokens.io", | ||
}, | ||
RecipeList: []supertokens.Recipe{ | ||
Init(nil), | ||
}, | ||
} | ||
BeforeEach() | ||
|
||
unittesting.StartUpST("localhost", "8080") | ||
|
||
defer AfterEach() | ||
|
||
err := supertokens.Init(configValue) | ||
|
||
if err != nil { | ||
t.Error(err.Error()) | ||
} | ||
|
||
supertokens.LogDebugMessage(logMessage) | ||
assert.Contains(t, buf.String(), logMessage, "checking log message in logs") | ||
} |
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
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