test
This commit is contained in:
parent
d12d3e31bf
commit
48301bf82e
@ -18,7 +18,7 @@ help:
|
||||
@echo
|
||||
@echo 'Usage:'
|
||||
@echo ' make build Génère les exécutables.'
|
||||
@echo ' make get-deps runs dep ensure, mostly used for ci.'
|
||||
@echo ' make get-deps Dependency download'
|
||||
|
||||
@echo ' make run BIN_OPTS=... Go run'
|
||||
@echo ' make run_install BIN_OPTS=... Go run'
|
||||
|
@ -18,5 +18,5 @@ func TestHelmVersion(t *testing.T){
|
||||
version, err := Version(bin)
|
||||
|
||||
assert.Nilf(t, err, "error message %s", bin)
|
||||
assert.Equal(t, version, "v3.15.4+gfa9efb0", "TestHelmVersion error")
|
||||
assert.Equal(t, "v3.15.4+gfa9efb0", version, "TestHelmVersion error")
|
||||
}
|
24
src/kubectl/main_test.go
Normal file
24
src/kubectl/main_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package kubectl
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var TEST_DEST_DIR = "../wrk_kubectl"
|
||||
var TEST_SRC_DIR = filepath.Join("../../test", "kubectl")
|
||||
var TEST_BIN_DIR = filepath.Join("../../test", "bin")
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
folderPath := TEST_DEST_DIR
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
exitCode := m.Run()
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.Exit(exitCode)
|
||||
}
|
22
src/kubectl/version_test.go
Normal file
22
src/kubectl/version_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package kubectl
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestKubectlVersion(t *testing.T){
|
||||
|
||||
bin := filepath.Join(TEST_BIN_DIR, "kubectl")
|
||||
os.Chmod(bin, 0700)
|
||||
assert.FileExists(t, bin, "TestKubectlVersion error")
|
||||
|
||||
version, err := Version(bin)
|
||||
|
||||
assert.Nilf(t, err, "error message %s", bin)
|
||||
assert.Equal(t, "v1.30.3", version, "TestKubectlVersion error")
|
||||
}
|
28
src/tool/conf_test.go
Normal file
28
src/tool/conf_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
// "os"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"testing"
|
||||
|
||||
// "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestToolConf(t *testing.T) {
|
||||
|
||||
src := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||
|
||||
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")
|
||||
|
||||
// version, err := Version(bin)
|
||||
|
||||
// assert.Nilf(t, err, "error message %s", bin)
|
||||
// assert.Equal(t, "v1.30.3", version, "TestKubectlVersion error")
|
||||
}
|
@ -22,7 +22,6 @@ func (this HelmInstallData) Download() (error) {
|
||||
bin_dir := this.obj.Bin
|
||||
err2 := os.MkdirAll(bin_dir, os.ModePerm)
|
||||
if err2 != nil {
|
||||
fmt.Println(err2)
|
||||
return err2
|
||||
}
|
||||
|
||||
|
24
src/tool/main_test.go
Normal file
24
src/tool/main_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package tool
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var TEST_DEST_DIR = "../wrk_tool"
|
||||
var TEST_SRC_DIR = filepath.Join("../../test", "tool")
|
||||
var TEST_BIN_DIR = filepath.Join("../../test", "bin")
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
folderPath := TEST_DEST_DIR
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
exitCode := m.Run()
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.Exit(exitCode)
|
||||
}
|
23
src/versionOc/main_test.go
Normal file
23
src/versionOc/main_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
package versionOc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var TEST_DEST_DIR = "../wrk_versionOc"
|
||||
var TEST_SRC_DIR = filepath.Join("../../test", "versionOc")
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
folderPath := TEST_DEST_DIR
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
exitCode := m.Run()
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.Exit(exitCode)
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"errors"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"gopkg.in/yaml.v2"
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
@ -14,6 +15,8 @@ type versionInput struct {
|
||||
Version string `yaml:"version"`
|
||||
}
|
||||
|
||||
var OFFLINE_DIR string = "../offline"
|
||||
|
||||
func GetFromFile(fileversion string) (string, error) {
|
||||
fin, err := os.Open(fileversion)
|
||||
if err != nil {
|
||||
@ -28,7 +31,10 @@ func GetFromFile(fileversion string) (string, error) {
|
||||
|
||||
var objmap versionInput
|
||||
|
||||
yaml.Unmarshal(byteValue, &objmap)
|
||||
err = yaml.Unmarshal(byteValue, &objmap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return objmap.Version, nil
|
||||
}
|
||||
@ -45,7 +51,8 @@ func Get(version string) (string, error) {
|
||||
version2 = versionLatest
|
||||
}
|
||||
|
||||
src := fmt.Sprintf("../offline/oc_%s.yml", version2)
|
||||
ficversion := fmt.Sprintf("oc_%s.yml", version2)
|
||||
src := filepath.Join(OFFLINE_DIR, ficversion)
|
||||
if _, err := os.Stat(src); err != nil {
|
||||
log.Log().Debug().Msg(err.Error())
|
||||
return "", errors.New("Version non disponible")
|
||||
@ -56,9 +63,10 @@ func Get(version string) (string, error) {
|
||||
|
||||
// readLatestFile : Lit le numéro de la version dans le fichier lastest.yml
|
||||
func readLatestFile() (string, error) {
|
||||
src := "../offline/latest.yml"
|
||||
src := filepath.Join(OFFLINE_DIR, "latest.yml")
|
||||
|
||||
fin, err := os.Open(src)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -71,7 +79,11 @@ func readLatestFile() (string, error) {
|
||||
|
||||
var objmap versionInput
|
||||
|
||||
yaml.Unmarshal(byteValue, &objmap)
|
||||
err = yaml.Unmarshal(byteValue, &objmap)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return objmap.Version, nil
|
||||
}
|
||||
|
42
src/versionOc/versionOc_test.go
Normal file
42
src/versionOc/versionOc_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package versionOc
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetFromFile(t *testing.T) {
|
||||
|
||||
ocyaml := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||
version, err := GetFromFile(ocyaml)
|
||||
|
||||
assert.Nilf(t, err, "error message %s", ocyaml)
|
||||
assert.Equal(t, "99.0", version, "TestGetFromFile error")
|
||||
}
|
||||
|
||||
func TestGetFromFileErr(t *testing.T) {
|
||||
|
||||
ocyaml := filepath.Join(TEST_SRC_DIR, "inconnu.yml")
|
||||
_, err := GetFromFile(ocyaml)
|
||||
|
||||
assert.NotNilf(t, err, "error message %s", ocyaml)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
|
||||
_, err := Get("99.1")
|
||||
assert.NotNilf(t, err, "error message %s", err)
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
}
|
0
test/bin/kubectl
Normal file → Executable file
0
test/bin/kubectl
Normal file → Executable file
4
test/tool/oc.yml
Normal file
4
test/tool/oc.yml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
tools:
|
||||
|
3
test/versionOc/oc.yml
Normal file
3
test/versionOc/oc.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
|
||||
version: 99.0
|
3
test/versionOc/offline/latest.yml
Normal file
3
test/versionOc/offline/latest.yml
Normal file
@ -0,0 +1,3 @@
|
||||
---
|
||||
|
||||
version: 99.1
|
1
test/versionOc/offline/oc_99.1.yml
Normal file
1
test/versionOc/offline/oc_99.1.yml
Normal file
@ -0,0 +1 @@
|
||||
---
|
Loading…
Reference in New Issue
Block a user