feat: remove temp files in tests

Signed-off-by: kerthcet <kerthcet@gmail.com>
This commit is contained in:
kerthcet 2022-02-20 13:56:30 +08:00
parent 1860fb2af9
commit defd566097
2 changed files with 15 additions and 2 deletions

View File

@ -12,7 +12,13 @@ import (
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/utils"
)
const (
TestCertsTmp = "./test-certs-tmp"
)
func TestGenCerts(t *testing.T) {
defer os.RemoveAll(TestCertsTmp)
notAfter := time.Now().Add(Duration365d * 10).UTC()
namespace := "kube-karmada"
flagsExternalIP := ""
@ -78,7 +84,7 @@ func TestGenCerts(t *testing.T) {
karmadaCertCfg := NewCertConfig("system:admin", []string{"system:masters"}, karmadaAltNames, &notAfter)
frontProxyClientCertCfg := NewCertConfig("front-proxy-client", []string{"karmada"}, certutil.AltNames{}, &notAfter)
if err := GenCerts("./test-Certs-tmp", etcdServerCertConfig, etcdClientCertCfg, karmadaCertCfg, frontProxyClientCertCfg); err != nil {
if err := GenCerts(TestCertsTmp, etcdServerCertConfig, etcdClientCertCfg, karmadaCertCfg, frontProxyClientCertCfg); err != nil {
fmt.Println(err)
}
}

View File

@ -1,13 +1,20 @@
package utils
import (
"os"
"testing"
)
const filePath = "./crds.tar.gz"
const (
filePath = "./crds.tar.gz"
folder = "./crds"
)
// TestDownloadFile test DownloadFile
func TestDownloadFile(t *testing.T) {
defer os.Remove(filePath)
defer os.RemoveAll(folder)
url := "https://github.com/karmada-io/karmada/releases/download/v0.9.0/crds.tar.gz"
if err := DownloadFile(url, filePath); err != nil {
panic(err)