-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating namespaced databases
- Loading branch information
Showing
3 changed files
with
134 additions
and
16 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
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,34 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/xmtp/xmtpd/pkg/testutils" | ||
) | ||
|
||
func TestNamespacedDB(t *testing.T) { | ||
startingDsn := testutils.LocalTestDBDSNPrefix + "/foo" + testutils.LocalTestDBDSNSuffix | ||
newDBName := "bar" | ||
// Create namespaced DB | ||
namespacedDB, err := NewNamespacedDB( | ||
context.Background(), | ||
startingDsn, | ||
newDBName, | ||
time.Second, | ||
time.Second, | ||
) | ||
require.NoError(t, err) | ||
|
||
result, err := namespacedDB.Query("SELECT current_database();") | ||
require.NoError(t, err) | ||
defer result.Close() | ||
|
||
require.True(t, result.Next()) | ||
var dbName string | ||
err = result.Scan(&dbName) | ||
require.NoError(t, err) | ||
require.Equal(t, "bar", dbName) | ||
} |
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