diff --git a/pkg/sql/sqlite/connection.go b/pkg/sql/sqlite/connection.go index de814c2db..edd2800bc 100644 --- a/pkg/sql/sqlite/connection.go +++ b/pkg/sql/sqlite/connection.go @@ -83,8 +83,12 @@ func (c *Connection) getFilePath() string { return c.formatFilePath(c.name) } +func formatFilePath(path, fileName string) string { + return filepath.Join(path, fileName+".sqlite") +} + func (c *Connection) formatFilePath(fileName string) string { - return fmt.Sprintf("%s.sqlite", filepath.Join(c.path, fileName)) + return formatFilePath(c.path, fileName) } func (c *Connection) openConn() error { diff --git a/pkg/sql/sqlite/helpers_test.go b/pkg/sql/sqlite/helpers_test.go new file mode 100644 index 000000000..9be798f08 --- /dev/null +++ b/pkg/sql/sqlite/helpers_test.go @@ -0,0 +1,57 @@ +package sqlite + +import ( + "runtime" + "testing" +) + +func Test_formatFilePathNotWindows(t *testing.T) { + // This test defines "want" paths in the *NIX path convention used by linux, + // mac, bsd, etc., but not windows. Rather than using build flags to skip + // this entire file, we'll define this test as such and we can make another + // for Windows hosts if we want to. + if runtime.GOOS == "windows" { + t.Skip("test not applicable to windows paths") + } + type args struct { + path string + fileName string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "abs path no slash", + args: args{ + path: "/tmp", + fileName: "dbname", + }, + want: "/tmp/dbname.sqlite", + }, + { + name: "abs path with trailing slash", + args: args{ + path: "/tmp/", + fileName: "dbname", + }, + want: "/tmp/dbname.sqlite", + }, + { + name: "rel path no slash", + args: args{ + path: "./here", + fileName: "dbname", + }, + want: "here/dbname.sqlite", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := formatFilePath(tt.args.path, tt.args.fileName); got != tt.want { + t.Errorf("formatFilePath() = %v, want %v", got, tt.want) + } + }) + } +}