From dfa9fe3f1ed80dce7784e1847453feec0ec46fcf Mon Sep 17 00:00:00 2001 From: admju Date: Thu, 12 Sep 2024 13:17:36 +0000 Subject: [PATCH] Gestion des versions --- src/cmd/args.go | 4 ++-- src/install/common.go | 6 +----- src/versionOc/online.go | 6 ++++++ src/versionOc/versionOc.go | 2 +- src/versionOc/versionOc_test.go | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cmd/args.go b/src/cmd/args.go index 8f879bd..7a479fc 100644 --- a/src/cmd/args.go +++ b/src/cmd/args.go @@ -24,7 +24,7 @@ func cobraInstallCmd() *cobra.Command { Long: `deploy Charts`, Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - return InstallCmd(context, "v"+version, modules) + return InstallCmd(context, version, modules) }, Example: "oc-deploy install --version 0.1.0 --context ex1", } @@ -51,7 +51,7 @@ func cobraGenerateCmd() *cobra.Command{ Long: "Value", Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - return GenerateCmd(context, "v"+version) + return GenerateCmd(context, version) }, Example: "oc-deploy generate --version 0.1.0 --context ex1", } diff --git a/src/install/common.go b/src/install/common.go index 0a63a6c..d8f0914 100644 --- a/src/install/common.go +++ b/src/install/common.go @@ -75,10 +75,6 @@ func (this *InstallClass) SetCommands() { this.commandKubectl.New() } -// func (this *InstallClass) SetCommandsMock(mock helm.HelmCommandInterface) { -// this.commandHelm = mock -// } - func (this *InstallClass) getToolBin(name string) (string, error) { for key, value := range this.toolsBin { if key == name { @@ -132,7 +128,7 @@ func (this *InstallClass) extractVersion() (string, error) { } this.Version = version } else { - log.Log().Debug().Msg("Téléchargement du fichier de version") + log.Log().Debug().Msg("Téléchargement du fichier de version "+ this.Version) version, fileversion, err := versionOc.GetFromOnline(this.Version) if err != nil { return "", err diff --git a/src/versionOc/online.go b/src/versionOc/online.go index 3dc361f..2622daf 100644 --- a/src/versionOc/online.go +++ b/src/versionOc/online.go @@ -36,6 +36,7 @@ func GetFromOnline(version string) (string, string, error) { type releaseStruct struct { Id int `json:"id"` Name string `json:"name"` + Message string `json:"message"` } type ocJsonStruct struct { @@ -49,6 +50,7 @@ func readLatestFromOnline() (string, error) { occonst.OCDEPLOY_ONLINE_URL, occonst.OCDEPLOY_ONLINE_REPO) + log.Log().Debug().Msg(url) res, err := http.Get(url) if err != nil { return "", err @@ -64,6 +66,10 @@ func readLatestFromOnline() (string, error) { if err != nil { return "", err } + if len(data.Message) > 0 { + log.Log().Debug().Msg(data.Message) + return "", fmt.Errorf("Dernière version introuvable") + } return data.Name, err } diff --git a/src/versionOc/versionOc.go b/src/versionOc/versionOc.go index cf351f5..1257b6f 100644 --- a/src/versionOc/versionOc.go +++ b/src/versionOc/versionOc.go @@ -26,5 +26,5 @@ func GetFromFile(fileversion string) (string, error) { return "", err } - return objmap.Version, nil + return "v" + objmap.Version, nil } diff --git a/src/versionOc/versionOc_test.go b/src/versionOc/versionOc_test.go index c816250..013e12a 100644 --- a/src/versionOc/versionOc_test.go +++ b/src/versionOc/versionOc_test.go @@ -14,7 +14,7 @@ func TestGetFromFile(t *testing.T) { version, err := GetFromFile(ocyaml) assert.Nilf(t, err, "error message %s", ocyaml) - assert.Equal(t, "99.0", version, "TestGetFromFile error") + assert.Equal(t, "v99.0", version, "TestGetFromFile error") } func TestGetFromFileErr(t *testing.T) {