mirror of
https://github.com/iyear/tdl
synced 2025-01-09 04:17:35 +08:00
0a084ef513
* fix part size * remove useless --size flag in e2e test
71 lines
1.2 KiB
Go
71 lines
1.2 KiB
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
_ "embed"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"math/rand"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
|
|
tcmd "github.com/iyear/tdl/cmd"
|
|
"github.com/iyear/tdl/test/testserver"
|
|
|
|
. "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
|
|
testAccount string
|
|
sessionFile string
|
|
)
|
|
|
|
var _ = BeforeSuite(func(ctx context.Context) {
|
|
var err error
|
|
testAccount, sessionFile, err = testserver.Setup(ctx, rand.NewSource(GinkgoRandomSeed()))
|
|
Expect(err).To(Succeed())
|
|
|
|
log.SetOutput(GinkgoWriter)
|
|
})
|
|
|
|
var _ = BeforeEach(func() {
|
|
cmd = tcmd.New()
|
|
})
|
|
|
|
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{
|
|
"-n", testAccount,
|
|
"--storage", fmt.Sprintf("type=file,path=%s", sessionFile),
|
|
}, 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)
|
|
}
|