mirror of
https://github.com/iyear/tdl
synced 2025-01-09 04:17:35 +08:00
5451bcb1ad
* runs on latest ubuntu * runs on latest ubuntu * cancel inf retries * change to self-hosted account * fix missing args * fix opendb error * inf retries * inf retries
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
|
|
tcmd "github.com/iyear/tdl/cmd"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
func TestCommand(t *testing.T) {
|
|
RegisterFailHandler(Fail)
|
|
RunSpecs(t, "Test tdl")
|
|
}
|
|
|
|
var (
|
|
cmd *cobra.Command
|
|
args []string
|
|
output string
|
|
storage string
|
|
)
|
|
|
|
var _ = BeforeSuite(func() {
|
|
// used to avoid "open db: timeout" conflict
|
|
storage = fmt.Sprintf("type=file,path=%s",
|
|
filepath.Join(os.TempDir(), "tdl", strconv.FormatInt(time.Now().UnixNano(), 10)))
|
|
|
|
log.SetOutput(GinkgoWriter)
|
|
})
|
|
|
|
var _ = BeforeEach(func() {
|
|
cmd = tcmd.New()
|
|
|
|
// wait before each test to avoid rate limit
|
|
time.Sleep(10 * time.Second)
|
|
})
|
|
|
|
func exec(cmd *cobra.Command, args []string, success bool) {
|
|
r, w, err := os.Pipe()
|
|
Expect(err).To(Succeed())
|
|
os.Stdout = w
|
|
color.Output = w
|
|
|
|
log.Printf("args: %s\n", args)
|
|
cmd.SetArgs(append([]string{
|
|
"--storage", storage,
|
|
}, args...))
|
|
if err = cmd.Execute(); success {
|
|
Expect(err).To(Succeed())
|
|
} else {
|
|
Expect(err).ToNot(Succeed())
|
|
}
|
|
|
|
Expect(w.Close()).To(Succeed())
|
|
|
|
o, err := io.ReadAll(r)
|
|
Expect(err).To(Succeed())
|
|
output = string(o)
|
|
}
|