feat(tests): Add tag generator utility functions for tests
Some checks failed
Gitea Build Check / Build (push) Failing after 30s

This commit is contained in:
SoXX 2024-08-12 15:54:36 +02:00
parent a4792f5d67
commit 8668d504b9

69
test/generator.go Normal file
View File

@ -0,0 +1,69 @@
package test
import (
"fmt"
"math/rand"
"git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models"
"github.com/davecgh/go-spew/spew"
gonanoid "github.com/matoous/go-nanoid/v2"
)
func GenerateRandomTags(numTags int) []models.Tag {
var tags []models.Tag
tagTypes := []models.TagType{"general", "species", "character", "artist", "lore", "meta", "invalid", "copyright"}
for i := 0; i < numTags; i++ {
id, _ := gonanoid.New(10)
tagName := spew.Sprintf("tag_name_%s", id)
tagType := tagTypes[rand.Intn(len(tagTypes))]
tag := models.Tag{
Name: models.TagName(tagName),
Type: tagType,
}
tags = append(tags, tag)
}
return tags
}
func GenerateRandomTagGroups(tags []models.Tag, numGroups int) []models.TagGroup {
var tagGroups []models.TagGroup
for i := 0; i < numGroups; i++ {
id, _ := gonanoid.New(10)
groupName := fmt.Sprintf("tag_group_%s", id)
randomTag := tags[rand.Intn(len(tags))]
tagGroup := models.TagGroup{
Name: models.TagGroupName(groupName),
TagID: randomTag.Name,
}
tagGroups = append(tagGroups, tagGroup)
}
return tagGroups
}
func GenerateRandomTagAlias(tags []models.Tag, numGroups int) []models.TagAlias {
var tagAliases []models.TagAlias
for i := 0; i < numGroups; i++ {
id, _ := gonanoid.New(10)
groupName := fmt.Sprintf("tag_alias_%s", id)
randomTag := tags[rand.Intn(len(tags))]
tagAlias := models.TagAlias{
Name: models.TagAliasName(groupName),
TagID: randomTag.Name,
}
tagAliases = append(tagAliases, tagAlias)
}
return tagAliases
}