Перенесите реализацию ЛР 4 на стенд ЛР 5
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package attachment_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"messenger/internal/testenv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFilesSchemaRejectsMalformedHashes(t *testing.T) {
|
||||
db, err := testenv.StartPostgres(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
_, err = db.Pool.Exec(context.Background(), `INSERT INTO files(hash,size_bytes,mime_type,status) VALUES (decode(repeat('ab',32),'hex'),12,'image/png','ready')`)
|
||||
if err != nil {
|
||||
t.Fatalf("valid content-addressed file: %v", err)
|
||||
}
|
||||
_, err = db.Pool.Exec(context.Background(), `INSERT INTO files(hash,size_bytes,mime_type,status) VALUES ('bad',12,'image/png','ready')`)
|
||||
if err == nil {
|
||||
t.Fatal("accepted a malformed SHA256")
|
||||
}
|
||||
_, err = db.Pool.Exec(context.Background(), `INSERT INTO files(hash,size_bytes,mime_type,status) VALUES (decode(repeat('ab',32),'hex'),12,'image/png','ready')`)
|
||||
if err == nil {
|
||||
t.Fatal("accepted duplicate content hash")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user