avoiding #732 by checking for empty versions list for recipe sync

This commit is contained in:
2025-12-18 14:41:58 -08:00
parent b79c4f33b6
commit 9e7bc31d4d
2 changed files with 46 additions and 6 deletions

33
cli/recipe/sync_test.go Normal file
View File

@ -0,0 +1,33 @@
package recipe
import (
"testing"
recipePkg "coopcloud.tech/abra/pkg/recipe"
"github.com/stretchr/testify/assert"
)
func TestGetLatestVersionReturnsDefault(t *testing.T) {
recipe := recipePkg.Recipe{}
catalogue := recipePkg.RecipeCatalogue{}
version := getLatestVersion(recipe, catalogue)
assert.Equal(t, version, "0.0.0")
}
func TestGetLatestVersionReturnsLastVersion(t *testing.T) {
recipe := recipePkg.Recipe{
Name: "test",
}
versions := []map[string]map[string]recipePkg.ServiceMeta{
make(map[string]map[string]recipePkg.ServiceMeta),
make(map[string]map[string]recipePkg.ServiceMeta),
}
versions[0]["0.0.3"] = make(map[string]recipePkg.ServiceMeta)
versions[1]["0.0.2"] = make(map[string]recipePkg.ServiceMeta)
catalogue := make(recipePkg.RecipeCatalogue)
catalogue["test"] = recipePkg.RecipeMeta{
Versions: versions,
}
version := getLatestVersion(recipe, catalogue)
assert.Equal(t, version, "0.0.3")
}