mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
chore: add the --ephemeral server flag (#16126)
Another PR to address https://github.com/coder/coder/issues/15109. Changes: - Introduces the `--ephemeral` flag, which changes the Coder config directory to a temporary location. The config directory is where the built-in PostgreSQL stores its data, so using a new one results in a deployment with a fresh state. The `--ephemeral` flag is set to replace the `--in-memory` flag once the in-memory database is removed.
This commit is contained in:
@ -177,6 +177,43 @@ func TestServer(t *testing.T) {
|
||||
return err == nil && rawURL != ""
|
||||
}, superDuperLong, testutil.IntervalFast, "failed to get access URL")
|
||||
})
|
||||
t.Run("EphemeralDeployment", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
inv, _ := clitest.New(t,
|
||||
"server",
|
||||
"--http-address", ":0",
|
||||
"--access-url", "http://example.com",
|
||||
"--ephemeral",
|
||||
)
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
|
||||
// Embedded postgres takes a while to fire up.
|
||||
const superDuperLong = testutil.WaitSuperLong * 3
|
||||
ctx, cancelFunc := context.WithCancel(testutil.Context(t, superDuperLong))
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
errCh <- inv.WithContext(ctx).Run()
|
||||
}()
|
||||
pty.ExpectMatch("Using an ephemeral deployment directory")
|
||||
rootDirLine := pty.ReadLine(ctx)
|
||||
rootDir := strings.TrimPrefix(rootDirLine, "Using an ephemeral deployment directory")
|
||||
rootDir = strings.TrimSpace(rootDir)
|
||||
rootDir = strings.TrimPrefix(rootDir, "(")
|
||||
rootDir = strings.TrimSuffix(rootDir, ")")
|
||||
require.NotEmpty(t, rootDir)
|
||||
require.DirExists(t, rootDir)
|
||||
|
||||
pty.ExpectMatchContext(ctx, "View the Web UI")
|
||||
|
||||
cancelFunc()
|
||||
<-errCh
|
||||
|
||||
require.NoDirExists(t, rootDir)
|
||||
})
|
||||
t.Run("BuiltinPostgresURL", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
root, _ := clitest.New(t, "server", "postgres-builtin-url")
|
||||
|
Reference in New Issue
Block a user