chore(test): support followers fixture data for testing

This commit is contained in:
Gabe Kangas 2024-02-18 19:02:04 -08:00
parent 3b50e87015
commit eb41bc0af3
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
3 changed files with 45 additions and 0 deletions

View 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)
}
}

View File

@ -0,0 +1,8 @@
//go:build !fixture
// +build !fixture
package persistence
func addFollowersFixtureData() {
// no-op
}

View File

@ -27,6 +27,7 @@ func Setup(datastore *data.Datastore) {
createFederationFollowersTable()
createFederationOutboxTable()
createFederatedActivitiesTable()
addFollowersFixtureData()
}
// AddFollow will save a follow to the datastore.