This simplifies the deploy overview, to only show 3 version fields: - CURRENT DEPLOYMENT - CURRENT ENV - NEW DEPLOYMENT It also fixes a few errors around version detection Reviewed-on: #508 Co-authored-by: p4u1 <p4u1_f4u1@riseup.net> Co-committed-by: p4u1 <p4u1_f4u1@riseup.net>
125 lines
4.7 KiB
Go
125 lines
4.7 KiB
Go
package recipe
|
|
|
|
import (
|
|
"path"
|
|
"testing"
|
|
|
|
"coopcloud.tech/abra/pkg/config"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGet(t *testing.T) {
|
|
cfg := config.LoadAbraConfig()
|
|
testcases := []struct {
|
|
name string
|
|
recipe Recipe
|
|
}{
|
|
{
|
|
name: "foo",
|
|
recipe: Recipe{
|
|
Name: "foo",
|
|
Dir: path.Join(cfg.GetAbraDir(), "/recipes/foo"),
|
|
GitURL: "https://git.coopcloud.tech/coop-cloud/foo.git",
|
|
SSHURL: "ssh://git@git.coopcloud.tech:2222/coop-cloud/foo.git",
|
|
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/foo/compose.yml"),
|
|
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/foo/README.md"),
|
|
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/foo/.env.sample"),
|
|
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/foo/abra.sh"),
|
|
},
|
|
},
|
|
{
|
|
name: "foo:1.2.3",
|
|
recipe: Recipe{
|
|
Name: "foo",
|
|
EnvVersion: "1.2.3",
|
|
EnvVersionRaw: "1.2.3",
|
|
Dir: path.Join(cfg.GetAbraDir(), "/recipes/foo"),
|
|
GitURL: "https://git.coopcloud.tech/coop-cloud/foo.git",
|
|
SSHURL: "ssh://git@git.coopcloud.tech:2222/coop-cloud/foo.git",
|
|
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/foo/compose.yml"),
|
|
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/foo/README.md"),
|
|
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/foo/.env.sample"),
|
|
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/foo/abra.sh"),
|
|
},
|
|
},
|
|
{
|
|
name: "mygit.org/myorg/cool-recipe",
|
|
recipe: Recipe{
|
|
Name: "mygit.org/myorg/cool-recipe",
|
|
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
|
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
|
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
|
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
|
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
|
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
|
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
|
},
|
|
},
|
|
{
|
|
name: "mygit.org/myorg/cool-recipe:1.2.4",
|
|
recipe: Recipe{
|
|
Name: "mygit.org/myorg/cool-recipe",
|
|
EnvVersion: "1.2.4",
|
|
EnvVersionRaw: "1.2.4",
|
|
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
|
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
|
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
|
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
|
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
|
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
|
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
|
},
|
|
},
|
|
{
|
|
name: "mygit.org/myorg/cool-recipe:1e83340e+U",
|
|
recipe: Recipe{
|
|
Name: "mygit.org/myorg/cool-recipe",
|
|
EnvVersion: "1e83340e",
|
|
EnvVersionRaw: "1e83340e+U",
|
|
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
|
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
|
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
|
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
|
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
|
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
|
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testcases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Setenv("ABRA_DIR", "<abraDir>")
|
|
recipe := Get(tc.name)
|
|
if diff := cmp.Diff(tc.recipe, recipe); diff != "" {
|
|
t.Errorf("Recipe mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetVersionLabelLocalDoesNotUseTimeoutLabel(t *testing.T) {
|
|
r := Get("traefik")
|
|
if err := r.EnsureExists(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
for i := 1; i < 50; i++ {
|
|
label, err := r.GetVersionLabelLocal()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// NOTE(d1): this is potentially quite a brittle unit test as it needs to
|
|
// hardcode the default timeout label to ensure that the label parser never
|
|
// returns it. hopefully this won't fail too often! if you're here because
|
|
// of a failure, just update the `defaultTimeoutLabel` value & permalink
|
|
// below
|
|
// https://git.coopcloud.tech/coop-cloud/traefik/src/commit/ac3a47fe8ca3ef92db84f64cfedfbb348000faee/.env.sample#L2
|
|
defaultTimeoutLabel := "300"
|
|
assert.NotEqual(t, label, defaultTimeoutLabel)
|
|
}
|
|
}
|