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:
@@ -18,6 +18,7 @@ package timetrigger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -35,19 +36,12 @@ import (
|
||||
)
|
||||
|
||||
type CreateSubCommand struct {
|
||||
client *client.Client
|
||||
cmd.CommandActioner
|
||||
trigger *fv1.TimeTrigger
|
||||
}
|
||||
|
||||
func Create(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := CreateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(input)
|
||||
return (&CreateSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
@@ -126,14 +120,14 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := opts.client.TimeTriggerCreate(opts.trigger)
|
||||
_, err := opts.Client().V1().TimeTrigger().Create(opts.trigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating Time trigger")
|
||||
}
|
||||
|
||||
fmt.Printf("trigger '%v' created\n", opts.trigger.Metadata.Name)
|
||||
|
||||
t, err := getAPITimeInfo(opts.client)
|
||||
t, err := getAPITimeInfo(opts.Client())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -146,8 +140,8 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getAPITimeInfo(client *client.Client) (time.Time, error) {
|
||||
serverInfo, err := client.ServerInfo()
|
||||
func getAPITimeInfo(client client.Interface) (time.Time, error) {
|
||||
serverInfo, err := client.V1().Misc().ServerInfo()
|
||||
if err != nil {
|
||||
return time.Time{}, errors.Errorf("Error syncing server time information: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user