From 8668d504b9f84a5f5ebfd8c4b6e44e4b10ad613a Mon Sep 17 00:00:00 2001 From: SoXX Date: Mon, 12 Aug 2024 15:54:36 +0200 Subject: [PATCH] feat(tests): Add tag generator utility functions for tests --- test/generator.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/generator.go diff --git a/test/generator.go b/test/generator.go new file mode 100644 index 0000000..a8e4fcb --- /dev/null +++ b/test/generator.go @@ -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 +}