test
This commit is contained in:
		| @@ -18,7 +18,7 @@ help: | |||||||
| 		@echo | 		@echo | ||||||
| 		@echo 'Usage:' | 		@echo 'Usage:' | ||||||
| 		@echo '    make build                Génère les exécutables.' | 		@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 BIN_OPTS=...     Go run' | ||||||
| 		@echo '    make run_install BIN_OPTS=...     Go run' | 		@echo '    make run_install BIN_OPTS=...     Go run' | ||||||
|   | |||||||
| @@ -7,14 +7,14 @@ import ( | |||||||
|  |  | ||||||
| func Version(path string) (string, error) { | func Version(path string) (string, error) { | ||||||
|  |  | ||||||
| 	cmd := exec.Command(path, "version", "--short") |     cmd := exec.Command(path, "version", "--short") | ||||||
| 	stdout, err := cmd.CombinedOutput() |     stdout, err := cmd.CombinedOutput() | ||||||
|  |  | ||||||
|     if err != nil { |     if err != nil { | ||||||
|         return "", err |         return "", err | ||||||
|     } |     } | ||||||
|  |  | ||||||
| 	res := string(stdout) |     res := string(stdout) | ||||||
| 	res = strings.TrimSuffix(res, "\n") |     res = strings.TrimSuffix(res, "\n") | ||||||
|     return res, nil |     return res, nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,22 +1,22 @@ | |||||||
| package helm | package helm | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"os" |     "os" | ||||||
| 	"path/filepath" |     "path/filepath" | ||||||
|  |  | ||||||
| 	"testing" |     "testing" | ||||||
|  |  | ||||||
|     "github.com/stretchr/testify/assert" |     "github.com/stretchr/testify/assert" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func TestHelmVersion(t *testing.T){ | func TestHelmVersion(t *testing.T){ | ||||||
|      |      | ||||||
| 	bin := filepath.Join(TEST_BIN_DIR, "helm") |     bin := filepath.Join(TEST_BIN_DIR, "helm") | ||||||
| 	os.Chmod(bin, 0700) |     os.Chmod(bin, 0700) | ||||||
|     assert.FileExists(t, bin, "TestHelmVersion error") |     assert.FileExists(t, bin, "TestHelmVersion error") | ||||||
|  |  | ||||||
| 	version, err := Version(bin) |     version, err := Version(bin) | ||||||
|  |  | ||||||
| 	assert.Nilf(t, err, "error message %s", 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) | ||||||
|  | } | ||||||
| @@ -6,25 +6,25 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type toolClientVersion struct { | type toolClientVersion struct { | ||||||
| 	GitVersion string `json:"gitVersion"` |     GitVersion string `json:"gitVersion"` | ||||||
| } | } | ||||||
|  |  | ||||||
| type toolVersion struct { | type toolVersion struct { | ||||||
| 	ClientVersion toolClientVersion `json:"clientVersion"` |     ClientVersion toolClientVersion `json:"clientVersion"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func Version(path string) (string, error) { | func Version(path string) (string, error) { | ||||||
|  |  | ||||||
| 	cmd := exec.Command(path, "version", "-o", "json", "--client=true") |     cmd := exec.Command(path, "version", "-o", "json", "--client=true") | ||||||
| 	stdout, err := cmd.CombinedOutput() |     stdout, err := cmd.CombinedOutput() | ||||||
|  |  | ||||||
|     if err != nil { |     if err != nil { | ||||||
|         return "", err |         return "", err | ||||||
|     } |     } | ||||||
|  |  | ||||||
| 	var objmap toolVersion |     var objmap toolVersion | ||||||
|  |  | ||||||
| 	json.Unmarshal(stdout, &objmap) |     json.Unmarshal(stdout, &objmap) | ||||||
|     res := objmap.ClientVersion.GitVersion |     res := objmap.ClientVersion.GitVersion | ||||||
|  |  | ||||||
|     return res, nil |     return res, nil | ||||||
|   | |||||||
							
								
								
									
										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 |     bin_dir := this.obj.Bin | ||||||
|     err2 := os.MkdirAll(bin_dir, os.ModePerm) |     err2 := os.MkdirAll(bin_dir, os.ModePerm) | ||||||
|     if err2 != nil { |     if err2 != nil { | ||||||
|         fmt.Println(err2) |  | ||||||
|         return 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" |     "os" | ||||||
|     "errors" |     "errors" | ||||||
|     "io" |     "io" | ||||||
|  |     "path/filepath" | ||||||
|     "gopkg.in/yaml.v2" |     "gopkg.in/yaml.v2" | ||||||
|     log "oc-deploy/log_wrapper" |     log "oc-deploy/log_wrapper" | ||||||
| ) | ) | ||||||
| @@ -14,6 +15,8 @@ type versionInput struct { | |||||||
|     Version string  `yaml:"version"` |     Version string  `yaml:"version"` | ||||||
| } | } | ||||||
|  |  | ||||||
|  | var OFFLINE_DIR string = "../offline" | ||||||
|  |  | ||||||
| func GetFromFile(fileversion string) (string, error) { | func GetFromFile(fileversion string) (string, error) { | ||||||
|     fin, err := os.Open(fileversion) |     fin, err := os.Open(fileversion) | ||||||
|     if err != nil { |     if err != nil { | ||||||
| @@ -28,7 +31,10 @@ func GetFromFile(fileversion string) (string, error) { | |||||||
|  |  | ||||||
|     var objmap versionInput |     var objmap versionInput | ||||||
|  |  | ||||||
|     yaml.Unmarshal(byteValue, &objmap) |     err = yaml.Unmarshal(byteValue, &objmap) | ||||||
|  |     if err != nil { | ||||||
|  |         return "", err | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return objmap.Version, nil |     return objmap.Version, nil | ||||||
| } | } | ||||||
| @@ -45,7 +51,8 @@ func Get(version string) (string, error) { | |||||||
|         version2 = versionLatest |         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 { |     if _, err := os.Stat(src); err != nil { | ||||||
|         log.Log().Debug().Msg(err.Error()) |         log.Log().Debug().Msg(err.Error()) | ||||||
|         return "", errors.New("Version non disponible") |         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 | // readLatestFile : Lit le numéro de la version dans le fichier lastest.yml | ||||||
| func readLatestFile() (string, error) { | func readLatestFile() (string, error) { | ||||||
|     src := "../offline/latest.yml" |     src := filepath.Join(OFFLINE_DIR, "latest.yml") | ||||||
|  |  | ||||||
|     fin, err := os.Open(src) |     fin, err := os.Open(src) | ||||||
|  |  | ||||||
|     if err != nil { |     if err != nil { | ||||||
|         return "", err |         return "", err | ||||||
|     } |     } | ||||||
| @@ -71,7 +79,11 @@ func readLatestFile() (string, error) { | |||||||
|  |  | ||||||
|     var objmap versionInput |     var objmap versionInput | ||||||
|  |  | ||||||
|     yaml.Unmarshal(byteValue, &objmap) |     err = yaml.Unmarshal(byteValue, &objmap) | ||||||
|  |  | ||||||
|  |     if err != nil { | ||||||
|  |         return "", err | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return objmap.Version, nil |     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 @@ | |||||||
|  | --- | ||||||
		Reference in New Issue
	
	Block a user