Add controller API client interface (#1467)
This PR adds an interface for controller API client, it allows us to implement mock API client for unit testing with ease and we are able to generate spec file without accessing the real Fission server.
This commit is contained in:
@@ -25,28 +25,20 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ListSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
listOrphans bool
|
||||
status string
|
||||
pkgNamespace string
|
||||
}
|
||||
|
||||
func List(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ListSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&ListSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
@@ -66,7 +58,7 @@ func (opts *ListSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
pkgList, err := opts.client.PackageList(opts.pkgNamespace)
|
||||
pkgList, err := opts.Client().V1().Package().List(opts.pkgNamespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -83,7 +75,7 @@ func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
show := true
|
||||
// TODO improve list speed when --orphan
|
||||
if opts.listOrphans {
|
||||
fnList, err := GetFunctionsByPackage(opts.client, pkg.Metadata.Name, pkg.Metadata.Namespace)
|
||||
fnList, err := GetFunctionsByPackage(opts.Client(), pkg.Metadata.Name, pkg.Metadata.Namespace)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("get functions sharing package %s", pkg.Metadata.Name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user