From eb41bc0af3f97a98956c5702c7818a6685ababb2 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 18 Feb 2024 19:02:04 -0800 Subject: [PATCH] chore(test): support followers fixture data for testing --- activitypub/persistence/followers_fixture.go | 36 +++++++++++++++++++ .../persistence/followers_nofixture.go | 8 +++++ activitypub/persistence/persistence.go | 1 + 3 files changed, 45 insertions(+) create mode 100644 activitypub/persistence/followers_fixture.go create mode 100644 activitypub/persistence/followers_nofixture.go diff --git a/activitypub/persistence/followers_fixture.go b/activitypub/persistence/followers_fixture.go new file mode 100644 index 000000000..e58a39a8c --- /dev/null +++ b/activitypub/persistence/followers_fixture.go @@ -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) + } +} diff --git a/activitypub/persistence/followers_nofixture.go b/activitypub/persistence/followers_nofixture.go new file mode 100644 index 000000000..30a881e3f --- /dev/null +++ b/activitypub/persistence/followers_nofixture.go @@ -0,0 +1,8 @@ +//go:build !fixture +// +build !fixture + +package persistence + +func addFollowersFixtureData() { + // no-op +} diff --git a/activitypub/persistence/persistence.go b/activitypub/persistence/persistence.go index 1f631053a..64ec39998 100644 --- a/activitypub/persistence/persistence.go +++ b/activitypub/persistence/persistence.go @@ -27,6 +27,7 @@ func Setup(datastore *data.Datastore) { createFederationFollowersTable() createFederationOutboxTable() createFederatedActivitiesTable() + addFollowersFixtureData() } // AddFollow will save a follow to the datastore.