mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 04:07:47 +08:00
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gcmd_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gcmd"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
type TestParamsCase struct {
|
|
g.Meta `name:"root" root:"root"`
|
|
}
|
|
|
|
type TestParamsCaseRootInput struct {
|
|
g.Meta `name:"root"`
|
|
Name string
|
|
}
|
|
|
|
type TestParamsCaseRootOutput struct {
|
|
Content string
|
|
}
|
|
|
|
func (c *TestParamsCase) Root(ctx context.Context, in TestParamsCaseRootInput) (out *TestParamsCaseRootOutput, err error) {
|
|
out = &TestParamsCaseRootOutput{
|
|
Content: in.Name,
|
|
}
|
|
return
|
|
}
|
|
|
|
func Test_Command_ParamsCase(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
var ctx = gctx.New()
|
|
cmd, err := gcmd.NewFromObject(TestParamsCase{})
|
|
t.AssertNil(err)
|
|
|
|
os.Args = []string{"root", "-name=john"}
|
|
value, err := cmd.RunWithValueError(ctx)
|
|
t.AssertNil(err)
|
|
t.Assert(value, `{"Content":"john"}`)
|
|
})
|
|
}
|