Skip to content

Commit

Permalink
add create_server_with_spaces_in_db_dir_with_local_user_perm
Browse files Browse the repository at this point in the history
  • Loading branch information
abagrov committed Feb 11, 2024
1 parent e7b5b68 commit a1b85c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/MysticMind.PostgresEmbed.Tests/PgServer_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,33 @@ public void create_server_with_spaces_in_db_dir()
var pathWithSpaces = Path.Combine(Directory.GetCurrentDirectory(), "folder with spaces");
if (!Directory.Exists(pathWithSpaces)) Directory.CreateDirectory(pathWithSpaces);

using var server = new PgServer(
"15.3.0",
dbDir: pathWithSpaces,
addLocalUserAccessPermission: AddLocalUserAccessPermission,
clearInstanceDirOnStop: true);
server.Start();

// Note: set pooling to false to prevent connecting issues
// https://github.com/npgsql/npgsql/issues/939
var connStr = string.Format(ConnStr, server.PgPort, PgUser);
var conn = new Npgsql.NpgsqlConnection(connStr);
var cmd =
new Npgsql.NpgsqlCommand(
"CREATE TABLE table1(ID CHAR(256) CONSTRAINT id PRIMARY KEY, Title CHAR)",
conn);

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}

[Fact]
public void create_server_with_spaces_in_db_dir_with_local_user_perm()
{
var pathWithSpaces = Path.Combine(Directory.GetCurrentDirectory(), "folder with spaces");
if (!Directory.Exists(pathWithSpaces)) Directory.CreateDirectory(pathWithSpaces);

using var server = new PgServer(
"15.3.0",
dbDir: pathWithSpaces,
Expand All @@ -262,7 +289,7 @@ public void create_server_with_spaces_in_db_dir()
[Fact]
public void create_server_with_spaces_in_db_dir_parent_dir()
{
var pathWithSpaces = Path.Combine(Path.GetTempPath(), "folder with spaces", "folder");
var pathWithSpaces = Path.Combine(Directory.GetCurrentDirectory(), "folder with spaces", "folder");
if (!Directory.Exists(pathWithSpaces)) Directory.CreateDirectory(pathWithSpaces);

using var server = new PgServer(
Expand Down
2 changes: 1 addition & 1 deletion src/MysticMind.PostgresEmbed/PgServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ private void AddLocalUserAccessPermission()
// get the local user under which the program runs
var currentLocalUser = Environment.GetEnvironmentVariable("Username");

args.Add(InstanceDir);
args.Add($"\"{InstanceDir}\"");
args.Add("/t");
args.Add("/grant:r");
args.Add($"{currentLocalUser}:(OI)(CI)F");
Expand Down

0 comments on commit a1b85c8

Please sign in to comment.