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_*
.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

View File

@ -1,7 +1,6 @@
package utils
import (
// "fmt"
"os"
"io"
"path"

View File

@ -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)
}

View File

@ -1,5 +1,7 @@
package utils
// https://pkg.go.dev/github.com/stretchr/testify/assert
import (
"os"
"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.