From b7e3877b68deab2dc1d7343a531b73026a63709b Mon Sep 17 00:00:00 2001 From: SoXX Date: Tue, 13 Aug 2024 15:41:36 +0200 Subject: [PATCH] feat(test): Add GenerateRandomSources function for creating random sources --- test/generator.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/generator.go b/test/generator.go index a8e4fcb..2e91ad7 100644 --- a/test/generator.go +++ b/test/generator.go @@ -3,10 +3,12 @@ package test import ( "fmt" "math/rand" + "time" "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" "github.com/davecgh/go-spew/spew" gonanoid "github.com/matoous/go-nanoid/v2" + "gorm.io/gorm" ) func GenerateRandomTags(numTags int) []models.Tag { @@ -67,3 +69,33 @@ func GenerateRandomTagAlias(tags []models.Tag, numGroups int) []models.TagAlias return tagAliases } + +func GenerateRandomSources(numTags int) []models.Source { + var sources []models.Source + + for i := 0; i < numTags; i++ { + id, _ := gonanoid.New(10) + displayName, _ := gonanoid.New(10) + domain, _ := gonanoid.New(10) + icon, _ := gonanoid.New(10) + id = spew.Sprintf("source_name_%s", id) + + source := models.Source{ + BaseModel: models.BaseModel[models.SourceID]{ + ID: models.SourceID(id), + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + DeletedAt: gorm.DeletedAt{}, + }, + DisplayName: displayName, + Domain: models.SourceDomain(domain), + Icon: icon, + UserSources: nil, + References: nil, + } + + sources = append(sources, source) + } + + return sources +}