Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f7d58b

Browse files
committed
fixes from code review
1 parentc552c02 commit3f7d58b

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

‎cli/templatepull_test.go‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,8 @@ func TestTemplatePull_ToDir(t *testing.T) {
263263
// nolint: paralleltest // These tests change the current working dir, and is therefore unsuitable for parallelisation.
264264
for_,tc:=rangetests {
265265
t.Run(tc.name,func(t*testing.T) {
266-
// create coderd first, because our postgres cloning code needs to be run from somewhere in the package
267-
// hierarchy, before we change directories.
268-
client:=coderdtest.New(t,&coderdtest.Options{
269-
IncludeProvisionerDaemon:true,
270-
})
271-
272266
dir:=t.TempDir()
267+
273268
cwd,err:=os.Getwd()
274269
require.NoError(t,err)
275270
t.Cleanup(func() {
@@ -287,6 +282,9 @@ func TestTemplatePull_ToDir(t *testing.T) {
287282
actualDest=filepath.Join(dir,"actual")
288283
}
289284

285+
client:=coderdtest.New(t,&coderdtest.Options{
286+
IncludeProvisionerDaemon:true,
287+
})
290288
owner:=coderdtest.CreateFirstUser(t,client)
291289
templateAdmin,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID,rbac.RoleTemplateAdmin())
292290

‎coderd/database/dbtestutil/broker.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (b *Broker) init(t TBSubset) error {
150150
b.uuid=uuid.New()
151151
ctx,cancel:=context.WithTimeout(context.Background(),20*time.Second)
152152
defercancel()
153-
b.cleanerFD,err=startCleaner(ctx,b.uuid)
153+
b.cleanerFD,err=startCleaner(ctx,b.uuid,coderTestingParams.DSN())
154154
iferr!=nil {
155155
returnxerrors.Errorf("start test db cleaner: %w",err)
156156
}

‎coderd/database/dbtestutil/cleaner.go‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,36 @@ import (
2121
const (
2222
cleanerRespOK="OK"
2323
envCleanerParentUUID="DB_CLEANER_PARENT_UUID"
24+
envCleanerDSN="DB_CLEANER_DSN"
2425
)
2526

27+
var (
28+
originalWorkingDirstring
29+
getWorkingDirErrorerror
30+
)
31+
32+
funcinit() {
33+
// We expect our tests to run from somewhere in the project tree where `go run` below in `startCleaner` will
34+
// be able to resolve the command package. However, some of the tests modify the working directory during the run.
35+
// So, we grab the working directory during package init, before tests are run, and then set that work dir on the
36+
// subcommand process before it starts.
37+
originalWorkingDir,getWorkingDirError=os.Getwd()
38+
}
39+
2640
// startCleaner starts the cleaner in a subprocess. holdThis is an opaque reference that needs to be kept from being
2741
// garbage collected until we are done with all test databases (e.g. the end of the process).
28-
funcstartCleaner(ctx context.Context,parentUUID uuid.UUID) (holdThisany,errerror) {
29-
cmd:=exec.Command("go","run","github.com/coder/coder/v2/cmd/dbtestcleaner")
30-
cmd.Env=append(os.Environ(),fmt.Sprintf("%s=%s",envCleanerParentUUID,parentUUID.String()))
42+
funcstartCleaner(ctx context.Context,parentUUID uuid.UUID,dsnstring) (holdThisany,errerror) {
43+
cmd:=exec.Command("go","run","github.com/coder/coder/v2/coderd/database/dbtestutil/cleanercmd")
44+
cmd.Env=append(os.Environ(),
45+
fmt.Sprintf("%s=%s",envCleanerParentUUID,parentUUID.String()),
46+
fmt.Sprintf("%s=%s",envCleanerDSN,dsn),
47+
)
48+
49+
// c.f. comment on `func init()` in this file.
50+
ifgetWorkingDirError!=nil {
51+
returnnil,xerrors.Errorf("failed to get working directory during init: %w",getWorkingDirError)
52+
}
53+
cmd.Dir=originalWorkingDir
3154

3255
// Here we don't actually use the reference to the stdin pipe, because we never write anything to it. When this
3356
// process exits, the pipe is closed by the OS and this triggers the cleaner to do its cleaning work. But, we do
@@ -79,6 +102,10 @@ type cleaner struct {
79102

80103
func (c*cleaner)init(ctx context.Context)error {
81104
varerrerror
105+
dsn:=os.Getenv(envCleanerDSN)
106+
ifdsn=="" {
107+
returnxerrors.Errorf("DSN not set via env %s: %w",envCleanerDSN,err)
108+
}
82109
parentUUIDStr:=os.Getenv(envCleanerParentUUID)
83110
c.parentUUID,err=uuid.Parse(parentUUIDStr)
84111
iferr!=nil {
@@ -89,8 +116,6 @@ func (c *cleaner) init(ctx context.Context) error {
89116
Leveled(slog.LevelDebug).
90117
With(slog.F("parent_uuid",parentUUIDStr))
91118

92-
// TODO: support configurable username, password & port if required
93-
dsn:=fmt.Sprintf("postgres://postgres:postgres@localhost:5432/%s?sslmode=disable",CoderTestingDBName)
94119
c.db,err=sql.Open("postgres",dsn)
95120
iferr!=nil {
96121
returnxerrors.Errorf("couldn't open DB: %w",err)
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp