-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use method name as its command name if no name defined in Meta of inp…
…ut struct for package gcmd (#2019)
- Loading branch information
Showing
3 changed files
with
104 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 TestNoNameTagCase struct { | ||
g.Meta `name:"root"` | ||
} | ||
|
||
type TestNoNameTagCaseRootInput struct { | ||
Name string | ||
} | ||
type TestNoNameTagCaseRootOutput struct { | ||
Content string | ||
} | ||
|
||
func (c *TestNoNameTagCase) TEST(ctx context.Context, in TestNoNameTagCaseRootInput) (out *TestNoNameTagCaseRootOutput, err error) { | ||
out = &TestNoNameTagCaseRootOutput{ | ||
Content: in.Name, | ||
} | ||
return | ||
} | ||
|
||
func Test_Command_NoNameTagCase(t *testing.T) { | ||
gtest.C(t, func(t *gtest.T) { | ||
var ctx = gctx.New() | ||
cmd, err := gcmd.NewFromObject(TestNoNameTagCase{}) | ||
t.AssertNil(err) | ||
|
||
os.Args = []string{"root", "TEST", "-name=john"} | ||
value, err := cmd.RunWithValueError(ctx) | ||
t.AssertNil(err) | ||
t.Assert(value, `{"Content":"john"}`) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters