Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 42f9e6d458 | |||
| 9e7bc31d4d |
@ -1,6 +1,7 @@
|
|||||||
package recipe
|
package recipe
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -19,6 +20,9 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Errors
|
||||||
|
var emptyVersionsInCatalogue = errors.New("Catalogue versions list is empty (unexpectedly!)")
|
||||||
|
|
||||||
// translators: `abra recipe reset` aliases. use a comma separated list of
|
// translators: `abra recipe reset` aliases. use a comma separated list of
|
||||||
// aliases with no spaces in between
|
// aliases with no spaces in between
|
||||||
var recipeSyncAliases = i18n.G("s")
|
var recipeSyncAliases = i18n.G("s")
|
||||||
@ -121,20 +125,18 @@ likely to change.
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
versions, err := recipePkg.GetRecipeCatalogueVersions(recipe.Name, catl)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
changesTable, err := formatter.CreateTable()
|
changesTable, err := formatter.CreateTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
latestRelease := tags[len(tags)-1]
|
latestRelease := tags[len(tags)-1]
|
||||||
|
latestRecipeVersion, err := getLatestVersion(recipe, catl)
|
||||||
|
if err != nil && err != emptyVersionsInCatalogue {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
changesTable.Headers(i18n.G("SERVICE"), latestRelease, i18n.G("PROPOSED CHANGES"))
|
changesTable.Headers(i18n.G("SERVICE"), latestRelease, i18n.G("PROPOSED CHANGES"))
|
||||||
|
|
||||||
latestRecipeVersion := versions[len(versions)-1]
|
|
||||||
allRecipeVersions := catl[recipe.Name].Versions
|
allRecipeVersions := catl[recipe.Name].Versions
|
||||||
for _, recipeVersion := range allRecipeVersions {
|
for _, recipeVersion := range allRecipeVersions {
|
||||||
if serviceVersions, ok := recipeVersion[latestRecipeVersion]; ok {
|
if serviceVersions, ok := recipeVersion[latestRecipeVersion]; ok {
|
||||||
@ -298,3 +300,14 @@ func init() {
|
|||||||
i18n.G("increase the patch part of the version"),
|
i18n.G("increase the patch part of the version"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getLatestVersion(recipe recipePkg.Recipe, catl recipePkg.RecipeCatalogue) (string, error) {
|
||||||
|
versions, err := recipePkg.GetRecipeCatalogueVersions(recipe.Name, catl)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if len(versions) > 0 {
|
||||||
|
return versions[len(versions)-1], nil
|
||||||
|
}
|
||||||
|
return "", emptyVersionsInCatalogue
|
||||||
|
}
|
||||||
|
|||||||
33
cli/recipe/sync_test.go
Normal file
33
cli/recipe/sync_test.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package recipe
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetLatestVersionReturnsErrorWhenVersionsIsEmpty(t *testing.T) {
|
||||||
|
recipe := recipePkg.Recipe{}
|
||||||
|
catalogue := recipePkg.RecipeCatalogue{}
|
||||||
|
_, err := getLatestVersion(recipe, catalogue)
|
||||||
|
assert.Equal(t, err, emptyVersionsInCatalogue)
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user