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

Commit7f37232

Browse files
committed
got it working
1 parent4356f53 commit7f37232

13 files changed

+89
-35
lines changed

‎coderd/database/db_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ package database_test
55
import (
66
"context"
77
"database/sql"
8+
"os"
89
"testing"
910

1011
"github.com/google/uuid"
1112
"github.com/lib/pq"
13+
"github.com/rs/zerolog"
14+
sqldblogger"github.com/simukti/sqldb-logger"
15+
"github.com/simukti/sqldb-logger/logadapter/zerologadapter"
1216
"github.com/stretchr/testify/require"
1317

1418
"github.com/coder/coder/v2/coderd/database"
@@ -92,6 +96,14 @@ func testSQLDB(t testing.TB) *sql.DB {
9296
t.Cleanup(closeFn)
9397

9498
db,err:=sql.Open("postgres",connection)
99+
loggerAdapter:=zerologadapter.New(zerolog.New(zerolog.ConsoleWriter{Out:os.Stderr}))
100+
db=sqldblogger.OpenDriver(connection,db.Driver(),loggerAdapter,
101+
sqldblogger.WithMinimumLevel(sqldblogger.LevelTrace),
102+
sqldblogger.WithPreparerLevel(sqldblogger.LevelTrace),// default: LevelInfo
103+
sqldblogger.WithQueryerLevel(sqldblogger.LevelTrace),// default: LevelInfo
104+
sqldblogger.WithExecerLevel(sqldblogger.LevelTrace),// default: LevelInfo
105+
)
106+
95107
require.NoError(t,err)
96108
t.Cleanup(func() {_=db.Close() })
97109

‎coderd/database/dbtestutil/postgres.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func Open() (string, func(), error) {
2828
iferr!=nil {
2929
return"",nil,xerrors.Errorf("connect to ci postgres: %w",err)
3030
}
31+
3132
deferdb.Close()
3233

3334
dbName,err:=cryptorand.StringCharset(cryptorand.Lower,10)

‎coderd/database/dump.sql‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/migrations/000215_scoped_org_db_roles.up.sql‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ ALTER TABLE ONLY organization_members ALTER COLUMN roles SET DEFAULT '{}';
55
-- No one should be using organization roles yet. If they are, the names in the
66
-- database are now incorrect. Just remove them all.
77
UPDATE organization_membersSET roles='{}';
8-
9-
CREATETYPEname_organization_pairAS (nametext, organiztion_id uuid);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROPTYPE name_organization_pair;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATETYPEname_organization_pairAS (nametext, organization_id uuid);

‎coderd/database/models.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/querier_test.go‎

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,10 @@ func TestReadCustomRoles(t *testing.T) {
539539
roles:=make([]database.CustomRole,0)
540540
fori:=0;i<15;i++ {
541541
orgID:= uuid.NullUUID{}
542-
ifi%7!=0 {
543-
orgID= uuid.NullUUID{
544-
UUID:orgIDs[i%len(orgIDs)],
545-
Valid:true,
546-
}
542+
543+
orgID= uuid.NullUUID{
544+
UUID:orgIDs[i%len(orgIDs)],
545+
Valid:true,
547546
}
548547

549548
role,err:=db.UpsertCustomRole(ctx, database.UpsertCustomRoleParams{
@@ -561,25 +560,57 @@ func TestReadCustomRoles(t *testing.T) {
561560

562561
testCases:= []struct {
563562
Namestring
564-
Params database.CustomRoles2Params
563+
Params database.CustomRolesParams
565564
Matchfunc(role database.CustomRole)bool
566565
}{
566+
{
567+
Name:"NilRoles",
568+
Params: database.CustomRolesParams{
569+
LookupRoles:nil,
570+
ExcludeOrgRoles:false,
571+
OrganizationID: uuid.UUID{},
572+
},
573+
Match:func(role database.CustomRole)bool {
574+
returntrue
575+
},
576+
},
567577
{
568578
// Empty params should return all roles
569-
Name:"Empty",
570-
Params: database.CustomRoles2Params{},
579+
Name:"Empty",
580+
Params: database.CustomRolesParams{
581+
LookupRoles: []database.NameOrganizationPair{},
582+
ExcludeOrgRoles:false,
583+
OrganizationID: uuid.UUID{},
584+
},
571585
Match:func(role database.CustomRole)bool {
572586
returntrue
573587
},
574588
},
575-
//{
576-
//// Only an organization roles
577-
//Name: "Organization",
578-
//Params: database.CustomRolesParams{},
579-
//Match: func(role database.CustomRole) bool {
580-
//return true
581-
//},
582-
//},
589+
{
590+
Name:"Organization",
591+
Params: database.CustomRolesParams{
592+
LookupRoles: []database.NameOrganizationPair{},
593+
ExcludeOrgRoles:false,
594+
OrganizationID:orgIDs[1],
595+
},
596+
Match:func(role database.CustomRole)bool {
597+
returnrole.OrganizationID.UUID==orgIDs[1]
598+
},
599+
},
600+
{
601+
Name:"SpecificRole",
602+
Params: database.CustomRolesParams{
603+
LookupRoles: []database.NameOrganizationPair{
604+
{
605+
Name:roles[0].Name,
606+
OrganizationID:roles[0].OrganizationID.UUID,
607+
},
608+
},
609+
},
610+
Match:func(role database.CustomRole)bool {
611+
returnrole.Name==roles[0].Name&&role.OrganizationID.UUID==roles[0].OrganizationID.UUID
612+
},
613+
},
583614
}
584615

585616
for_,tc:=rangetestCases {
@@ -588,8 +619,9 @@ func TestReadCustomRoles(t *testing.T) {
588619
t.Run(tc.Name,func(t*testing.T) {
589620
t.Parallel()
590621

622+
t.Log(tc.Params)
591623
ctx:=testutil.Context(t,testutil.WaitLong)
592-
found,err:=db.CustomRoles2(ctx,tc.Params)
624+
found,err:=db.CustomRoles(ctx,tc.Params)
593625
require.NoError(t,err)
594626
filtered:=make([]database.CustomRole,0)
595627
for_,role:=rangeroles {
@@ -599,9 +631,8 @@ func TestReadCustomRoles(t *testing.T) {
599631
}
600632

601633
a:=db2sdk.List(filtered,normalizedRoleName)
602-
var_,_=found,a
603-
//b := db2sdk.List(found, normalizedRoleName)
604-
//require.Equal(t, a, b)
634+
b:=db2sdk.List(found,normalizedRoleName)
635+
require.Equal(t,a,b)
605636
})
606637
}
607638
}

‎coderd/database/queries.sql.go‎

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp