feat(goctl): Support gateway sample generation (#3049)
This commit is contained in:
78
tools/goctl/internal/flags/flags_test.go
Normal file
78
tools/goctl/internal/flags/flags_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/test"
|
||||
)
|
||||
|
||||
func TestFlags_Get(t *testing.T) {
|
||||
setTestData(t, []byte(`{"host":"0.0.0.0","port":8888,"service":{"host":"{{.host}}","port":"{{.port}}","invalid":"{{.service.invalid}}"}}`))
|
||||
f := MustLoad()
|
||||
executor := test.NewExecutor[string, string]()
|
||||
executor.Add([]test.Data[string, string]{
|
||||
{
|
||||
Name: "key_host",
|
||||
Input: "host",
|
||||
Want: "0.0.0.0",
|
||||
},
|
||||
{
|
||||
Name: "key_port",
|
||||
Input: "port",
|
||||
Want: "8888",
|
||||
},
|
||||
{
|
||||
Name: "key_service.host",
|
||||
Input: "service.host",
|
||||
Want: "0.0.0.0",
|
||||
},
|
||||
{
|
||||
Name: "key_service.port",
|
||||
Input: "service.port",
|
||||
Want: "8888",
|
||||
},
|
||||
{
|
||||
Name: "key_not_exists",
|
||||
Input: "service.port.invalid",
|
||||
},
|
||||
{
|
||||
Name: "key_service.invalid",
|
||||
Input: "service.invalid",
|
||||
E: fmt.Errorf("the variable can not be self: %q", "service.invalid"),
|
||||
},
|
||||
}...)
|
||||
executor.RunE(t, f.Get)
|
||||
}
|
||||
|
||||
func Test_Get(t *testing.T) {
|
||||
setTestData(t, []byte(`{"host":"0.0.0.0","port":8888,"service":{"host":"{{.host}}","port":"{{.port}}","invalid":"{{.service.invalid}}"}}`))
|
||||
executor := test.NewExecutor[string, string]()
|
||||
executor.Add([]test.Data[string, string]{
|
||||
{
|
||||
Name: "key_host",
|
||||
Input: "host",
|
||||
Want: "0.0.0.0",
|
||||
},
|
||||
{
|
||||
Name: "key_port",
|
||||
Input: "port",
|
||||
Want: "8888",
|
||||
},
|
||||
{
|
||||
Name: "key_service.host",
|
||||
Input: "service.host",
|
||||
Want: "0.0.0.0",
|
||||
},
|
||||
{
|
||||
Name: "key_service.port",
|
||||
Input: "service.port",
|
||||
Want: "8888",
|
||||
},
|
||||
{
|
||||
Name: "key_not_exists",
|
||||
Input: "service.port.invalid",
|
||||
},
|
||||
}...)
|
||||
executor.Run(t, Get)
|
||||
}
|
||||
Reference in New Issue
Block a user