MockActor creates a new actor in the database.
(t *testing.T, tx *gorm.DB, name, domain string, opts ...func(*Actor))
| 22 | // MockActor creates a new actor in the database. |
| 23 | func MockActor(t *testing.T, tx *gorm.DB, name, domain string, opts ...func(*Actor)) *Actor { |
| 24 | t.Helper() |
| 25 | require := require.New(t) |
| 26 | |
| 27 | kp, err := crypto.GenerateRSAKeypair() |
| 28 | require.NoError(err) |
| 29 | |
| 30 | actor := &Actor{ |
| 31 | ID: snowflake.Now(), |
| 32 | URI: fmt.Sprintf("https://%s/%s", domain, name), |
| 33 | Name: name, |
| 34 | Domain: domain, |
| 35 | DisplayName: name, |
| 36 | Avatar: "https://avatars.githubusercontent.com/u/1024?v=4", |
| 37 | Header: "https://avatars.githubusercontent.com/u/1024?v=4", |
| 38 | PublicKey: kp.PublicKey, |
| 39 | } |
| 40 | for _, opt := range opts { |
| 41 | opt(actor) |
| 42 | } |
| 43 | require.NoError(tx.Create(actor).Error) |
| 44 | return actor |
| 45 | } |
| 46 | |
| 47 | func MockStatus(t *testing.T, tx *gorm.DB, actor *Actor, note string) *Status { |
no test coverage detected