Just want to share a useful tip for anyone using G...
# talk-kratos
s
Just want to share a useful tip for anyone using GoLand IDE to do code contribution or learning
kratos
. To run the test inside the IDE make sure you have the tag
-tags sqlite
in the
Go tool arguments:
. In the example screenshot I'm looking at
login_test.go
and add it to the
Run/Debug Configurations
s
Courtesy of @proud-plumber-24205
if you're using Goland you can set the tag globally and just hit the checkbox on a new build configuration under custom tags
Last one by me:
did you know that jetbrains IDEs have an awesome sql debugger, that can open sqlite files? from now on debugging tests is so much easier in keto, you can set a bool flag to use an sqlite file instead of in-mem and then debug after the test failed 😉 😍
https://github.com/ory/keto/pull/638/files#diff-19d74043bd6f4fd4ffaf6dee2895a42da0a754b6135339343117614974ff6182R84
Copy code
func GetSqlite(t testing.TB, mode sqliteMode) *DsnT {
	dsn := &DsnT{
		MigrateUp:   true,
		MigrateDown: false,
	}

	switch mode {
	case SQLiteMemory:
		dsn.Name = "memory"
		dsn.Conn = fmt.Sprintf("<sqlite://file:%s?_fk=true&cache=shared&mode=memory|sqlite://file:%s?_fk=true&cache=shared&mode=memory>", t.Name())
	case SQLiteFile:
		t.Cleanup(func() {
			_ = os.Remove("TestDB.sqlite")
		})
		fallthrough
	case SQLiteDebug:
		dsn.Name = "sqlite"
		dsn.Conn = "<sqlite://file:TestDB.sqlite?_fk=true|sqlite://file:TestDB.sqlite?_fk=true>"
	}

	return dsn
}
w
Under Settings, search for
Go: Test Tags
, click
Edit in settings.json
and add the following KV to the settings:
"go.testTags": "sqlite",