This commit is contained in:
admju 2024-09-05 07:26:32 +00:00
parent a7a5465a22
commit dddd5d1831
11 changed files with 152 additions and 91 deletions

View File

@ -1,16 +1,27 @@
package helm
import (
"fmt"
// "os"
// "path/filepath"
"testing"
// "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
func TestHelmRepoAdd(t *testing.T) {
// fmt.Println(" TestVersion ", TEST_BIN_DIR)
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)
@ -21,3 +32,17 @@ func TestHelmRepoAdd(t *testing.T){
// 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")
}

View File

@ -18,7 +18,6 @@ type InstallClass struct {
Version string
Workspace string
// versionFile string
tools []tool.ToolData
toolsBin map[string]string
charts []chart.ChartRepoData

View File

@ -1,13 +1,12 @@
package tool
import (
// "os"
"fmt"
"path/filepath"
"testing"
// "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
)
func TestToolConf(t *testing.T) {
@ -17,12 +16,12 @@ func TestToolConf(t *testing.T) {
data, err := FromConfigFile(src)
fmt.Println("data", src, data, err)
// bin := filepath.Join(TEST_BIN_DIR, "kubectl")
// os.Chmod(bin, 0700)
// assert.FileExists(t, bin, "TestKubectlVersion error")
bin := filepath.Join(TEST_BIN_DIR, "kubectl")
os.Chmod(bin, 0700)
assert.FileExists(t, bin, "TestKubectlVersion error")
// version, err := Version(bin)
version, err := Version(bin)
// assert.Nilf(t, err, "error message %s", bin)
// assert.Equal(t, "v1.30.3", version, "TestKubectlVersion error")
assert.Nilf(t, err, "error message %s", bin)
assert.Equal(t, "v1.30.3", version, "TestKubectlVersion error")
}

0
src/tool/helm_test.go Normal file
View File

View File

@ -45,3 +45,13 @@ func TestCopyErrSrcWrite(t *testing.T) {
assert.NotNilf(t, err, "CopyFile error %s", src)
}
func TestCopyContentFile(t *testing.T) {
content := "TestCopyContentFileExist"
dest := filepath.Join(TEST_DEST_DIR, "fichier1")
err := CopyContentFile(content, dest)
assert.Nilf(t, err, "error message")
assert.FileExists(t, dest, "CopyFile error")
}

View File

@ -15,6 +15,7 @@ import (
func GetFromOnline(version string) (string, string, error) {
fmt.Println(" ONLINE 18")
version2 := version
if version == "latest" {
versionLatest, err := readLatestFromOnline()
@ -90,7 +91,6 @@ func getFileVersion(version string) (string, error) {
}
var data ocJsonStruct
err = json.Unmarshal(body, &data)
if err != nil {
return "", err
@ -103,30 +103,3 @@ func getFileVersion(version string) (string, error) {
return string(data64), nil
}
// Cherche l'Id de la release
func getIdRelease(version string) (int, error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION,
version)
res, err := http.Get(url)
if err != nil {
return 0, err
}
body, err := io.ReadAll(res.Body)
if err != nil {
return 0, err
}
var data releaseStruct
err = json.Unmarshal(body, &data)
if err != nil {
return 0, err
}
return data.Id, nil
}

View File

@ -0,0 +1,62 @@
package versionOc
import (
"fmt"
"testing"
// "encoding/base64"
"oc-deploy/occonst"
"github.com/stretchr/testify/assert"
"github.com/jarcoal/httpmock"
)
//
func TestGetOnline(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
version := "99.1"
url := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION,
version)
httpmock.RegisterResponder("GET", url,
httpmock.NewStringResponder(200, `{"value": "e30K"}`))
res, _, err := GetFromOnline(version)
assert.Nilf(t, err, "error message %s", err)
assert.Equal(t, version, res, "TestGetOnline error")
}
func TestGetOnlineLatest(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
// version := "99.1"
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/latest",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION)
httpmock.RegisterResponder("GET", url,
httpmock.NewStringResponder(200, `{"name": "99.0", "id": 2}`))
version := "99.0"
url2 := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
occonst.ONLINE_URL,
occonst.ONLINE_VERSION,
version)
httpmock.RegisterResponder("GET", url2,
httpmock.NewStringResponder(200, `{"value": "e30K"}`))
version, _, err := GetFromOnline("latest")
assert.Nilf(t, err, "error message %s", err)
assert.Equal(t, "99.0", version, "TestGetFromFile error")
fmt.Println("TestGetOnlineLatest ", version, err)
}

View File

@ -25,18 +25,10 @@ func TestGetFromFileErr(t *testing.T) {
assert.NotNilf(t, err, "error message %s", ocyaml)
}
// func TestGet(t *testing.T) {
func TestGetFromFileErr2(t *testing.T) {
// _, err := Get("99.1")
// assert.NotNilf(t, err, "error message %s", err)
// }
ocyaml := filepath.Join(TEST_SRC_DIR, "oc_error.yml")
_, err := GetFromFile(ocyaml)
// func TestGetLatest(t *testing.T) {
// OFFLINE_DIR = filepath.Join(TEST_SRC_DIR, "offline")
// version, err := Get("latest")
// assert.Nilf(t, err, "error message %s", err)
// assert.Equal(t, "99.1", version, "TestGetFromFile error")
// }
assert.NotNilf(t, err, "error message %s", ocyaml)
}

View File

@ -0,0 +1 @@
N'est pas un fichier