test
This commit is contained in:
@@ -1,53 +1,53 @@
|
||||
package helm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"os/exec"
|
||||
"fmt"
|
||||
"strings"
|
||||
"os/exec"
|
||||
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
|
||||
type HelmRepo struct {
|
||||
Bin string // Chemin vers le binaire
|
||||
Bin string // Chemin vers le binaire
|
||||
Name string
|
||||
Repository string // Url du dépôt
|
||||
ForceUpdate bool
|
||||
Opts string
|
||||
Repository string // Url du dépôt
|
||||
ForceUpdate bool
|
||||
Opts string
|
||||
}
|
||||
|
||||
func (this HelmRepo) AddRepository() (string, error) {
|
||||
helm_bin := this.Bin
|
||||
helm_bin := this.Bin
|
||||
|
||||
force_update := "--force-update=false"
|
||||
if this.ForceUpdate {
|
||||
force_update = "--force-update=true"
|
||||
}
|
||||
force_update := "--force-update=false"
|
||||
if this.ForceUpdate {
|
||||
force_update = "--force-update=true"
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("%s repo add %s %s %s %s", helm_bin, this.Name, this.Repository, force_update, this.Opts)
|
||||
log.Log().Debug().Msg(msg)
|
||||
msg := fmt.Sprintf("%s repo add %s %s %s %s", helm_bin, this.Name, this.Repository, force_update, this.Opts)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd := exec.Command(helm_bin, "repo", "add", this.Name, this.Repository, force_update)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
cmd := exec.Command(helm_bin, "repo", "add", this.Name, this.Repository, force_update)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
return res, err
|
||||
return res, err
|
||||
}
|
||||
|
||||
// helm repo remove [NAME]
|
||||
func (this HelmRepo) RemoveRepository() (string, error) {
|
||||
helm_bin := this.Bin
|
||||
helm_bin := this.Bin
|
||||
|
||||
msg := fmt.Sprintf("%s repo remove %s", helm_bin, this.Name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
msg := fmt.Sprintf("%s repo remove %s", helm_bin, this.Name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
cmd := exec.Command(helm_bin, "repo", "remove", this.Name)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
cmd := exec.Command(helm_bin, "repo", "remove", this.Name)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
res := string(stdout)
|
||||
res = strings.TrimSuffix(res, "\n")
|
||||
|
||||
return res, err
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -1,23 +1,48 @@
|
||||
package helm
|
||||
|
||||
import (
|
||||
// "os"
|
||||
// "path/filepath"
|
||||
"fmt"
|
||||
// "os"
|
||||
// "path/filepath"
|
||||
|
||||
"testing"
|
||||
"testing"
|
||||
|
||||
// "github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHelmRepoAdd(t *testing.T){
|
||||
// fmt.Println(" TestVersion ", TEST_BIN_DIR)
|
||||
|
||||
// bin := filepath.Join(TEST_BIN_DIR, "helm")
|
||||
// os.Chmod(bin, 0700)
|
||||
func TestHelmRepoAdd(t *testing.T) {
|
||||
|
||||
repo := HelmRepo{
|
||||
Bin: "./helm",
|
||||
Name: "repooc",
|
||||
Repository: "https://url",
|
||||
ForceUpdate: true,
|
||||
Opts: ""}
|
||||
fmt.Println(" TestHelmRepoAdd ", repo)
|
||||
|
||||
res, err := repo.AddRepository()
|
||||
fmt.Println("TestHelmRepoAdd.24", res, err)
|
||||
|
||||
// bin := filepath.Join(TEST_BIN_DIR, "helm")
|
||||
// os.Chmod(bin, 0700)
|
||||
// assert.FileExists(t, bin, "TestHelmVersion error")
|
||||
|
||||
// version, err := Version(bin)
|
||||
// version, err := Version(bin)
|
||||
|
||||
// assert.Nilf(t, err, "error message %s", bin)
|
||||
// assert.Equal(t, version, "v3.15.4+gfa9efb0", "TestHelmVersion error")
|
||||
// assert.Nilf(t, err, "error message %s", bin)
|
||||
// assert.Equal(t, version, "v3.15.4+gfa9efb0", "TestHelmVersion error")
|
||||
}
|
||||
|
||||
// helm : not found
|
||||
func TestHelmRepoAddErr(t *testing.T) {
|
||||
|
||||
repo := HelmRepo{
|
||||
Bin: "./helm",
|
||||
Name: "repooc",
|
||||
Repository: "https://url",
|
||||
ForceUpdate: true,
|
||||
Opts: ""}
|
||||
|
||||
_, err := repo.AddRepository()
|
||||
assert.NotNilf(t, err, "error message %s", "./helm")
|
||||
}
|
||||
Reference in New Issue
Block a user