mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
chore(test): support followers fixture data for testing
This commit is contained in:
parent
3b50e87015
commit
eb41bc0af3
36
activitypub/persistence/followers_fixture.go
Normal file
36
activitypub/persistence/followers_fixture.go
Normal file
@ -0,0 +1,36 @@
|
||||
//go:build fixture
|
||||
// +build fixture
|
||||
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/owncast/owncast/models"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func addFollowersFixtureData() {
|
||||
log.Println("Adding followers fixture data...")
|
||||
file, err := os.Open("./test/fixture/followers_fixture.json")
|
||||
if err != nil {
|
||||
fmt.Println("Error opening file:", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var followers []models.Follower
|
||||
decoder := json.NewDecoder(file)
|
||||
err = decoder.Decode(&followers)
|
||||
if err != nil {
|
||||
fmt.Println("Error decoding JSON:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Iterate over the followers array
|
||||
for _, follower := range followers {
|
||||
createFollow(follower.ActorIRI, follower.Inbox, "", follower.Name, follower.Username, follower.Image, nil, true)
|
||||
}
|
||||
}
|
||||
8
activitypub/persistence/followers_nofixture.go
Normal file
8
activitypub/persistence/followers_nofixture.go
Normal file
@ -0,0 +1,8 @@
|
||||
//go:build !fixture
|
||||
// +build !fixture
|
||||
|
||||
package persistence
|
||||
|
||||
func addFollowersFixtureData() {
|
||||
// no-op
|
||||
}
|
||||
@ -27,6 +27,7 @@ func Setup(datastore *data.Datastore) {
|
||||
createFederationFollowersTable()
|
||||
createFederationOutboxTable()
|
||||
createFederatedActivitiesTable()
|
||||
addFollowersFixtureData()
|
||||
}
|
||||
|
||||
// AddFollow will save a follow to the datastore.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user