Skip to content

Commit 73217a5

Browse files
committed
test
1 parent 17597b1 commit 73217a5

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

cmd/dbos/cli_integration_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ func getDatabaseURL(dbRole string) string {
5555
return dsn.String()
5656
}
5757

58+
// getDatabaseURLKeyValue returns the same connection string in libpq key-value format
59+
// This is useful for testing that commands handle both URL and key-value formats
60+
func getDatabaseURLKeyValue(dbRole string) string {
61+
password := os.Getenv("PGPASSWORD")
62+
if password == "" {
63+
password = "dbos"
64+
}
65+
return fmt.Sprintf("user='%s' password='%s' database=dbos host=localhost port=5432 sslmode=disable", dbRole, password)
66+
}
67+
5868
// TestCLIWorkflow provides comprehensive integration testing of the DBOS CLI
5969
func TestCLIWorkflow(t *testing.T) {
6070
defer goleak.VerifyNone(t,
@@ -147,6 +157,27 @@ func TestCLIWorkflow(t *testing.T) {
147157
}
148158
})
149159

160+
t.Run("ResetDatabaseWithKeyValueFormat", func(t *testing.T) {
161+
// Test reset command with key-value format connection string
162+
args := append([]string{"reset", "-y", "--db-url", getDatabaseURLKeyValue("postgres")}, config.args...)
163+
cmd := exec.Command(cliPath, args...)
164+
165+
output, err := cmd.CombinedOutput()
166+
require.NoError(t, err, "Reset database command with key-value format failed: %s", string(output))
167+
168+
assert.Contains(t, string(output), "System database has been reset successfully", "Output should confirm database reset")
169+
170+
// Verify the database was reset by checking schema doesn't exist
171+
db, err := sql.Open("pgx", getDatabaseURL("postgres"))
172+
require.NoError(t, err)
173+
defer db.Close()
174+
175+
var exists bool
176+
err = db.QueryRow("SELECT EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name = $1)", config.schemaName).Scan(&exists)
177+
require.NoError(t, err)
178+
assert.False(t, exists, fmt.Sprintf("Schema %s should not exist after reset", config.schemaName))
179+
})
180+
150181
t.Run("ProjectInitialization", func(t *testing.T) {
151182
testProjectInitialization(t, cliPath)
152183
})
@@ -507,6 +538,22 @@ func testListWorkflows(t *testing.T, cliPath string, baseArgs []string, dbRole s
507538
}
508539
})
509540
}
541+
542+
// Test list command with key-value format connection string
543+
t.Run("ListWithKeyValueFormat", func(t *testing.T) {
544+
args := append([]string{"workflow", "list", "--db-url", getDatabaseURLKeyValue(dbRole)}, baseArgs...)
545+
fmt.Println(args)
546+
cmd := exec.Command(cliPath, args...)
547+
548+
output, err := cmd.CombinedOutput()
549+
require.NoError(t, err, "List command with key-value format failed: %s", string(output))
550+
551+
// Parse JSON output
552+
var workflows []dbos.WorkflowStatus
553+
err = json.Unmarshal(output, &workflows)
554+
require.NoError(t, err, "JSON output should be valid")
555+
assert.Greater(t, len(workflows), 0, "Should have workflows when using key-value format")
556+
})
510557
}
511558

512559
// testGetWorkflow tests retrieving individual workflow details
@@ -560,6 +607,21 @@ func testGetWorkflow(t *testing.T, cliPath string, baseArgs []string, dbRole str
560607
assert.NotEmpty(t, status2.Status, "Should have workflow status")
561608
assert.NotEmpty(t, status2.Name, "Should have workflow name")
562609

610+
// Test with key-value format connection string (libpq format)
611+
argsKeyValue := append([]string{"workflow", "get", workflowID, "--db-url", getDatabaseURLKeyValue(dbRole)}, baseArgs...)
612+
cmdKeyValue := exec.Command(cliPath, argsKeyValue...)
613+
614+
outputKeyValue, errKeyValue := cmdKeyValue.CombinedOutput()
615+
require.NoError(t, errKeyValue, "Get workflow JSON command with key-value format failed: %s", string(outputKeyValue))
616+
617+
// Verify valid JSON
618+
var statusKeyValue dbos.WorkflowStatus
619+
err = json.Unmarshal(outputKeyValue, &statusKeyValue)
620+
require.NoError(t, err, "JSON output should be valid")
621+
assert.Equal(t, workflowID, statusKeyValue.ID, "JSON should contain correct workflow ID")
622+
assert.NotEmpty(t, statusKeyValue.Status, "Should have workflow status")
623+
assert.NotEmpty(t, statusKeyValue.Name, "Should have workflow name")
624+
563625
// Test with config file containing environment variable
564626
configPath := "dbos-config.yaml"
565627

cmd/dbos/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func getDBURL() (string, error) {
103103
// Log the database URL in verbose mode with masked password
104104
maskedURL, err := maskPassword(resolvedURL)
105105
if err != nil {
106-
logger.Warn("Failed to mask database URL", "error", err)
106+
logger.Debug("Failed to mask database URL", "error", err)
107107
maskedURL = resolvedURL
108108
}
109109
logger.Debug("Using database URL", "source", source, "url", maskedURL)

dbos/dbos_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func TestConfig(t *testing.T) {
337337
t.Run("DBOSContextCreation", func(t *testing.T) {
338338
// Use the actual password from config for integration test
339339
actualPassword := parsedURL.ConnConfig.Password
340-
keyValueConnStr := fmt.Sprintf("user=%s password=%s database=%s host=%s%s", user, actualPassword, database, host, portSSL)
340+
keyValueConnStr := fmt.Sprintf("user='%s' password='%s' database=%s host=%s%s", user, actualPassword, database, host, portSSL)
341341

342342
ctx, err := NewDBOSContext(context.Background(), Config{
343343
DatabaseURL: keyValueConnStr,

0 commit comments

Comments
 (0)