feat(test): Add GenerateRandomSources function for creating random sources

This commit is contained in:
SoXX 2024-08-13 15:41:36 +02:00
parent 2bbfc79e43
commit b7e3877b68

View File

@ -3,10 +3,12 @@ package test
import ( import (
"fmt" "fmt"
"math/rand" "math/rand"
"time"
"git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
gonanoid "github.com/matoous/go-nanoid/v2" gonanoid "github.com/matoous/go-nanoid/v2"
"gorm.io/gorm"
) )
func GenerateRandomTags(numTags int) []models.Tag { func GenerateRandomTags(numTags int) []models.Tag {
@ -67,3 +69,33 @@ func GenerateRandomTagAlias(tags []models.Tag, numGroups int) []models.TagAlias
return tagAliases 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
}