mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. [1]: https://golang.org/doc/go1.16#ioutil Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
44 lines
1001 B
Go
44 lines
1001 B
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"time"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
|
|
prometheusutil "kubevirt.io/containerized-data-importer/pkg/util/prometheus"
|
|
)
|
|
|
|
var _ = Describe("Prometheus Endpoint", func() {
|
|
It("Should start prometheus endpoint", func() {
|
|
By("Creating cert directory, we can store self signed CAs")
|
|
certsDirectory, err := os.MkdirTemp("", "certsdir")
|
|
Expect(err).NotTo(HaveOccurred())
|
|
empty, err := isDirEmpty(certsDirectory)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(empty).To(BeTrue())
|
|
prometheusutil.StartPrometheusEndpoint(certsDirectory)
|
|
time.Sleep(time.Second)
|
|
empty, err = isDirEmpty(certsDirectory)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(empty).To(BeFalse())
|
|
defer os.RemoveAll(certsDirectory)
|
|
})
|
|
})
|
|
|
|
func isDirEmpty(dirName string) (bool, error) {
|
|
f, err := os.Open(dirName)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
defer f.Close()
|
|
|
|
_, err = f.Readdirnames(1)
|
|
if err == io.EOF {
|
|
return true, nil
|
|
}
|
|
return false, err
|
|
}
|