lab5 done
This commit is contained in:
@@ -259,7 +259,11 @@ func lab4Backend(t *testing.T, pool *pgxpool.Pool, repo *postgres.Storage, user
|
||||
fake.objects[orphan] = fakeObject{data: []byte("orphan"), modified: old}
|
||||
fake.objects[fresh] = fakeObject{data: []byte("fresh"), modified: time.Now()}
|
||||
fake.objects[locked] = fakeObject{data: []byte("locked"), modified: old}
|
||||
fake.objects["original/legacy-staging"] = fakeObject{data: []byte("legacy stage"), modified: old}
|
||||
fake.mu.Unlock()
|
||||
if _, err = pool.Exec(ctx, `UPDATE attachments SET staging_key='original/legacy-staging' WHERE id=$1`, second.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = pool.Exec(ctx, `UPDATE attachments SET created_at=$1 WHERE id=ANY($2::uuid[])`, old, []string{first.ID, second.ID}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -294,8 +298,9 @@ func lab4Backend(t *testing.T, pool *pgxpool.Pool, repo *postgres.Storage, user
|
||||
_, hasFresh := fake.objects[fresh]
|
||||
_, hasLinked := fake.objects[second.Key]
|
||||
_, hasLocked := fake.objects[locked]
|
||||
_, hasLegacyStage := fake.objects["original/legacy-staging"]
|
||||
fake.mu.Unlock()
|
||||
if hasOrphan || !hasFresh || !hasLinked || !hasLocked {
|
||||
if hasOrphan || !hasFresh || !hasLinked || !hasLocked || !hasLegacyStage {
|
||||
t.Fatal("unsafe object cleanup")
|
||||
}
|
||||
_, err = service.Get(ctx, first.ID, user.ID)
|
||||
|
||||
@@ -53,7 +53,7 @@ func (s *Storage) CreateMessageWithAttachments(ctx context.Context, chatID, send
|
||||
if err != nil {
|
||||
return domain.Message{}, dbError(err)
|
||||
}
|
||||
if status != "ready" {
|
||||
if status == "failed" {
|
||||
return domain.Message{}, domain.NewApplicationError(domain.ErrorConflict, "Вложение не готово")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestIntegration(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
runGoose := func(t *testing.T, command string) {
|
||||
runGoose := func(t *testing.T, command string, params ...string) {
|
||||
t.Helper()
|
||||
migrationDir := os.Getenv("GOOSE_MIGRATION_DIR")
|
||||
if migrationDir == "" {
|
||||
@@ -73,7 +73,8 @@ func TestIntegration(t *testing.T) {
|
||||
connection.RawQuery = url.Values{"sslmode": {"disable"}, "search_path": {schema}, "connect_timeout": {"5"}}.Encode()
|
||||
commandCtx, cancel := context.WithTimeout(ctx, 45*time.Second)
|
||||
defer cancel()
|
||||
commandExec := exec.CommandContext(commandCtx, "goose", "-env", "/dev/null", "-dir", migrationDir, "-timeout", "30s", command)
|
||||
args := append([]string{"-env", "/dev/null", "-dir", migrationDir, "-timeout", "30s", command}, params...)
|
||||
commandExec := exec.CommandContext(commandCtx, "goose", args...)
|
||||
commandExec.Env = append(os.Environ(), "GOOSE_DRIVER=postgres", "GOOSE_DBSTRING="+connection.String(), "PGPASSWORD="+cfg.PostgresPassword)
|
||||
output, err := commandExec.CombinedOutput()
|
||||
if err != nil {
|
||||
@@ -260,6 +261,8 @@ func TestIntegration(t *testing.T) {
|
||||
if err = pool.QueryRow(ctx, digestSQL).Scan(&before); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Model the actual lab4 physical schema before adopting its legacy journal.
|
||||
runGoose(t, "down-to", "4")
|
||||
if _, err = pool.Exec(ctx, `DROP TABLE goose_db_version;
|
||||
CREATE TABLE schema_migrations(version text PRIMARY KEY,applied_at timestamptz NOT NULL DEFAULT now());
|
||||
INSERT INTO schema_migrations(version) VALUES('001_initial.sql')`); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user