check if source file or directory is ready or not (#447)
This commit is contained in:
2
fx.go
2
fx.go
@@ -17,7 +17,7 @@ import (
|
|||||||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "0.8.87"
|
const version = "0.8.88"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
go checkForUpdate()
|
go checkForUpdate()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/metrue/fx/context"
|
"github.com/metrue/fx/context"
|
||||||
|
"github.com/metrue/fx/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse parse input
|
// Parse parse input
|
||||||
@@ -15,7 +16,11 @@ func Parse(action string) func(ctx context.Contexter) (err error) {
|
|||||||
case "up":
|
case "up":
|
||||||
sources := []string{}
|
sources := []string{}
|
||||||
for _, s := range cli.Args() {
|
for _, s := range cli.Args() {
|
||||||
sources = append(sources, s)
|
if utils.IsDir(s) || utils.IsRegularFile(s) {
|
||||||
|
sources = append(sources, s)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("no such file or directory: %s", s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ctx.Set("sources", sources)
|
ctx.Set("sources", sources)
|
||||||
name := cli.String("name")
|
name := cli.String("name")
|
||||||
|
|||||||
49
middlewares/parse_test.go
Normal file
49
middlewares/parse_test.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"flag"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
|
mockCtx "github.com/metrue/fx/context/mocks"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParse(t *testing.T) {
|
||||||
|
t.Run("source code not existed", func(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
ctx := mockCtx.NewMockContexter(ctrl)
|
||||||
|
argset := flag.NewFlagSet("test", 0)
|
||||||
|
cli := cli.NewContext(nil, argset, nil)
|
||||||
|
argset.Parse([]string{"this_file_should_not_existed"})
|
||||||
|
ctx.EXPECT().GetCliContext().Return(cli)
|
||||||
|
if err := Parse("up")(ctx); err == nil {
|
||||||
|
t.Fatal("should got file or directory not existed error")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("source code ready", func(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
ctx := mockCtx.NewMockContexter(ctrl)
|
||||||
|
argset := flag.NewFlagSet("test", 0)
|
||||||
|
cli := cli.NewContext(nil, argset, nil)
|
||||||
|
pwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
argset.Parse([]string{pwd})
|
||||||
|
ctx.EXPECT().GetCliContext().Return(cli)
|
||||||
|
ctx.EXPECT().Set("sources", []string{pwd})
|
||||||
|
ctx.EXPECT().Set("name", "")
|
||||||
|
ctx.EXPECT().Set("port", 0)
|
||||||
|
ctx.EXPECT().Set("force", false)
|
||||||
|
if err := Parse("up")(ctx); err != nil {
|
||||||
|
t.Fatal("should got file or directory not existed error")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user