MCPcopy Index your code
hub / github.com/coder/coder / TestMigration000457ChatAccessRole

Function TestMigration000457ChatAccessRole

coderd/database/migrations/migrate_test.go:882–1026  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

880}
881
882func TestMigration000457ChatAccessRole(t *testing.T) {
883 t.Parallel()
884
885 const migrationVersion = 457
886
887 sqlDB := testSQLDB(t)
888
889 // Migrate up to the migration before the one that grants
890 // agents-access roles.
891 next, err := migrations.Stepper(sqlDB)
892 require.NoError(t, err)
893 for {
894 version, more, err := next()
895 require.NoError(t, err)
896 if !more {
897 t.Fatalf("migration %d not found", migrationVersion)
898 }
899 if version == migrationVersion-1 {
900 break
901 }
902 }
903
904 ctx := testutil.Context(t, testutil.WaitSuperLong)
905
906 // Define test users.
907 userWithChat := uuid.New() // Has a chat, no agents-access role.
908 userAlreadyHasRole := uuid.New() // Has a chat and already has agents-access.
909 userNoChat := uuid.New() // No chat at all.
910 userWithChatAndRoles := uuid.New() // Has a chat and other existing roles.
911
912 now := time.Now().UTC().Truncate(time.Microsecond)
913
914 // We need a chat_provider and chat_model_config for the chats FK.
915 providerID := uuid.New()
916 modelConfigID := uuid.New()
917
918 tx, err := sqlDB.BeginTx(ctx, nil)
919 require.NoError(t, err)
920 defer tx.Rollback()
921
922 fixtures := []struct {
923 query string
924 args []any
925 }{
926 // Insert test users with varying rbac_roles.
927 {
928 `INSERT INTO users (id, username, email, hashed_password, created_at, updated_at, status, rbac_roles, login_type)
929 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
930 []any{userWithChat, "user-with-chat", "chat@test.com", []byte{}, now, now, "active", pq.StringArray{}, "password"},
931 },
932 {
933 `INSERT INTO users (id, username, email, hashed_password, created_at, updated_at, status, rbac_roles, login_type)
934 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
935 []any{userAlreadyHasRole, "user-already-has-role", "already@test.com", []byte{}, now, now, "active", pq.StringArray{"agents-access"}, "password"},
936 },
937 {
938 `INSERT INTO users (id, username, email, hashed_password, created_at, updated_at, status, rbac_roles, login_type)
939 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,

Callers

nothing calls this directly

Calls 12

StepperFunction · 0.92
ContextFunction · 0.92
ExecContextMethod · 0.80
CommitMethod · 0.80
QueryRowContextMethod · 0.80
testSQLDBFunction · 0.70
NewMethod · 0.65
HelperMethod · 0.65
FatalfMethod · 0.45
ScanMethod · 0.45
ContainsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected