This commit is contained in:
admju 2024-09-09 10:11:10 +00:00
parent 53a614bd7e
commit a1af83689d
6 changed files with 65 additions and 14 deletions

View File

@ -70,6 +70,11 @@ clean:
@rm -rf workspace_* @rm -rf workspace_*
.PHONY: test .PHONY: test
test_%:
go test oc-deploy/$(subst test_,,$@) -coverprofile=.coverage.out -v
@go tool cover -html=.coverage.out -o .coverage.html
test: test:
@go test ./... -coverprofile=.coverage.out -v @go test ./... -coverprofile=.coverage.out -v
go tool cover -html=.coverage.out -o .coverage.html go tool cover -html=.coverage.out -o .coverage.html

View File

@ -1,7 +1,6 @@
package utils package utils
import ( import (
// "fmt"
"os" "os"
"io" "io"
"path" "path"
@ -56,7 +55,7 @@ func ExtractTarGz(dest string, gzipStream io.Reader) error {
// return err // return err
// } // }
case tar.TypeReg: case tar.TypeReg:
outName := dest + "/" + path.Base( header.Name) outName := dest + "/" + path.Base(header.Name)
outFile, _ := os.Create(outName) outFile, _ := os.Create(outName)
if err != nil { if err != nil {
return err return err

View File

@ -1,8 +1,7 @@
package utils package utils
// https://pkg.go.dev/github.com/stretchr/testify/assert#Nilf
import ( import (
"os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -26,3 +25,27 @@ func TestDownload(t *testing.T) {
assert.Nilf(t, err, "error message %s", url) assert.Nilf(t, err, "error message %s", url)
assert.FileExists(t, dest, "DownloadFromUrl error") 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)
}

View File

@ -1,5 +1,7 @@
package utils package utils
// https://pkg.go.dev/github.com/stretchr/testify/assert
import ( import (
"os" "os"
"testing" "testing"

22
src/utils/slice_test.go Normal file
View 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

Binary file not shown.