(t *testing.T)
| 880 | } |
| 881 | |
| 882 | func 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)`, |
nothing calls this directly
no test coverage detected