test
This commit is contained in:
parent
53a614bd7e
commit
a1af83689d
@ -70,6 +70,11 @@ clean:
|
||||
@rm -rf workspace_*
|
||||
|
||||
.PHONY: test
|
||||
test_%:
|
||||
go test oc-deploy/$(subst test_,,$@) -coverprofile=.coverage.out -v
|
||||
@go tool cover -html=.coverage.out -o .coverage.html
|
||||
|
||||
test:
|
||||
@go test ./... -coverprofile=.coverage.out -v
|
||||
go tool cover -html=.coverage.out -o .coverage.html
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"os"
|
||||
"io"
|
||||
"path"
|
||||
@ -56,7 +55,7 @@ func ExtractTarGz(dest string, gzipStream io.Reader) error {
|
||||
// return err
|
||||
// }
|
||||
case tar.TypeReg:
|
||||
outName := dest + "/" + path.Base( header.Name)
|
||||
outName := dest + "/" + path.Base(header.Name)
|
||||
outFile, _ := os.Create(outName)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1,8 +1,7 @@
|
||||
package utils
|
||||
|
||||
// https://pkg.go.dev/github.com/stretchr/testify/assert#Nilf
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"testing"
|
||||
@ -26,3 +25,27 @@ func TestDownload(t *testing.T) {
|
||||
assert.Nilf(t, err, "error message %s", url)
|
||||
assert.FileExists(t, dest, "DownloadFromUrl error")
|
||||
}
|
||||
|
||||
func TestExtractTarGz(t *testing.T) {
|
||||
|
||||
dest := filepath.Join(TEST_DEST_DIR, "extract")
|
||||
os.MkdirAll(dest, os.ModePerm)
|
||||
|
||||
src := filepath.Join(TEST_SRC_DIR, "fichier1.tgz")
|
||||
file, _ := os.Open(src)
|
||||
|
||||
err := ExtractTarGz(dest, file)
|
||||
assert.Nilf(t, err, "error message %s", src)
|
||||
assert.FileExists(t, filepath.Join(dest, "fichier1"), "TestExtractTarGz error")
|
||||
}
|
||||
|
||||
func TestExtractTarGzErr(t *testing.T) {
|
||||
|
||||
dest := filepath.Join(TEST_DEST_DIR, "extract")
|
||||
|
||||
src := filepath.Join(TEST_SRC_DIR, "fichier1")
|
||||
file, _ := os.Open(src)
|
||||
|
||||
err := ExtractTarGz(dest, file)
|
||||
assert.NotNilf(t, err, "error message %s", src)
|
||||
}
|
@ -1,23 +1,25 @@
|
||||
package utils
|
||||
|
||||
// https://pkg.go.dev/github.com/stretchr/testify/assert
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"testing"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var TEST_DEST_DIR = "../wrk_utils"
|
||||
var TEST_SRC_DIR = filepath.Join("../../test", "utils")
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
folderPath := TEST_DEST_DIR
|
||||
folderPath := TEST_DEST_DIR
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
os.RemoveAll(folderPath)
|
||||
os.MkdirAll(folderPath, os.ModePerm)
|
||||
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
exitCode := m.Run()
|
||||
// call flag.Parse() here if TestMain uses flags
|
||||
exitCode := m.Run()
|
||||
|
||||
os.RemoveAll(folderPath)
|
||||
os.Exit(exitCode)
|
||||
os.RemoveAll(folderPath)
|
||||
os.Exit(exitCode)
|
||||
}
|
22
src/utils/slice_test.go
Normal file
22
src/utils/slice_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSliceInStringExist(t *testing.T) {
|
||||
liste := []string{"text1", "text2"}
|
||||
|
||||
res := StringInSlice("text1", liste)
|
||||
|
||||
assert.Truef(t, res, "error message %s", "text1")
|
||||
}
|
||||
|
||||
func TestSliceInStringNotExist(t *testing.T) {
|
||||
liste := []string{"text1", "text2"}
|
||||
|
||||
res := StringInSlice("text3", liste)
|
||||
|
||||
assert.Falsef(t, res, "error message %s", "text3")
|
||||
}
|
BIN
test/utils/fichier1.tgz
Normal file
BIN
test/utils/fichier1.tgz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user