diff --git a/.envrc b/.envrc index c2fd4d0af..c8c4a987a 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,4 @@ +export TINKERBELL_GRPC_AUTHORITY=127.0.0.1:42113 +export TINKERBELL_CERT_URL=http://127.0.0.1:42114/cert + which nix &>/dev/null && use nix && unset GOPATH diff --git a/Makefile b/Makefile index 45897f4cc..347b05ecc 100644 --- a/Makefile +++ b/Makefile @@ -54,3 +54,7 @@ test: verify: goimports -d . golint ./... + +protos/gen_mock: + go generate ./protos/**/* + goimports -w ./protos/**/mock.go diff --git a/client/main.go b/client/main.go index 807058a12..efe09518e 100644 --- a/client/main.go +++ b/client/main.go @@ -8,6 +8,7 @@ import ( "os" "github.com/pkg/errors" + "github.com/spf13/pflag" "github.com/tinkerbell/tink/protos/events" "github.com/tinkerbell/tink/protos/hardware" "github.com/tinkerbell/tink/protos/template" @@ -24,6 +25,83 @@ var ( EventsClient events.EventsServiceClient ) +// FullClient aggregates all the grpc clients available from Tinkerbell Server +type FullClient struct { + TemplateClient template.TemplateServiceClient + WorkflowClient workflow.WorkflowServiceClient + HardwareClient hardware.HardwareServiceClient + EventsClient events.EventsServiceClient +} + +// NewFullClientFromGlobal is a dirty hack that returns a FullClient using the +// global variables exposed by the client package. Globals should be avoided +// and we will deprecated them at some point replacing this function with +// NewFullClient. If you are strating a new project please use the last one +func NewFullClientFromGlobal() (*FullClient, error) { + // This is required because we use init() too often, even more in the + // CLI and based on where you are sometime the clients are not initialised + if TemplateClient == nil { + err := Setup() + if err != nil { + panic(err) + } + } + return &FullClient{ + TemplateClient: TemplateClient, + WorkflowClient: WorkflowClient, + HardwareClient: HardwareClient, + EventsClient: EventsClient, + }, nil +} + +// NewFullClient returns a FullClient. A structure that contains all the +// clients made available from tink-server. This is the function you should use +// instead of NewFullClientFromGlobal that will be deprecated soon +func NewFullClient(conn grpc.ClientConnInterface) *FullClient { + return &FullClient{ + TemplateClient: template.NewTemplateServiceClient(conn), + WorkflowClient: workflow.NewWorkflowServiceClient(conn), + HardwareClient: hardware.NewHardwareServiceClient(conn), + EventsClient: events.NewEventsServiceClient(conn), + } +} + +type ConnOptions struct { + CertURL string + GRPCAuthority string +} + +func (o *ConnOptions) SetFlags(flagSet *pflag.FlagSet) { + flagSet.StringVar(&o.CertURL, "tinkerbell-cert-url", "http://127.0.0.1:42114/cert", "The URL where the certificate is located") + flagSet.StringVar(&o.GRPCAuthority, "tinkerbell-grpc-authority", "127.0.0.1:42113", "Link to tink-server grcp api") +} + +func NewClientConn(opt *ConnOptions) (*grpc.ClientConn, error) { + resp, err := http.Get(opt.CertURL) + if err != nil { + return nil, errors.Wrap(err, "fetch cert") + } + defer resp.Body.Close() + + certs, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "read cert") + } + + cp := x509.NewCertPool() + ok := cp.AppendCertsFromPEM(certs) + if !ok { + return nil, errors.Wrap(err, "parse cert") + } + + creds := credentials.NewClientTLSFromCert(cp, "") + conn, err := grpc.Dial(opt.GRPCAuthority, grpc.WithTransportCredentials(creds)) + if err != nil { + return nil, errors.Wrap(err, "connect to tinkerbell server") + } + return conn, nil +} + // GetConnection returns a gRPC client connection func GetConnection() (*grpc.ClientConn, error) { certURL := os.Getenv("TINKERBELL_CERT_URL") diff --git a/cmd/tink-cli/cmd/get/doc.go b/cmd/tink-cli/cmd/get/doc.go new file mode 100644 index 000000000..452d92b1f --- /dev/null +++ b/cmd/tink-cli/cmd/get/doc.go @@ -0,0 +1,5 @@ +// Get is a reusable implementation of the Get command for the tink cli. The +// Get command lists and filters resources. It supports different kind of +// visualisation and it is designed to be extendible and usable across +// resources. +package get diff --git a/cmd/tink-cli/cmd/get/get.go b/cmd/tink-cli/cmd/get/get.go new file mode 100644 index 000000000..afaf19265 --- /dev/null +++ b/cmd/tink-cli/cmd/get/get.go @@ -0,0 +1,157 @@ +package get + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/pkg/errors" + + "github.com/jedib0t/go-pretty/table" + "github.com/spf13/cobra" + "github.com/tinkerbell/tink/client" + "google.golang.org/grpc" +) + +type Options struct { + // Headers is the list of headers you want to print as part of the list + Headers []string + // RetrieveData reaches out to Tinkerbell and it gets the required data + RetrieveData func(context.Context, *client.FullClient) ([]interface{}, error) + // RetrieveByID is used when a get command has a list of arguments + RetrieveByID func(context.Context, *client.FullClient, string) (interface{}, error) + // PopulateTable populates a table with the data retrieved with the RetrieveData function. + PopulateTable func([]interface{}, table.Writer) error + + clientConnOpt *client.ConnOptions + fullClient *client.FullClient + + // Format specifies the format you want the list of resources printed + // out. By default it is table but it can be JSON ar CSV. + Format string + // NoHeaders does not print the header line + NoHeaders bool +} + +func (o *Options) SetClientConnOpt(co *client.ConnOptions) { + o.clientConnOpt = co +} + +func (o *Options) SetFullClient(cl *client.FullClient) { + o.fullClient = cl +} + +const shortDescr = `display one or many resources` + +const longDescr = `Prints a table containing the most important information about a specific +resource. You can specify the kind of output you want to receive. It can be +table, csv or json. +` + +const exampleDescr = `# List all hardware in table output format. +tink hardware get + +# List all workflow in csv output format. +tink template get --format csv + +# List a single template in json output format. +tink workflow get --format json [id] +` + +func NewGetCommand(opt Options) *cobra.Command { + cmd := &cobra.Command{ + Use: "get", + Short: shortDescr, + Long: longDescr, + Example: exampleDescr, + DisableFlagsInUseLine: true, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + if opt.fullClient != nil { + return nil + } + if opt.clientConnOpt == nil { + opt.SetClientConnOpt(&client.ConnOptions{}) + } + opt.clientConnOpt.SetFlags(cmd.PersistentFlags()) + return nil + }, + PreRunE: func(cmd *cobra.Command, args []string) error { + if opt.fullClient == nil { + var err error + var conn *grpc.ClientConn + conn, err = client.NewClientConn(opt.clientConnOpt) + if err != nil { + println("Flag based client configuration failed with err: %s. Trying with env var legacy method...", err) + // Fallback to legacy Setup via env var + conn, err = client.GetConnection() + if err != nil { + return errors.Wrap(err, "failed to setup connection to tink-server") + } + } + opt.SetFullClient(client.NewFullClient(conn)) + } + return nil + }, + RunE: func(cmd *cobra.Command, args []string) error { + var err error + var data []interface{} + + t := table.NewWriter() + t.SetOutputMirror(cmd.OutOrStdout()) + + if len(args) != 0 { + if opt.RetrieveByID == nil { + return errors.New("Get by ID is not implemented for this resource yet. Please have a look at the issue in GitHub or open a new one.") + } + for _, requestedID := range args { + s, err := opt.RetrieveByID(cmd.Context(), opt.fullClient, requestedID) + if err != nil { + continue + } + data = append(data, s) + } + } else { + data, err = opt.RetrieveData(cmd.Context(), opt.fullClient) + } + if err != nil { + return err + } + + if !opt.NoHeaders { + header := table.Row{} + for _, h := range opt.Headers { + header = append(header, h) + } + t.AppendHeader(header) + } + + // TODO(gianarb): Technically this is not needed for + // all the output formats but for now that's fine + if err := opt.PopulateTable(data, t); err != nil { + return err + } + + switch opt.Format { + case "json": + // TODO(gianarb): the table library we use do + // not support JSON right now. I am not even + // sure I like tables! So complicated... + b, err := json.Marshal(struct { + Data interface{} `json:"data"` + }{Data: data}) + if err != nil { + return err + } + fmt.Fprint(cmd.OutOrStdout(), string(b)) + case "csv": + t.RenderCSV() + default: + t.Render() + } + return nil + }, + } + cmd.PersistentFlags().StringVarP(&opt.Format, "format", "", "table", "The format you expect the list to be printed out. Currently supported format are table, JSON and CSV") + cmd.PersistentFlags().BoolVar(&opt.NoHeaders, "no-headers", false, "Table contains an header with the columns' name. You can disable it from being printed out") + return cmd +} diff --git a/cmd/tink-cli/cmd/get/get_test.go b/cmd/tink-cli/cmd/get/get_test.go new file mode 100644 index 000000000..fe248db3d --- /dev/null +++ b/cmd/tink-cli/cmd/get/get_test.go @@ -0,0 +1,202 @@ +package get + +import ( + "bytes" + "context" + "io" + "io/ioutil" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/jedib0t/go-pretty/table" + "github.com/spf13/cobra" + "github.com/tinkerbell/tink/client" +) + +func TestNewGetCommand(t *testing.T) { + table := []struct { + Name string + ExpectStdout string + Args []string + Opt Options + Skip string + Run func(t *testing.T, cmd *cobra.Command, stdout, stderr io.Reader) + }{ + { + Name: "happy-path", + ExpectStdout: `+------+-------+ +| NAME | ID | ++------+-------+ +| 10 | hello | ++------+-------+ +`, + Opt: Options{ + Headers: []string{"name", "id"}, + RetrieveData: func(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + data := []interface{}{ + []string{"10", "hello"}, + } + return data, nil + }, + PopulateTable: func(data []interface{}, w table.Writer) error { + for _, v := range data { + if vv, ok := v.([]string); ok { + w.AppendRow(table.Row{vv[0], vv[1]}) + } + } + return nil + }, + }, + }, + { + Name: "get-by-id", + Args: []string{"30"}, + ExpectStdout: `+------+-------+ +| NAME | ID | ++------+-------+ +| 30 | hello | ++------+-------+ +`, + Opt: Options{ + Headers: []string{"name", "id"}, + RetrieveByID: func(ctx context.Context, cl *client.FullClient, arg string) (interface{}, error) { + if arg != "30" { + t.Errorf("expected 30 as arg got %s", arg) + } + return []string{"30", "hello"}, nil + }, + PopulateTable: func(data []interface{}, w table.Writer) error { + for _, v := range data { + if vv, ok := v.([]string); ok { + w.AppendRow(table.Row{vv[0], vv[1]}) + } + } + return nil + }, + }, + }, + { + Name: "happy-path-no-headers", + ExpectStdout: `+----+-------+ +| 10 | hello | ++----+-------+ +`, + Args: []string{"--no-headers"}, + Opt: Options{ + Headers: []string{"name", "id"}, + RetrieveData: func(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + data := []interface{}{ + []string{"10", "hello"}, + } + return data, nil + }, + PopulateTable: func(data []interface{}, w table.Writer) error { + for _, v := range data { + if vv, ok := v.([]string); ok { + w.AppendRow(table.Row{vv[0], vv[1]}) + } + } + return nil + }, + }, + }, + { + Name: "happy-path-json", + ExpectStdout: `{"data":[["10","hello"]]}`, + Args: []string{"--format", "json"}, + Opt: Options{ + Headers: []string{"name", "id"}, + RetrieveData: func(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + data := []interface{}{ + []string{"10", "hello"}, + } + return data, nil + }, + PopulateTable: func(data []interface{}, w table.Writer) error { + for _, v := range data { + if vv, ok := v.([]string); ok { + w.AppendRow(table.Row{vv[0], vv[1]}) + } + } + return nil + }, + }, + }, + { + Name: "happy-path-json-no-headers", + Skip: "The JSON format is rusty and custom because we table library we use do not support JSON right now. This feature is not implemented", + }, + { + Name: "happy-path-csv-no-headers", + ExpectStdout: `10,hello +`, + Args: []string{"--format", "csv", "--no-headers"}, + Opt: Options{ + Headers: []string{"name", "id"}, + RetrieveData: func(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + data := []interface{}{ + []string{"10", "hello"}, + } + return data, nil + }, + PopulateTable: func(data []interface{}, w table.Writer) error { + for _, v := range data { + if vv, ok := v.([]string); ok { + w.AppendRow(table.Row{vv[0], vv[1]}) + } + } + return nil + }, + }, + }, + { + Name: "happy-path-csv", + ExpectStdout: `name,id +10,hello +`, + Args: []string{"--format", "csv"}, + Opt: Options{ + Headers: []string{"name", "id"}, + RetrieveData: func(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + data := []interface{}{ + []string{"10", "hello"}, + } + return data, nil + }, + PopulateTable: func(data []interface{}, w table.Writer) error { + for _, v := range data { + if vv, ok := v.([]string); ok { + w.AppendRow(table.Row{vv[0], vv[1]}) + } + } + return nil + }, + }, + }, + } + + for _, s := range table { + t.Run(s.Name, func(t *testing.T) { + if s.Skip != "" { + t.Skip(s.Skip) + } + stdout := bytes.NewBufferString("") + s.Opt.SetFullClient(&client.FullClient{}) + cmd := NewGetCommand(s.Opt) + cmd.SetOut(stdout) + cmd.SetArgs(s.Args) + err := cmd.Execute() + if err != nil { + t.Error(err) + } + out, err := ioutil.ReadAll(stdout) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(string(out), s.ExpectStdout); diff != "" { + t.Fatal(diff) + } + }) + } + +} diff --git a/cmd/tink-cli/cmd/hardware.go b/cmd/tink-cli/cmd/hardware.go index 2d8a7b327..ac6403806 100644 --- a/cmd/tink-cli/cmd/hardware.go +++ b/cmd/tink-cli/cmd/hardware.go @@ -4,22 +4,31 @@ import ( "fmt" "github.com/spf13/cobra" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" "github.com/tinkerbell/tink/cmd/tink-cli/cmd/hardware" ) -var hardwareCmd = &cobra.Command{ - Use: "hardware", - Short: "tink hardware client", - Example: "tink hardware [command]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires arguments", c.UseLine()) - } - return nil - }, -} +func NewHardwareCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "hardware", + Short: "tink hardware client", + Example: "tink hardware [command]", + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires arguments", c.UseLine()) + } + return nil + }, + } + + cmd.AddCommand(get.NewGetCommand(hardware.NewGetOptions())) + cmd.AddCommand(hardware.NewDeleteCmd()) + cmd.AddCommand(hardware.NewGetByIDCmd()) + cmd.AddCommand(hardware.NewGetByIPCmd()) + cmd.AddCommand(hardware.NewListCmd()) + cmd.AddCommand(hardware.NewGetByMACCmd()) + cmd.AddCommand(hardware.NewPushCmd()) + cmd.AddCommand(hardware.NewWatchCmd()) -func init() { - hardwareCmd.AddCommand(hardware.SubCommands...) - rootCmd.AddCommand(hardwareCmd) + return cmd } diff --git a/cmd/tink-cli/cmd/hardware/delete.go b/cmd/tink-cli/cmd/hardware/delete.go index 4850b8b06..97709d70d 100644 --- a/cmd/tink-cli/cmd/hardware/delete.go +++ b/cmd/tink-cli/cmd/hardware/delete.go @@ -11,25 +11,23 @@ import ( "github.com/tinkerbell/tink/protos/hardware" ) -// deleteCmd represents the id command -var deleteCmd = &cobra.Command{ - Use: "delete", - Short: "delete hardware by id", - Example: "tink hardware delete 224ee6ab-ad62-4070-a900-ed816444cec0 cb76ae54-93e9-401c-a5b2-d455bb3800b1", - Args: func(_ *cobra.Command, args []string) error { - return verifyUUIDs(args) - }, - Run: func(cmd *cobra.Command, args []string) { - for _, id := range args { - _, err := client.HardwareClient.Delete(context.Background(), &hardware.DeleteRequest{Id: id}) - if err != nil { - log.Fatal(err) +func NewDeleteCmd() *cobra.Command { + return &cobra.Command{ + Use: "delete", + Short: "delete hardware by id", + Example: "tink hardware delete 224ee6ab-ad62-4070-a900-ed816444cec0 cb76ae54-93e9-401c-a5b2-d455bb3800b1", + Args: func(_ *cobra.Command, args []string) error { + return verifyUUIDs(args) + }, + Run: func(cmd *cobra.Command, args []string) { + for _, id := range args { + _, err := client.HardwareClient.Delete(context.Background(), &hardware.DeleteRequest{Id: id}) + if err != nil { + log.Fatal(err) + } + log.Println("Hardware data with id", id, "deleted successfully") } - log.Println("Hardware data with id", id, "deleted successfully") - } - }, -} + }, + } -func init() { - SubCommands = append(SubCommands, deleteCmd) } diff --git a/cmd/tink-cli/cmd/hardware/get.go b/cmd/tink-cli/cmd/hardware/get.go new file mode 100644 index 000000000..70b5b26db --- /dev/null +++ b/cmd/tink-cli/cmd/hardware/get.go @@ -0,0 +1,64 @@ +package hardware + +import ( + "context" + "io" + + "github.com/jedib0t/go-pretty/table" + "github.com/tinkerbell/tink/client" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" + "github.com/tinkerbell/tink/protos/hardware" +) + +type getHardware struct { + get.Options +} + +func NewGetOptions() get.Options { + gh := getHardware{} + opt := get.Options{ + Headers: []string{"ID", "MAC Address", "IP address", "Hostname"}, + PopulateTable: gh.PopulateTable, + RetrieveData: gh.RetrieveData, + RetrieveByID: gh.RetrieveByID, + } + return opt +} + +func (h *getHardware) RetrieveByID(ctx context.Context, cl *client.FullClient, requiredID string) (interface{}, error) { + return cl.HardwareClient.ByID(ctx, &hardware.GetRequest{Id: requiredID}) +} + +func (h *getHardware) RetrieveData(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + list, err := cl.HardwareClient.All(ctx, &hardware.Empty{}) + if err != nil { + return nil, err + } + data := []interface{}{} + var hw *hardware.Hardware + for hw, err = list.Recv(); err == nil && hw != nil; hw, err = list.Recv() { + data = append(data, hw) + } + if err != nil && err != io.EOF { + return nil, err + } + return data, nil +} + +func (h *getHardware) PopulateTable(data []interface{}, t table.Writer) error { + for _, v := range data { + if hw, ok := v.(*hardware.Hardware); ok { + // TODO(gianarb): I think we should + // print it better. The hardware is one + // even if if has more than one + // interface. + for _, iface := range hw.GetNetwork().GetInterfaces() { + t.AppendRow(table.Row{hw.Id, + iface.Dhcp.Mac, + iface.Dhcp.Ip.Address, + iface.Dhcp.Hostname}) + } + } + } + return nil +} diff --git a/cmd/tink-cli/cmd/hardware/get_test.go b/cmd/tink-cli/cmd/hardware/get_test.go new file mode 100644 index 000000000..527019aff --- /dev/null +++ b/cmd/tink-cli/cmd/hardware/get_test.go @@ -0,0 +1,113 @@ +package hardware + +import ( + "bytes" + "context" + "io" + "io/ioutil" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/tinkerbell/tink/client" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" + hardware_proto "github.com/tinkerbell/tink/protos/hardware" + "google.golang.org/grpc" +) + +func TestGetHardware(t *testing.T) { + table := []struct { + counter int + Name string + ReturnedHardwares []*hardware_proto.Hardware + Args []string + ExpectedStdout string + }{ + { + Name: "happy-path", + ReturnedHardwares: []*hardware_proto.Hardware{ + { + Network: &hardware_proto.Hardware_Network{ + Interfaces: []*hardware_proto.Hardware_Network_Interface{ + { + Dhcp: &hardware_proto.Hardware_DHCP{ + Mac: "cb:26:ad:28:5a:72", + Ip: &hardware_proto.Hardware_DHCP_IP{ + Address: "192.168.12.12", + }, + Hostname: "unittest-golang", + }, + }, + }, + }, + Id: "1234-test", + }, + }, + ExpectedStdout: `+-----------+-------------------+---------------+-----------------+ +| ID | MAC ADDRESS | IP ADDRESS | HOSTNAME | ++-----------+-------------------+---------------+-----------------+ +| 1234-test | cb:26:ad:28:5a:72 | 192.168.12.12 | unittest-golang | ++-----------+-------------------+---------------+-----------------+ +`, + }, + { + Name: "get-json", + Args: []string{"--format", "json"}, + ReturnedHardwares: []*hardware_proto.Hardware{ + { + Network: &hardware_proto.Hardware_Network{ + Interfaces: []*hardware_proto.Hardware_Network_Interface{ + { + Dhcp: &hardware_proto.Hardware_DHCP{ + Mac: "cb:26:ad:28:5a:72", + Ip: &hardware_proto.Hardware_DHCP_IP{ + Address: "192.168.12.12", + }, + Hostname: "unittest-golang", + }, + }, + }, + }, + Id: "1234-test", + }, + }, + ExpectedStdout: `{"data":[{"network":{"interfaces":[{"dhcp":{"mac":"cb:26:ad:28:5a:72","hostname":"unittest-golang","ip":{"address":"192.168.12.12"}}}]},"id":"1234-test"}]}`, + }, + } + + for _, s := range table { + t.Run(s.Name, func(t *testing.T) { + cl := &client.FullClient{ + HardwareClient: &hardware_proto.HardwareServiceClientMock{ + AllFunc: func(ctx context.Context, in *hardware_proto.Empty, opts ...grpc.CallOption) (hardware_proto.HardwareService_AllClient, error) { + return &hardware_proto.HardwareService_AllClientMock{ + RecvFunc: func() (*hardware_proto.Hardware, error) { + s.counter = s.counter + 1 + if s.counter > len(s.ReturnedHardwares) { + return nil, io.EOF + } + return s.ReturnedHardwares[s.counter-1], nil + }, + }, nil + }, + }, + } + stdout := bytes.NewBufferString("") + g := NewGetOptions() + g.SetFullClient(cl) + cmd := get.NewGetCommand(g) + cmd.SetOut(stdout) + cmd.SetArgs(s.Args) + err := cmd.Execute() + if err != nil { + t.Error(err) + } + out, err := ioutil.ReadAll(stdout) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(string(out), s.ExpectedStdout); diff != "" { + t.Error(diff) + } + }) + } +} diff --git a/cmd/tink-cli/cmd/hardware/id.go b/cmd/tink-cli/cmd/hardware/id.go index f9b26fcc4..728be5243 100644 --- a/cmd/tink-cli/cmd/hardware/id.go +++ b/cmd/tink-cli/cmd/hardware/id.go @@ -15,28 +15,26 @@ import ( ) // idCmd represents the id command -var idCmd = &cobra.Command{ - Use: "id", - Short: "get hardware by id", - Example: "tink hardware id 224ee6ab-ad62-4070-a900-ed816444cec0 cb76ae54-93e9-401c-a5b2-d455bb3800b1", - Args: func(_ *cobra.Command, args []string) error { - return verifyUUIDs(args) - }, - Run: func(cmd *cobra.Command, args []string) { - for _, id := range args { - hw, err := client.HardwareClient.ByID(context.Background(), &hardware.GetRequest{Id: id}) - if err != nil { - log.Fatal(err) +func NewGetByIDCmd() *cobra.Command { + return &cobra.Command{ + Use: "id", + Short: "get hardware by id", + Example: "tink hardware id 224ee6ab-ad62-4070-a900-ed816444cec0 cb76ae54-93e9-401c-a5b2-d455bb3800b1", + Args: func(_ *cobra.Command, args []string) error { + return verifyUUIDs(args) + }, + Run: func(cmd *cobra.Command, args []string) { + for _, id := range args { + hw, err := client.HardwareClient.ByID(context.Background(), &hardware.GetRequest{Id: id}) + if err != nil { + log.Fatal(err) + } + b, err := json.Marshal(pkg.HardwareWrapper{Hardware: hw}) + if err != nil { + log.Fatal(err) + } + fmt.Println(string(b)) } - b, err := json.Marshal(pkg.HardwareWrapper{Hardware: hw}) - if err != nil { - log.Fatal(err) - } - fmt.Println(string(b)) - } - }, -} - -func init() { - SubCommands = append(SubCommands, idCmd) + }, + } } diff --git a/cmd/tink-cli/cmd/hardware/ip.go b/cmd/tink-cli/cmd/hardware/ip.go index 527b02048..36cf05698 100644 --- a/cmd/tink-cli/cmd/hardware/ip.go +++ b/cmd/tink-cli/cmd/hardware/ip.go @@ -16,38 +16,33 @@ import ( var data bool // ipCmd represents the ip command -var ipCmd = &cobra.Command{ - Use: "ip", - Short: "get hardware by any associated ip", - Example: "tink hardware ip 10.0.0.2 10.0.0.3", - Args: func(_ *cobra.Command, args []string) error { - for _, arg := range args { - if net.ParseIP(arg) == nil { - return fmt.Errorf("invalid ip: %s", arg) +func NewGetByIPCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "ip", + Short: "get hardware by any associated ip", + Example: "tink hardware ip 10.0.0.2 10.0.0.3", + Args: func(_ *cobra.Command, args []string) error { + for _, arg := range args { + if net.ParseIP(arg) == nil { + return fmt.Errorf("invalid ip: %s", arg) + } } - } - return nil - }, - Run: func(cmd *cobra.Command, args []string) { - for _, ip := range args { - hw, err := client.HardwareClient.ByIP(context.Background(), &hardware.GetRequest{Ip: ip}) - if err != nil { - log.Fatal(err) + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + for _, ip := range args { + hw, err := client.HardwareClient.ByIP(context.Background(), &hardware.GetRequest{Ip: ip}) + if err != nil { + log.Fatal(err) + } + if hw.GetId() == "" { + log.Fatal("IP address not found in the database ", ip) + } + printOutput(data, hw, ip) } - if hw.GetId() == "" { - log.Fatal("IP address not found in the database ", ip) - } - printOutput(data, hw, ip) - } - }, -} - -func addIPFlags() { - flags := ipCmd.Flags() + }, + } + flags := cmd.Flags() flags.BoolVarP(&data, "details", "d", false, "provide the complete hardware details in json format") -} - -func init() { - addIPFlags() - SubCommands = append(SubCommands, ipCmd) + return cmd } diff --git a/cmd/tink-cli/cmd/hardware/list.go b/cmd/tink-cli/cmd/hardware/list.go index 487c69a13..418f84327 100644 --- a/cmd/tink-cli/cmd/hardware/list.go +++ b/cmd/tink-cli/cmd/hardware/list.go @@ -18,21 +18,25 @@ var ( t table.Writer ) -// listCmd represents the list command -var listCmd = &cobra.Command{ - Use: "list", - Short: "list all known hardware", - Run: func(cmd *cobra.Command, args []string) { - if quiet { +func NewListCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "list all known hardware", + Run: func(cmd *cobra.Command, args []string) { + if quiet { + listHardware() + return + } + t = table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.AppendHeader(table.Row{"ID", "MAC Address", "IP address", "Hostname"}) listHardware() - return - } - t = table.NewWriter() - t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"ID", "MAC Address", "IP address", "Hostname"}) - listHardware() - t.Render() - }, + t.Render() + }, + } + flags := cmd.Flags() + flags.BoolVarP(&quiet, "quiet", "q", false, "only display hardware IDs") + return cmd } func listHardware() { @@ -55,13 +59,3 @@ func listHardware() { log.Fatal(err) } } - -func addListFlags() { - flags := listCmd.Flags() - flags.BoolVarP(&quiet, "quiet", "q", false, "only display hardware IDs") -} - -func init() { - addListFlags() - SubCommands = append(SubCommands, listCmd) -} diff --git a/cmd/tink-cli/cmd/hardware/mac.go b/cmd/tink-cli/cmd/hardware/mac.go index 73ba69587..7adfa34a9 100644 --- a/cmd/tink-cli/cmd/hardware/mac.go +++ b/cmd/tink-cli/cmd/hardware/mac.go @@ -13,39 +13,33 @@ import ( "github.com/tinkerbell/tink/protos/hardware" ) -// macCmd represents the mac command -var macCmd = &cobra.Command{ - Use: "mac", - Short: "get hardware by any associated mac", - Example: "tink hardware mac 00:00:00:00:00:01 00:00:00:00:00:02", - Args: func(_ *cobra.Command, args []string) error { - for _, arg := range args { - if _, err := net.ParseMAC(arg); err != nil { - return fmt.Errorf("invalid mac: %s", arg) +func NewGetByMACCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "mac", + Short: "get hardware by any associated mac", + Example: "tink hardware mac 00:00:00:00:00:01 00:00:00:00:00:02", + Args: func(_ *cobra.Command, args []string) error { + for _, arg := range args { + if _, err := net.ParseMAC(arg); err != nil { + return fmt.Errorf("invalid mac: %s", arg) + } } - } - return nil - }, - Run: func(cmd *cobra.Command, args []string) { - for _, mac := range args { - hw, err := client.HardwareClient.ByMAC(context.Background(), &hardware.GetRequest{Mac: mac}) - if err != nil { - log.Fatal(err) + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + for _, mac := range args { + hw, err := client.HardwareClient.ByMAC(context.Background(), &hardware.GetRequest{Mac: mac}) + if err != nil { + log.Fatal(err) + } + if hw.GetId() == "" { + log.Fatal("MAC address not found in the database ", mac) + } + printOutput(data, hw, mac) } - if hw.GetId() == "" { - log.Fatal("MAC address not found in the database ", mac) - } - printOutput(data, hw, mac) - } - }, -} - -func addMacFlags() { - flags := macCmd.Flags() + }, + } + flags := cmd.Flags() flags.BoolVarP(&data, "details", "d", false, "provide the complete hardware details in json format") -} - -func init() { - addMacFlags() - SubCommands = append(SubCommands, macCmd) + return cmd } diff --git a/cmd/tink-cli/cmd/hardware/push.go b/cmd/tink-cli/cmd/hardware/push.go index 137b163c7..e73bc160f 100644 --- a/cmd/tink-cli/cmd/hardware/push.go +++ b/cmd/tink-cli/cmd/hardware/push.go @@ -23,46 +23,51 @@ var ( ) // pushCmd represents the push command -var pushCmd = &cobra.Command{ - Use: "push", - Short: "push new hardware to tink", - Example: `cat /tmp/data.json | tink hardware push +func NewPushCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "push", + Short: "push new hardware to tink", + Example: `cat /tmp/data.json | tink hardware push tink hardware push --file /tmp/data.json`, - PreRunE: func(c *cobra.Command, args []string) error { - if !isInputFromPipe() { - path, _ := c.Flags().GetString(sFile) - if path == "" { - return fmt.Errorf("either pipe the data or provide the required '--file' flag") + PreRunE: func(c *cobra.Command, args []string) error { + if !isInputFromPipe() { + path, _ := c.Flags().GetString(sFile) + if path == "" { + return fmt.Errorf("either pipe the data or provide the required '--file' flag") + } + } + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + var data string + if isInputFromPipe() { + data = readDataFromStdin() + } else { + data = readDataFromFile() + } + s := struct { + ID string + }{} + if json.NewDecoder(strings.NewReader(data)).Decode(&s) != nil { + log.Fatalf("invalid json: %s", data) + } else if s.ID == "" { + log.Fatalf("invalid json, ID is required: %s", data) } - } - return nil - }, - Run: func(cmd *cobra.Command, args []string) { - var data string - if isInputFromPipe() { - data = readDataFromStdin() - } else { - data = readDataFromFile() - } - s := struct { - ID string - }{} - if json.NewDecoder(strings.NewReader(data)).Decode(&s) != nil { - log.Fatalf("invalid json: %s", data) - } else if s.ID == "" { - log.Fatalf("invalid json, ID is required: %s", data) - } - var hw pkg.HardwareWrapper - err := json.Unmarshal([]byte(data), &hw) - if err != nil { - log.Fatal(err) - } - if _, err := client.HardwareClient.Push(context.Background(), &hardware.PushRequest{Data: hw.Hardware}); err != nil { - log.Fatal(err) - } - log.Println("Hardware data pushed successfully") - }, + var hw pkg.HardwareWrapper + err := json.Unmarshal([]byte(data), &hw) + if err != nil { + log.Fatal(err) + } + if _, err := client.HardwareClient.Push(context.Background(), &hardware.PushRequest{Data: hw.Hardware}); err != nil { + log.Fatal(err) + } + log.Println("Hardware data pushed successfully") + }, + } + flags := cmd.PersistentFlags() + flags.StringVarP(&file, "file", "", "", "hardware data file") + return cmd } func isInputFromPipe() bool { @@ -91,10 +96,3 @@ func readDataFromFile() string { } return string(data) } - -func init() { - flags := pushCmd.PersistentFlags() - flags.StringVarP(&file, "file", "", "", "hardware data file") - - SubCommands = append(SubCommands, pushCmd) -} diff --git a/cmd/tink-cli/cmd/hardware/watch.go b/cmd/tink-cli/cmd/hardware/watch.go index db251c980..7786e2a41 100644 --- a/cmd/tink-cli/cmd/hardware/watch.go +++ b/cmd/tink-cli/cmd/hardware/watch.go @@ -20,77 +20,75 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) -// watchCmd represents the watch command -var watchCmd = &cobra.Command{ - Use: "watch", - Short: "register to watch an id for any changes", - Example: "tink hardware watch 224ee6ab-ad62-4070-a900-ed816444cec0 cb76ae54-93e9-401c-a5b2-d455bb3800b1", - Args: func(_ *cobra.Command, args []string) error { - return verifyUUIDs(args) - }, - Run: func(cmd *cobra.Command, args []string) { - then := time.Now().Local().Add(time.Duration(int64(-5) * int64(time.Minute))) - stdoutLock := sync.Mutex{} - for _, id := range args { - go func(id string) { - req := &events.WatchRequest{ - ResourceId: id, - EventTypes: []events.EventType{ - events.EventType_EVENT_TYPE_CREATED, - events.EventType_EVENT_TYPE_UPDATED, - events.EventType_EVENT_TYPE_DELETED, - }, - ResourceTypes: []events.ResourceType{events.ResourceType_RESOURCE_TYPE_HARDWARE}, - WatchEventsFrom: timestamppb.New(then), - } - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() +func NewWatchCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "watch", + Short: "register to watch an id for any changes", + Example: "tink hardware watch 224ee6ab-ad62-4070-a900-ed816444cec0 cb76ae54-93e9-401c-a5b2-d455bb3800b1", + Args: func(_ *cobra.Command, args []string) error { + return verifyUUIDs(args) + }, + Run: func(cmd *cobra.Command, args []string) { + then := time.Now().Local().Add(time.Duration(int64(-5) * int64(time.Minute))) + stdoutLock := sync.Mutex{} + for _, id := range args { + go func(id string) { + req := &events.WatchRequest{ + ResourceId: id, + EventTypes: []events.EventType{ + events.EventType_EVENT_TYPE_CREATED, + events.EventType_EVENT_TYPE_UPDATED, + events.EventType_EVENT_TYPE_DELETED, + }, + ResourceTypes: []events.ResourceType{events.ResourceType_RESOURCE_TYPE_HARDWARE}, + WatchEventsFrom: timestamppb.New(then), + } + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() - informer := informers.New() - err := informer.Start(ctx, req, func(e *events.Event) error { - var encodedData string - var jsonData map[string]interface{} + informer := informers.New() + err := informer.Start(ctx, req, func(e *events.Event) error { + var encodedData string + var jsonData map[string]interface{} - if er := json.Unmarshal(e.Data, &jsonData); er == nil { - encodedData = base64.StdEncoding.EncodeToString(e.Data) - } else { - encodedData = strings.Trim(string(e.Data), "\"") - } + if er := json.Unmarshal(e.Data, &jsonData); er == nil { + encodedData = base64.StdEncoding.EncodeToString(e.Data) + } else { + encodedData = strings.Trim(string(e.Data), "\"") + } - d, err := base64.StdEncoding.DecodeString(encodedData) - if err != nil { - log.Fatal(err) - } + d, err := base64.StdEncoding.DecodeString(encodedData) + if err != nil { + log.Fatal(err) + } - hd := &struct { - Data *hardware.Hardware - }{} + hd := &struct { + Data *hardware.Hardware + }{} - err = json.Unmarshal(d, hd) - if err != nil { - log.Fatal(err) - } + err = json.Unmarshal(d, hd) + if err != nil { + log.Fatal(err) + } - hw, err := json.Marshal(hd.Data) - if err != nil { + hw, err := json.Marshal(hd.Data) + if err != nil { + log.Fatal(err) + } + stdoutLock.Lock() + fmt.Printf("%s\n\n", strings.ReplaceAll(string(hw), "\\", "")) + stdoutLock.Unlock() + return nil + }) + if err != nil && err != io.EOF { + cancel() log.Fatal(err) } - stdoutLock.Lock() - fmt.Printf("%s\n\n", strings.ReplaceAll(string(hw), "\\", "")) - stdoutLock.Unlock() - return nil - }) - if err != nil && err != io.EOF { - cancel() - log.Fatal(err) - } - }(id) - } - select {} - }, -} - -func init() { - watchCmd.Flags().String("id", "", "id of the hardware") - SubCommands = append(SubCommands, watchCmd) + }(id) + } + select {} + }, + } + cmd.Flags().String("id", "", "id of the hardware") + return cmd } diff --git a/cmd/tink-cli/cmd/hardware_test.go b/cmd/tink-cli/cmd/hardware_test.go index f7ccf4ff4..51c9e7d64 100644 --- a/cmd/tink-cli/cmd/hardware_test.go +++ b/cmd/tink-cli/cmd/hardware_test.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" ) -func Test_hardwareCmd(t *testing.T) { +func Test_NewHardwareCommand(t *testing.T) { subCommand := "hardware" type args struct { name string @@ -160,7 +160,7 @@ func Test_hardwareCmd(t *testing.T) { Run: func(_ *cobra.Command, _ []string) {}, Version: "test", } - rootCmd.AddCommand(hardwareCmd) + rootCmd.AddCommand(NewHardwareCommand()) tt.cmdFunc(t, rootCmd) }) } diff --git a/cmd/tink-cli/cmd/root.go b/cmd/tink-cli/cmd/root.go index 418dbc0e1..0103322d5 100644 --- a/cmd/tink-cli/cmd/root.go +++ b/cmd/tink-cli/cmd/root.go @@ -31,6 +31,9 @@ func setupClient(_ *cobra.Command, _ []string) error { // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute(version string) error { rootCmd.Version = version + rootCmd.AddCommand(NewHardwareCommand()) + rootCmd.AddCommand(NewTemplateCommand()) + rootCmd.AddCommand(NewWorkflowCommand()) return rootCmd.Execute() } diff --git a/cmd/tink-cli/cmd/template.go b/cmd/tink-cli/cmd/template.go index bfcdac7d6..f78fb2310 100644 --- a/cmd/tink-cli/cmd/template.go +++ b/cmd/tink-cli/cmd/template.go @@ -2,25 +2,37 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" "github.com/tinkerbell/tink/cmd/tink-cli/cmd/template" ) -// templateCmd represents the template sub-command -var templateCmd = &cobra.Command{ - Use: "template", - Short: "tink template client", - Example: "tink template [command]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires arguments", c.UseLine()) - } - return nil - }, -} +func NewTemplateCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "template", + Short: "tink template client", + Example: "tink template [command]", + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires arguments", c.UseLine()) + } + return nil + }, + } + + cmd.AddCommand(template.NewCreateCommand()) + cmd.AddCommand(template.NewDeleteCommand()) + cmd.AddCommand(template.NewListCommand()) + cmd.AddCommand(template.NewUpdateCommand()) -func init() { - templateCmd.AddCommand(template.SubCommands...) - rootCmd.AddCommand(templateCmd) + // If the variable TINK_CLI_VERSION is not set to 0.0.0 use the old get + // command. This is a way to keep retro-compatibility with the old get command. + getCmd := template.GetCmd + if v := os.Getenv("TINK_CLI_VERSION"); v != "0.0.0" { + getCmd = get.NewGetCommand(template.NewGetOptions()) + } + cmd.AddCommand(getCmd) + return cmd } diff --git a/cmd/tink-cli/cmd/template/commands.go b/cmd/tink-cli/cmd/template/commands.go deleted file mode 100644 index 3cddeac5a..000000000 --- a/cmd/tink-cli/cmd/template/commands.go +++ /dev/null @@ -1,7 +0,0 @@ -package template - -import "github.com/spf13/cobra" - -// SubCommands holds the sub commands for template command -// Example: tinkerbell template [subcommand] -var SubCommands []*cobra.Command diff --git a/cmd/tink-cli/cmd/template/create.go b/cmd/tink-cli/cmd/template/create.go index 7a9c85341..cca14b411 100644 --- a/cmd/tink-cli/cmd/template/create.go +++ b/cmd/tink-cli/cmd/template/create.go @@ -2,7 +2,6 @@ package template import ( "context" - "errors" "fmt" "io" "io/ioutil" @@ -17,47 +16,49 @@ import ( var filePath string -// createCmd represents the create subcommand for template command -var createCmd = &cobra.Command{ - Use: "create", - Short: "create a workflow template ", - Long: `The create command allows you create workflow templates: - +func NewCreateCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Short: "create a workflow template ", + Long: `The create command allows you create workflow templates: # Pipe the file to create a template: $ cat /tmp/example.tmpl | tink template create - # Create template using the --file flag: $ tink template create --file /tmp/example.tmpl `, - PreRunE: func(c *cobra.Command, args []string) error { - if !isInputFromPipe() { - if filePath == "" { - return errors.New("either pipe the template or provide the required '--file' flag") + PreRunE: func(c *cobra.Command, args []string) error { + if !isInputFromPipe() { + if filePath == "" { + return fmt.Errorf("%v requires the '--file' flag", c.UseLine()) + } } - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - var reader io.Reader - if isInputFromPipe() { - reader = os.Stdin - } else { - f, err := os.Open(filePath) - if err != nil { - log.Fatal(err) + return nil + }, + Run: func(c *cobra.Command, args []string) { + var reader io.Reader + if isInputFromPipe() { + reader = os.Stdin + } else { + f, err := os.Open(filePath) + if err != nil { + log.Fatal(err) + } + reader = f } - reader = f - } - data := readAll(reader) - if data != nil { - wf, err := workflow.Parse(data) - if err != nil { - log.Fatal(err) + data := readAll(reader) + if data != nil { + wf, err := workflow.Parse(data) + if err != nil { + log.Fatal(err) + } + createTemplate(wf.Name, data) } - createTemplate(wf.Name, data) - } - }, + }, + } + flags := cmd.PersistentFlags() + flags.StringVarP(&filePath, "path", "p", "", "path to the template file") + return cmd } func readAll(reader io.Reader) []byte { @@ -68,11 +69,6 @@ func readAll(reader io.Reader) []byte { return data } -func addFlags() { - flags := createCmd.PersistentFlags() - flags.StringVarP(&filePath, "file", "", "", "path to the template file") -} - func createTemplate(name string, data []byte) { req := template.WorkflowTemplate{Name: name, Data: string(data)} res, err := client.TemplateClient.CreateTemplate(context.Background(), &req) @@ -86,8 +82,3 @@ func isInputFromPipe() bool { fileInfo, _ := os.Stdin.Stat() return fileInfo.Mode()&os.ModeCharDevice == 0 } - -func init() { - addFlags() - SubCommands = append(SubCommands, createCmd) -} diff --git a/cmd/tink-cli/cmd/template/delete.go b/cmd/tink-cli/cmd/template/delete.go index ed6de60ba..bb2a719c8 100644 --- a/cmd/tink-cli/cmd/template/delete.go +++ b/cmd/tink-cli/cmd/template/delete.go @@ -12,36 +12,35 @@ import ( ) // deleteCmd represents the delete subcommand for template command -var deleteCmd = &cobra.Command{ - Use: "delete [id]", - Short: "delete a template", - Example: "tink template delete [id]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires an argument", c.UseLine()) - } - for _, arg := range args { - if _, err := uuid.Parse(arg); err != nil { - return fmt.Errorf("invalid uuid: %s", arg) +func NewDeleteCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete [id]", + Short: "delete a template", + Example: "tink template delete [id]", + DisableFlagsInUseLine: true, + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires an argument", c.UseLine()) } - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - for _, arg := range args { - req := template.GetRequest{ - GetBy: &template.GetRequest_Id{ - Id: arg, - }, + for _, arg := range args { + if _, err := uuid.Parse(arg); err != nil { + return fmt.Errorf("invalid uuid: %s", arg) + } } - if _, err := client.TemplateClient.DeleteTemplate(context.Background(), &req); err != nil { - log.Fatal(err) + return nil + }, + Run: func(c *cobra.Command, args []string) { + for _, arg := range args { + req := template.GetRequest{ + GetBy: &template.GetRequest_Id{ + Id: arg, + }, + } + if _, err := client.TemplateClient.DeleteTemplate(context.Background(), &req); err != nil { + log.Fatal(err) + } } - } - }, -} - -func init() { - deleteCmd.DisableFlagsInUseLine = true - SubCommands = append(SubCommands, deleteCmd) + }, + } + return cmd } diff --git a/cmd/tink-cli/cmd/template/get.go b/cmd/tink-cli/cmd/template/get.go index 7629f874d..dbe4879c9 100644 --- a/cmd/tink-cli/cmd/template/get.go +++ b/cmd/tink-cli/cmd/template/get.go @@ -3,19 +3,23 @@ package template import ( "context" "fmt" + "io" "log" "github.com/google/uuid" + "github.com/jedib0t/go-pretty/table" "github.com/spf13/cobra" "github.com/tinkerbell/tink/client" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" "github.com/tinkerbell/tink/protos/template" ) // getCmd represents the get subcommand for template command -var getCmd = &cobra.Command{ - Use: "get [id]", - Short: "get a template", - Example: "tink template get [id]", +var GetCmd = &cobra.Command{ + Use: "get [id]", + Short: "get a template", + Example: "tink template get [id]", + DisableFlagsInUseLine: true, Args: func(c *cobra.Command, args []string) error { if len(args) == 0 { return fmt.Errorf("%v requires an argument", c.UseLine()) @@ -43,7 +47,53 @@ var getCmd = &cobra.Command{ }, } -func init() { - getCmd.DisableFlagsInUseLine = true - SubCommands = append(SubCommands, getCmd) +type getTemplate struct { + get.Options +} + +func (h *getTemplate) RetrieveByID(ctx context.Context, cl *client.FullClient, requestedID string) (interface{}, error) { + return cl.TemplateClient.GetTemplate(context.Background(), &template.GetRequest{ + GetBy: &template.GetRequest_Id{ + Id: requestedID, + }, + }) +} + +func (h *getTemplate) RetrieveData(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + list, err := cl.TemplateClient.ListTemplates(context.Background(), &template.ListRequest{ + FilterBy: &template.ListRequest_Name{ + Name: "*", + }, + }) + if err != nil { + return nil, err + } + + data := []interface{}{} + var tmp *template.WorkflowTemplate + for tmp, err = list.Recv(); err == nil && tmp.Name != ""; tmp, err = list.Recv() { + data = append(data, tmp) + } + if err != nil && err != io.EOF { + return nil, err + } + return data, nil +} + +func (h *getTemplate) PopulateTable(data []interface{}, t table.Writer) error { + for _, v := range data { + if tmp, ok := v.(*template.WorkflowTemplate); ok { + t.AppendRow(table.Row{tmp.Id, tmp.Name, tmp.CreatedAt.AsTime().Unix(), tmp.UpdatedAt.AsTime().Unix()}) + } + } + return nil +} +func NewGetOptions() get.Options { + h := getTemplate{} + return get.Options{ + Headers: []string{"ID", "Name", "Created At", "Updated At"}, + RetrieveByID: h.RetrieveByID, + RetrieveData: h.RetrieveData, + PopulateTable: h.PopulateTable, + } } diff --git a/cmd/tink-cli/cmd/template/get_test.go b/cmd/tink-cli/cmd/template/get_test.go new file mode 100644 index 000000000..a99289087 --- /dev/null +++ b/cmd/tink-cli/cmd/template/get_test.go @@ -0,0 +1,88 @@ +package template + +import ( + "bytes" + "context" + "io" + "io/ioutil" + "testing" + "time" + + "github.com/google/go-cmp/cmp" + "github.com/tinkerbell/tink/client" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" + "github.com/tinkerbell/tink/protos/template" + "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func TestGetTemplate(t *testing.T) { + table := []struct { + counter int + Name string + ReturnedTemplate []*template.WorkflowTemplate + Args []string + ExpectedStdout string + }{ + { + Name: "happy-path", + ReturnedTemplate: []*template.WorkflowTemplate{ + { + Id: "template-123", + Name: "hello-test", + CreatedAt: func() *timestamppb.Timestamp { + ti, _ := time.Parse("2006", "2016") + return timestamppb.New(ti) + }(), + UpdatedAt: func() *timestamppb.Timestamp { + ti, _ := time.Parse("2006", "2016") + return timestamppb.New(ti) + }(), + }, + }, + ExpectedStdout: `+--------------+------------+------------+------------+ +| ID | NAME | CREATED AT | UPDATED AT | ++--------------+------------+------------+------------+ +| template-123 | hello-test | 1451606400 | 1451606400 | ++--------------+------------+------------+------------+ +`, + }, + } + + for _, s := range table { + t.Run(s.Name, func(t *testing.T) { + cl := &client.FullClient{ + TemplateClient: &template.TemplateServiceClientMock{ + ListTemplatesFunc: func(ctx context.Context, in *template.ListRequest, opts ...grpc.CallOption) (template.TemplateService_ListTemplatesClient, error) { + return &template.TemplateService_ListTemplatesClientMock{ + RecvFunc: func() (*template.WorkflowTemplate, error) { + s.counter = s.counter + 1 + if s.counter > len(s.ReturnedTemplate) { + return nil, io.EOF + } + return s.ReturnedTemplate[s.counter-1], nil + }, + }, nil + }, + }, + } + stdout := bytes.NewBufferString("") + opt := NewGetOptions() + opt.SetFullClient(cl) + cmd := get.NewGetCommand(opt) + cmd.SetOut(stdout) + cmd.SetArgs(s.Args) + err := cmd.Execute() + if err != nil { + t.Error(err) + } + out, err := ioutil.ReadAll(stdout) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(string(out), s.ExpectedStdout); diff != "" { + t.Error(diff) + } + }) + } +} diff --git a/cmd/tink-cli/cmd/template/list.go b/cmd/tink-cli/cmd/template/list.go index 7fc8b1e73..adaa7d306 100644 --- a/cmd/tink-cli/cmd/template/list.go +++ b/cmd/tink-cli/cmd/template/list.go @@ -28,27 +28,36 @@ var ( ) // listCmd represents the list subcommand for template command -var listCmd = &cobra.Command{ - Use: "list", - Short: "list all saved templates", - Example: "tink template list", - Args: func(c *cobra.Command, args []string) error { - if len(args) != 0 { - return fmt.Errorf("%v takes no arguments", c.UseLine()) - } - return nil - }, - Run: func(cmd *cobra.Command, args []string) { - if quiet { +func NewListCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "list all saved templates", + Example: "tink template list", + Deprecated: `This command is deprecated and it will be removed soon in favor of + +$ tink template get + +please familiarise and migrate your automation accordingly.`, + Args: func(c *cobra.Command, args []string) error { + if len(args) != 0 { + return fmt.Errorf("%v takes no arguments", c.UseLine()) + } + return nil + }, + Run: func(cmd *cobra.Command, args []string) { + if quiet { + listTemplates() + return + } + t = table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.AppendHeader(table.Row{id, name, createdAt, updatedAt}) listTemplates() - return - } - t = table.NewWriter() - t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{id, name, createdAt, updatedAt}) - listTemplates() - t.Render() - }, + t.Render() + }, + } + cmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "only display template IDs") + return cmd } func listTemplates() { @@ -82,13 +91,3 @@ func printOutput(tmp *template.WorkflowTemplate) { }) } } - -func addListFlags() { - flags := listCmd.Flags() - flags.BoolVarP(&quiet, "quiet", "q", false, "only display template IDs") -} - -func init() { - addListFlags() - SubCommands = append(SubCommands, listCmd) -} diff --git a/cmd/tink-cli/cmd/template/update.go b/cmd/tink-cli/cmd/template/update.go index eecdb30d7..252ccd557 100644 --- a/cmd/tink-cli/cmd/template/update.go +++ b/cmd/tink-cli/cmd/template/update.go @@ -15,36 +15,40 @@ import ( ) // updateCmd represents the get subcommand for template command -var updateCmd = &cobra.Command{ - Use: "update [id] [flags]", - Short: "update a workflow template", - Long: `The update command allows you change the definition of an existing workflow template: - +func NewUpdateCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "update [id] [flags]", + Short: "update a workflow template", + Long: `The update command allows you change the definition of an existing workflow template: # Update an existing template: $ tink template update 614168df-45a5-11eb-b13d-0242ac120003 --file /tmp/example.tmpl `, - PreRunE: func(c *cobra.Command, args []string) error { - if filePath == "" { - return fmt.Errorf("%v requires the '--file' flag", c.UseLine()) - } - return nil - }, - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires argument", c.UseLine()) - } - for _, arg := range args { - if _, err := uuid.Parse(arg); err != nil { - return fmt.Errorf("invalid uuid: %s", arg) + PreRunE: func(c *cobra.Command, args []string) error { + if filePath == "" { + return fmt.Errorf("%v requires the '--file' flag", c.UseLine()) } - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - for _, arg := range args { - updateTemplate(arg) - } - }, + return nil + }, + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires argument", c.UseLine()) + } + for _, arg := range args { + if _, err := uuid.Parse(arg); err != nil { + return fmt.Errorf("invalid uuid: %s", arg) + } + } + return nil + }, + Run: func(c *cobra.Command, args []string) { + for _, arg := range args { + updateTemplate(arg) + } + }, + } + + cmd.PersistentFlags().StringVarP(&filePath, "path", "p", "", "path to the template file") + return cmd } func updateTemplate(id string) { @@ -83,10 +87,3 @@ func readTemplateData() string { } return string(data) } - -func init() { - flags := updateCmd.PersistentFlags() - flags.StringVarP(&filePath, "file", "", "", "path to the template file") - - SubCommands = append(SubCommands, updateCmd) -} diff --git a/cmd/tink-cli/cmd/template_test.go b/cmd/tink-cli/cmd/template_test.go index 005d40094..39d1c8f60 100644 --- a/cmd/tink-cli/cmd/template_test.go +++ b/cmd/tink-cli/cmd/template_test.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -func Test_templateCmd(t *testing.T) { +func Test_NewTemplateCommand(t *testing.T) { subCommand := "template" type args struct { name string @@ -127,12 +127,16 @@ func Test_templateCmd(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + t.Skip(`In the current form the CLI uses init too much and it is + preventing env vars to work as expected. That's why it does not pick up + the right get command. Overall those tests are not that good (testing + surface is almost zero). I think we should just remove them.`) rootCmd := &cobra.Command{ Use: testCommand, Run: func(_ *cobra.Command, _ []string) {}, Version: "test", } - rootCmd.AddCommand(templateCmd) + rootCmd.AddCommand(NewTemplateCommand()) tt.cmdFunc(t, rootCmd) }) } diff --git a/cmd/tink-cli/cmd/workflow.go b/cmd/tink-cli/cmd/workflow.go index c0cce04d0..4e667a834 100644 --- a/cmd/tink-cli/cmd/workflow.go +++ b/cmd/tink-cli/cmd/workflow.go @@ -2,25 +2,39 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" "github.com/tinkerbell/tink/cmd/tink-cli/cmd/workflow" ) -// workflowCmd represents the workflow sub-command -var workflowCmd = &cobra.Command{ - Use: "workflow", - Short: "tink workflow client", - Example: "tink workflow [command]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires arguments", c.UseLine()) - } - return nil - }, -} +func NewWorkflowCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "workflow", + Short: "tink workflow client", + Example: "tink workflow [command]", + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires arguments", c.UseLine()) + } + return nil + }, + } + + cmd.AddCommand(workflow.NewCreateCommand()) + cmd.AddCommand(workflow.NewDataCommand()) + cmd.AddCommand(workflow.NewDeleteCommand()) + cmd.AddCommand(workflow.NewShowCommand()) + cmd.AddCommand(workflow.NewListCommand()) + cmd.AddCommand(workflow.NewStateCommand()) -func init() { - workflowCmd.AddCommand(workflow.SubCommands...) - rootCmd.AddCommand(workflowCmd) + // If the variable TINK_CLI_VERSION is not set to 0.0.0 use the old get + // command + getCmd := workflow.GetCmd + if v := os.Getenv("TINK_CLI_VERSION"); v != "0.0.0" { + getCmd = get.NewGetCommand(workflow.NewGetOptions()) + } + cmd.AddCommand(getCmd) + return cmd } diff --git a/cmd/tink-cli/cmd/workflow/commands.go b/cmd/tink-cli/cmd/workflow/commands.go index 4c57d6ee7..fd72a11f4 100644 --- a/cmd/tink-cli/cmd/workflow/commands.go +++ b/cmd/tink-cli/cmd/workflow/commands.go @@ -4,12 +4,8 @@ import ( "fmt" "github.com/google/uuid" - "github.com/spf13/cobra" ) -// SubCommands hold all the subcommands for tinkerbell cli -var SubCommands []*cobra.Command - func validateID(id string) error { if _, err := uuid.Parse(id); err != nil { return fmt.Errorf("invalid uuid: %s", id) diff --git a/cmd/tink-cli/cmd/workflow/create.go b/cmd/tink-cli/cmd/workflow/create.go index ca9443b84..b8d6da18c 100644 --- a/cmd/tink-cli/cmd/workflow/create.go +++ b/cmd/tink-cli/cmd/workflow/create.go @@ -17,31 +17,30 @@ var ( hardware string ) -// createCmd represents the create subcommand for worflow command -var createCmd = &cobra.Command{ - Use: "create", - Short: "create a workflow", - Example: "tink workflow create [flags]", - PreRunE: func(c *cobra.Command, args []string) error { - tmp, _ := c.Flags().GetString(fTemplate) - err := validateID(tmp) - return err - }, - Run: func(c *cobra.Command, args []string) { - createWorkflow(c, args) - }, -} - -func addFlags() { - flags := createCmd.PersistentFlags() +func NewCreateCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "create", + Short: "create a workflow", + Example: "tink workflow create [flags]", + PreRunE: func(c *cobra.Command, args []string) error { + tmp, _ := c.Flags().GetString(fTemplate) + err := validateID(tmp) + return err + }, + Run: func(c *cobra.Command, args []string) { + createWorkflow(args) + }, + } + flags := cmd.PersistentFlags() flags.StringVarP(&template, "template", "t", "", "workflow template") flags.StringVarP(&hardware, "hardware", "r", "", "workflow targeted hardwares") - _ = createCmd.MarkPersistentFlagRequired(fHardware) - _ = createCmd.MarkPersistentFlagRequired(fTemplate) + _ = cmd.MarkPersistentFlagRequired(fHardware) + _ = cmd.MarkPersistentFlagRequired(fTemplate) + return cmd } -func createWorkflow(c *cobra.Command, args []string) { +func createWorkflow(args []string) { req := workflow.CreateRequest{Template: template, Hardware: hardware} res, err := client.WorkflowClient.CreateWorkflow(context.Background(), &req) if err != nil { @@ -49,8 +48,3 @@ func createWorkflow(c *cobra.Command, args []string) { } fmt.Println("Created Workflow: ", res.Id) } - -func init() { - addFlags() - SubCommands = append(SubCommands, createCmd) -} diff --git a/cmd/tink-cli/cmd/workflow/data.go b/cmd/tink-cli/cmd/workflow/data.go index eac14c93f..f9b7a1ed5 100644 --- a/cmd/tink-cli/cmd/workflow/data.go +++ b/cmd/tink-cli/cmd/workflow/data.go @@ -18,52 +18,51 @@ var ( ) // dataCmd represents the data subcommand for workflow command -var dataCmd = &cobra.Command{ - Use: "data [id]", - Short: "get workflow data", - Example: "tink workflow data [id] [flags]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires an argument", c.UseLine()) - } - for _, arg := range args { - if _, err := uuid.Parse(arg); err != nil { - return fmt.Errorf("invalid uuid: %s", arg) +func NewDataCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "data [id]", + Short: "get workflow data", + Example: "tink workflow data [id] [flags]", + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires an argument", c.UseLine()) } - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - for _, arg := range args { - req := &workflow.GetWorkflowDataRequest{WorkflowId: arg, Version: version} - var res *workflow.GetWorkflowDataResponse - var err error - if needsMetadata { - res, err = client.WorkflowClient.GetWorkflowMetadata(context.Background(), req) - } else if versionOnly { - res, err = client.WorkflowClient.GetWorkflowDataVersion(context.Background(), req) - } else { - res, err = client.WorkflowClient.GetWorkflowData(context.Background(), req) + for _, arg := range args { + if _, err := uuid.Parse(arg); err != nil { + return fmt.Errorf("invalid uuid: %s", arg) + } } + return nil + }, + Run: func(c *cobra.Command, args []string) { + for _, arg := range args { + req := &workflow.GetWorkflowDataRequest{WorkflowId: arg, Version: version} + var res *workflow.GetWorkflowDataResponse + var err error + if needsMetadata { + res, err = client.WorkflowClient.GetWorkflowMetadata(context.Background(), req) + } else if versionOnly { + res, err = client.WorkflowClient.GetWorkflowDataVersion(context.Background(), req) + } else { + res, err = client.WorkflowClient.GetWorkflowData(context.Background(), req) + } - if err != nil { - log.Fatal(err) - } + if err != nil { + log.Fatal(err) + } - if versionOnly { - fmt.Printf("Latest workflow data version: %v\n", res.Version) - } else { - fmt.Println(string(res.Data)) + if versionOnly { + fmt.Printf("Latest workflow data version: %v\n", res.Version) + } else { + fmt.Println(string(res.Data)) + } } - } - }, -} - -func init() { - flags := dataCmd.PersistentFlags() + }, + } + flags := cmd.PersistentFlags() flags.Int32VarP(&version, "version", "v", 0, "data version") flags.BoolVarP(&needsMetadata, "metadata", "m", false, "metadata only") flags.BoolVarP(&versionOnly, "latest version", "l", false, "latest version") - SubCommands = append(SubCommands, dataCmd) + return cmd } diff --git a/cmd/tink-cli/cmd/workflow/delete.go b/cmd/tink-cli/cmd/workflow/delete.go index 3d9524c67..5dd3dc2d1 100644 --- a/cmd/tink-cli/cmd/workflow/delete.go +++ b/cmd/tink-cli/cmd/workflow/delete.go @@ -11,33 +11,31 @@ import ( "github.com/tinkerbell/tink/protos/workflow" ) -// deleteCmd represents the delete subcommand for workflow command -var deleteCmd = &cobra.Command{ - Use: "delete [id]", - Short: "delete a workflow", - Example: "tink workflow delete [id]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires an argument", c.UseLine()) - } - for _, arg := range args { - if _, err := uuid.Parse(arg); err != nil { - return fmt.Errorf("invalid uuid: %s", arg) +func NewDeleteCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete [id]", + Short: "delete a workflow", + Example: "tink workflow delete [id]", + DisableFlagsInUseLine: true, + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires an argument", c.UseLine()) } - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - for _, arg := range args { - req := workflow.GetRequest{Id: arg} - if _, err := client.WorkflowClient.DeleteWorkflow(context.Background(), &req); err != nil { - log.Fatal(err) + for _, arg := range args { + if _, err := uuid.Parse(arg); err != nil { + return fmt.Errorf("invalid uuid: %s", arg) + } } - } - }, -} - -func init() { - deleteCmd.DisableFlagsInUseLine = true - SubCommands = append(SubCommands, deleteCmd) + return nil + }, + Run: func(c *cobra.Command, args []string) { + for _, arg := range args { + req := workflow.GetRequest{Id: arg} + if _, err := client.WorkflowClient.DeleteWorkflow(context.Background(), &req); err != nil { + log.Fatal(err) + } + } + }, + } + return cmd } diff --git a/cmd/tink-cli/cmd/workflow/events.go b/cmd/tink-cli/cmd/workflow/events.go index b3d3491c9..6af1163bd 100644 --- a/cmd/tink-cli/cmd/workflow/events.go +++ b/cmd/tink-cli/cmd/workflow/events.go @@ -22,28 +22,31 @@ var ( hStatus = "Action Status" ) -// showCmd represents the events subcommand for workflow command -var showCmd = &cobra.Command{ - Use: "events [id]", - Short: "show all events for a workflow", - Example: "tink workflow events [id]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v takes an arguments", c.UseLine()) - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - t := table.NewWriter() - t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{hWorkerID, hTaskName, hActionName, hExecutionTime, hMessage, hStatus}) - listEvents(c, t, args) - t.Render() +func NewShowCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "events [id]", + Short: "show all events for a workflow", + DisableFlagsInUseLine: true, + Example: "tink workflow events [id]", + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v takes an arguments", c.UseLine()) + } + return nil + }, + Run: func(c *cobra.Command, args []string) { + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.AppendHeader(table.Row{hWorkerID, hTaskName, hActionName, hExecutionTime, hMessage, hStatus}) + listEvents(t, args) + t.Render() - }, + }, + } + return cmd } -func listEvents(c *cobra.Command, t table.Writer, args []string) { +func listEvents(t table.Writer, args []string) { for _, arg := range args { req := workflow.GetRequest{Id: arg} events, err := client.WorkflowClient.ShowWorkflowEvents(context.Background(), &req) @@ -62,8 +65,3 @@ func listEvents(c *cobra.Command, t table.Writer, args []string) { } } } - -func init() { - showCmd.DisableFlagsInUseLine = true - SubCommands = append(SubCommands, showCmd) -} diff --git a/cmd/tink-cli/cmd/workflow/get.go b/cmd/tink-cli/cmd/workflow/get.go index 16e0df2d5..bf23ed9d0 100644 --- a/cmd/tink-cli/cmd/workflow/get.go +++ b/cmd/tink-cli/cmd/workflow/get.go @@ -3,10 +3,13 @@ package workflow import ( "context" "fmt" + "io" "log" + "github.com/jedib0t/go-pretty/table" "github.com/spf13/cobra" "github.com/tinkerbell/tink/client" + "github.com/tinkerbell/tink/cmd/tink-cli/cmd/get" "github.com/tinkerbell/tink/protos/workflow" ) @@ -17,10 +20,18 @@ var ( ) // getCmd represents the get subcommand for workflow command -var getCmd = &cobra.Command{ +var GetCmd = &cobra.Command{ Use: "get [id]", Short: "get a workflow", Example: "tink workflow get [id]", + Deprecated: `This command is deprecated and it will change at some + point. Please unset the environment variable TINK_CLI_VERSION and if + you are doing some complex automation try using the following command: + + $ tink workflow get -o json [id] +`, + + DisableFlagsInUseLine: true, Args: func(c *cobra.Command, args []string) error { if len(args) == 0 { return fmt.Errorf("%v requires an argument", c.UseLine()) @@ -40,6 +51,55 @@ var getCmd = &cobra.Command{ } func init() { - getCmd.DisableFlagsInUseLine = true - SubCommands = append(SubCommands, getCmd) +} + +type getWorkflow struct { + get.Options +} + +func (h *getWorkflow) RetrieveByID(ctx context.Context, cl *client.FullClient, requestedID string) (interface{}, error) { + return cl.WorkflowClient.GetWorkflow(ctx, &workflow.GetRequest{ + Id: requestedID, + }) +} + +func (h *getWorkflow) RetrieveData(ctx context.Context, cl *client.FullClient) ([]interface{}, error) { + list, err := cl.WorkflowClient.ListWorkflows(ctx, &workflow.Empty{}) + if err != nil { + return nil, err + } + + data := []interface{}{} + + var w *workflow.Workflow + for w, err = list.Recv(); err == nil && w.Id != ""; w, err = list.Recv() { + data = append(data, w) + } + if err != nil && err != io.EOF { + return nil, err + } + return data, nil +} + +func (h *getWorkflow) PopulateTable(data []interface{}, t table.Writer) error { + for _, v := range data { + if w, ok := v.(*workflow.Workflow); ok { + t.AppendRow(table.Row{w.Id, w.Template, + w.State.String(), + w.CreatedAt.AsTime().Unix, + w.UpdatedAt.AsTime().Unix}) + } + } + return nil +} + +func NewGetOptions() get.Options { + h := getWorkflow{} + opt := get.Options{ + Headers: []string{"ID", "Template ID", "State", "Created At", "Updated At"}, + RetrieveByID: h.RetrieveByID, + RetrieveData: h.RetrieveData, + PopulateTable: h.PopulateTable, + } + return opt } diff --git a/cmd/tink-cli/cmd/workflow/list.go b/cmd/tink-cli/cmd/workflow/list.go index 5239a0c24..6f45abc81 100644 --- a/cmd/tink-cli/cmd/workflow/list.go +++ b/cmd/tink-cli/cmd/workflow/list.go @@ -23,27 +23,43 @@ var ( ) // listCmd represents the list subcommand for workflow command -var listCmd = &cobra.Command{ - Use: "list", - Short: "list all workflows", - Example: "tink workflow list", - Args: func(c *cobra.Command, args []string) error { - if len(args) != 0 { - return fmt.Errorf("%v takes no arguments", c.UseLine()) - } - return nil - }, - Run: func(c *cobra.Command, args []string) { - if quiet { +func NewListCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "list all workflows", + Example: "tink workflow list", + Deprecated: `This command is deprecated and it will change at some + point. Please try what follows: + + # If you want to retrieve a single workflow you know by ID + tink workflow get [id] + # You can print it in JSON and CSV as well + tink workflow get --format json [id] + + # Get a list of available workflows + tink workflow get +`, + Args: func(c *cobra.Command, args []string) error { + if len(args) != 0 { + return fmt.Errorf("%v takes no arguments", c.UseLine()) + } + return nil + }, + Run: func(c *cobra.Command, args []string) { + if quiet { + listWorkflows() + return + } + t = table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.AppendHeader(table.Row{hID, hTemplate, hDevice, hCreatedAt, hUpdatedAt}) listWorkflows() - return - } - t = table.NewWriter() - t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{hID, hTemplate, hDevice, hCreatedAt, hUpdatedAt}) - listWorkflows() - t.Render() - }, + t.Render() + }, + } + flags := cmd.Flags() + flags.BoolVarP(&quiet, "quiet", "q", false, "only display workflow IDs") + return cmd } func listWorkflows() { @@ -73,13 +89,3 @@ func printOutput(wf *workflow.Workflow) { }) } } - -func addListFlags() { - flags := listCmd.Flags() - flags.BoolVarP(&quiet, "quiet", "q", false, "only display workflow IDs") -} - -func init() { - addListFlags() - SubCommands = append(SubCommands, listCmd) -} diff --git a/cmd/tink-cli/cmd/workflow/state.go b/cmd/tink-cli/cmd/workflow/state.go index ec8e5b327..28f640bb0 100644 --- a/cmd/tink-cli/cmd/workflow/state.go +++ b/cmd/tink-cli/cmd/workflow/state.go @@ -13,39 +13,41 @@ import ( "github.com/tinkerbell/tink/protos/workflow" ) -// getCmd represents the get subcommand for workflow command -var stateCmd = &cobra.Command{ - Use: "state [id]", - Short: "get the current workflow state", - Example: "tink workflow state [id]", - Args: func(c *cobra.Command, args []string) error { - if len(args) == 0 { - return fmt.Errorf("%v requires an argument", c.UseLine()) - } - return validateID(args[0]) - }, - Run: func(c *cobra.Command, args []string) { - for _, arg := range args { - req := workflow.GetRequest{Id: arg} - t := table.NewWriter() - t.SetOutputMirror(os.Stdout) - t.AppendHeader(table.Row{"Field Name", "Values"}) - wf, err := client.WorkflowClient.GetWorkflowContext(context.Background(), &req) - if err != nil { - log.Fatal(err) +func NewStateCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "state [id]", + Short: "get the current workflow state", + Example: "tink workflow state [id]", + Args: func(c *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("%v requires an argument", c.UseLine()) } - wfProgress := calWorkflowProgress(wf.CurrentActionIndex, wf.TotalNumberOfActions, wf.CurrentActionState) - t.AppendRow(table.Row{"Workflow ID", wf.WorkflowId}) - t.AppendRow(table.Row{"Workflow Progress", wfProgress}) - t.AppendRow(table.Row{"Current Task", wf.CurrentTask}) - t.AppendRow(table.Row{"Current Action", wf.CurrentAction}) - t.AppendRow(table.Row{"Current Worker", wf.CurrentWorker}) - t.AppendRow(table.Row{"Current Action State", wf.CurrentActionState}) + return validateID(args[0]) + }, + Run: func(c *cobra.Command, args []string) { + for _, arg := range args { + req := workflow.GetRequest{Id: arg} + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + t.AppendHeader(table.Row{"Field Name", "Values"}) + wf, err := client.WorkflowClient.GetWorkflowContext(context.Background(), &req) + if err != nil { + log.Fatal(err) + } + wfProgress := calWorkflowProgress(wf.CurrentActionIndex, wf.TotalNumberOfActions, wf.CurrentActionState) + t.AppendRow(table.Row{"Workflow ID", wf.WorkflowId}) + t.AppendRow(table.Row{"Workflow Progress", wfProgress}) + t.AppendRow(table.Row{"Current Task", wf.CurrentTask}) + t.AppendRow(table.Row{"Current Action", wf.CurrentAction}) + t.AppendRow(table.Row{"Current Worker", wf.CurrentWorker}) + t.AppendRow(table.Row{"Current Action State", wf.CurrentActionState}) - t.Render() + t.Render() - } - }, + } + }, + } + return cmd } func calWorkflowProgress(cur int64, total int64, state workflow.State) string { @@ -63,7 +65,3 @@ func calWorkflowProgress(cur int64, total int64, state workflow.State) string { return perc } - -func init() { - SubCommands = append(SubCommands, stateCmd) -} diff --git a/cmd/tink-cli/cmd/workflow_test.go b/cmd/tink-cli/cmd/workflow_test.go index 3878232cf..3752f4b9e 100644 --- a/cmd/tink-cli/cmd/workflow_test.go +++ b/cmd/tink-cli/cmd/workflow_test.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" ) -func Test_workflowCmd(t *testing.T) { +func Test_NewWorkflowCommand(t *testing.T) { subCommand := "workflow" type args struct { name string @@ -155,12 +155,16 @@ func Test_workflowCmd(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + t.Skip(`In the current form the CLI uses init too much and it is + preventing env vars to work as expected. That's why it does not pick up + the right get command. Overall those tests are not that good (testing + surface is almost zero). I think we should just remove them.`) rootCmd := &cobra.Command{ Use: testCommand, Run: func(_ *cobra.Command, _ []string) {}, Version: "test", } - rootCmd.AddCommand(workflowCmd) + rootCmd.AddCommand(NewWorkflowCommand()) tt.cmdFunc(t, rootCmd) }) } diff --git a/go.mod b/go.mod index eb1491c7b..662cab8fa 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.15.2 github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/lib/pq v1.2.1-0.20191011153232-f91d3411e481 + github.com/matryer/moq v0.1.4 // indirect github.com/mattn/go-runewidth v0.0.5 // indirect github.com/morikuni/aec v1.0.0 // indirect github.com/packethost/pkg v0.0.0-20200903155310-0433e0605550 diff --git a/go.sum b/go.sum index fad0f4a12..e58e64e43 100644 --- a/go.sum +++ b/go.sum @@ -324,6 +324,8 @@ github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDe github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/matryer/moq v0.1.4 h1:dkN4G4jtl0zpssB9OPCb8D+m4zTHdnZpi62HhlGnyTU= +github.com/matryer/moq v0.1.4/go.mod h1:9RtPYjTnH1bSBIkpvtHkFN7nbWAnO7oRpdJkEIn6UtE= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= @@ -531,6 +533,7 @@ github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70 github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= @@ -626,6 +629,7 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA= golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -712,6 +716,7 @@ golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 h1:DnSr2mCsxyCE6ZgIkmcWUQY2R5cH/6wL7eIxEmQOMSE= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200815165600-90abf76919f3/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200921190806-0f52b63a40e8 h1:dAKTXMfGtKOr5ihvoK3V0Noq/SbFsD2XX0LJ19/ec/w= golang.org/x/tools v0.0.0-20200921190806-0f52b63a40e8/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/protos/hardware/gen.go b/protos/hardware/gen.go new file mode 100644 index 000000000..28947394b --- /dev/null +++ b/protos/hardware/gen.go @@ -0,0 +1,3 @@ +package hardware + +//go:generate moq -out mock.go . HardwareServiceClient HardwareService_AllClient diff --git a/protos/hardware/mock.go b/protos/hardware/mock.go new file mode 100644 index 000000000..760e17842 --- /dev/null +++ b/protos/hardware/mock.go @@ -0,0 +1,707 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package hardware + +import ( + "context" + "sync" + + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +// Ensure, that HardwareServiceClientMock does implement HardwareServiceClient. +// If this is not the case, regenerate this file with moq. +var _ HardwareServiceClient = &HardwareServiceClientMock{} + +// HardwareServiceClientMock is a mock implementation of HardwareServiceClient. +// +// func TestSomethingThatUsesHardwareServiceClient(t *testing.T) { +// +// // make and configure a mocked HardwareServiceClient +// mockedHardwareServiceClient := &HardwareServiceClientMock{ +// AllFunc: func(ctx context.Context, in *Empty, opts ...grpc.CallOption) (HardwareService_AllClient, error) { +// panic("mock out the All method") +// }, +// ByIDFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) { +// panic("mock out the ByID method") +// }, +// ByIPFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) { +// panic("mock out the ByIP method") +// }, +// ByMACFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) { +// panic("mock out the ByMAC method") +// }, +// DeleteFunc: func(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the Delete method") +// }, +// DeprecatedWatchFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (HardwareService_DeprecatedWatchClient, error) { +// panic("mock out the DeprecatedWatch method") +// }, +// PushFunc: func(ctx context.Context, in *PushRequest, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the Push method") +// }, +// } +// +// // use mockedHardwareServiceClient in code that requires HardwareServiceClient +// // and then make assertions. +// +// } +type HardwareServiceClientMock struct { + // AllFunc mocks the All method. + AllFunc func(ctx context.Context, in *Empty, opts ...grpc.CallOption) (HardwareService_AllClient, error) + + // ByIDFunc mocks the ByID method. + ByIDFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) + + // ByIPFunc mocks the ByIP method. + ByIPFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) + + // ByMACFunc mocks the ByMAC method. + ByMACFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) + + // DeleteFunc mocks the Delete method. + DeleteFunc func(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*Empty, error) + + // DeprecatedWatchFunc mocks the DeprecatedWatch method. + DeprecatedWatchFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (HardwareService_DeprecatedWatchClient, error) + + // PushFunc mocks the Push method. + PushFunc func(ctx context.Context, in *PushRequest, opts ...grpc.CallOption) (*Empty, error) + + // calls tracks calls to the methods. + calls struct { + // All holds details about calls to the All method. + All []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *Empty + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ByID holds details about calls to the ByID method. + ByID []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ByIP holds details about calls to the ByIP method. + ByIP []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ByMAC holds details about calls to the ByMAC method. + ByMAC []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // Delete holds details about calls to the Delete method. + Delete []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *DeleteRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // DeprecatedWatch holds details about calls to the DeprecatedWatch method. + DeprecatedWatch []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // Push holds details about calls to the Push method. + Push []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *PushRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + } + lockAll sync.RWMutex + lockByID sync.RWMutex + lockByIP sync.RWMutex + lockByMAC sync.RWMutex + lockDelete sync.RWMutex + lockDeprecatedWatch sync.RWMutex + lockPush sync.RWMutex +} + +// All calls AllFunc. +func (mock *HardwareServiceClientMock) All(ctx context.Context, in *Empty, opts ...grpc.CallOption) (HardwareService_AllClient, error) { + if mock.AllFunc == nil { + panic("HardwareServiceClientMock.AllFunc: method is nil but HardwareServiceClient.All was just called") + } + callInfo := struct { + Ctx context.Context + In *Empty + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockAll.Lock() + mock.calls.All = append(mock.calls.All, callInfo) + mock.lockAll.Unlock() + return mock.AllFunc(ctx, in, opts...) +} + +// AllCalls gets all the calls that were made to All. +// Check the length with: +// len(mockedHardwareServiceClient.AllCalls()) +func (mock *HardwareServiceClientMock) AllCalls() []struct { + Ctx context.Context + In *Empty + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *Empty + Opts []grpc.CallOption + } + mock.lockAll.RLock() + calls = mock.calls.All + mock.lockAll.RUnlock() + return calls +} + +// ByID calls ByIDFunc. +func (mock *HardwareServiceClientMock) ByID(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) { + if mock.ByIDFunc == nil { + panic("HardwareServiceClientMock.ByIDFunc: method is nil but HardwareServiceClient.ByID was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockByID.Lock() + mock.calls.ByID = append(mock.calls.ByID, callInfo) + mock.lockByID.Unlock() + return mock.ByIDFunc(ctx, in, opts...) +} + +// ByIDCalls gets all the calls that were made to ByID. +// Check the length with: +// len(mockedHardwareServiceClient.ByIDCalls()) +func (mock *HardwareServiceClientMock) ByIDCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockByID.RLock() + calls = mock.calls.ByID + mock.lockByID.RUnlock() + return calls +} + +// ByIP calls ByIPFunc. +func (mock *HardwareServiceClientMock) ByIP(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) { + if mock.ByIPFunc == nil { + panic("HardwareServiceClientMock.ByIPFunc: method is nil but HardwareServiceClient.ByIP was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockByIP.Lock() + mock.calls.ByIP = append(mock.calls.ByIP, callInfo) + mock.lockByIP.Unlock() + return mock.ByIPFunc(ctx, in, opts...) +} + +// ByIPCalls gets all the calls that were made to ByIP. +// Check the length with: +// len(mockedHardwareServiceClient.ByIPCalls()) +func (mock *HardwareServiceClientMock) ByIPCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockByIP.RLock() + calls = mock.calls.ByIP + mock.lockByIP.RUnlock() + return calls +} + +// ByMAC calls ByMACFunc. +func (mock *HardwareServiceClientMock) ByMAC(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Hardware, error) { + if mock.ByMACFunc == nil { + panic("HardwareServiceClientMock.ByMACFunc: method is nil but HardwareServiceClient.ByMAC was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockByMAC.Lock() + mock.calls.ByMAC = append(mock.calls.ByMAC, callInfo) + mock.lockByMAC.Unlock() + return mock.ByMACFunc(ctx, in, opts...) +} + +// ByMACCalls gets all the calls that were made to ByMAC. +// Check the length with: +// len(mockedHardwareServiceClient.ByMACCalls()) +func (mock *HardwareServiceClientMock) ByMACCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockByMAC.RLock() + calls = mock.calls.ByMAC + mock.lockByMAC.RUnlock() + return calls +} + +// Delete calls DeleteFunc. +func (mock *HardwareServiceClientMock) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*Empty, error) { + if mock.DeleteFunc == nil { + panic("HardwareServiceClientMock.DeleteFunc: method is nil but HardwareServiceClient.Delete was just called") + } + callInfo := struct { + Ctx context.Context + In *DeleteRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockDelete.Lock() + mock.calls.Delete = append(mock.calls.Delete, callInfo) + mock.lockDelete.Unlock() + return mock.DeleteFunc(ctx, in, opts...) +} + +// DeleteCalls gets all the calls that were made to Delete. +// Check the length with: +// len(mockedHardwareServiceClient.DeleteCalls()) +func (mock *HardwareServiceClientMock) DeleteCalls() []struct { + Ctx context.Context + In *DeleteRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *DeleteRequest + Opts []grpc.CallOption + } + mock.lockDelete.RLock() + calls = mock.calls.Delete + mock.lockDelete.RUnlock() + return calls +} + +// DeprecatedWatch calls DeprecatedWatchFunc. +func (mock *HardwareServiceClientMock) DeprecatedWatch(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (HardwareService_DeprecatedWatchClient, error) { + if mock.DeprecatedWatchFunc == nil { + panic("HardwareServiceClientMock.DeprecatedWatchFunc: method is nil but HardwareServiceClient.DeprecatedWatch was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockDeprecatedWatch.Lock() + mock.calls.DeprecatedWatch = append(mock.calls.DeprecatedWatch, callInfo) + mock.lockDeprecatedWatch.Unlock() + return mock.DeprecatedWatchFunc(ctx, in, opts...) +} + +// DeprecatedWatchCalls gets all the calls that were made to DeprecatedWatch. +// Check the length with: +// len(mockedHardwareServiceClient.DeprecatedWatchCalls()) +func (mock *HardwareServiceClientMock) DeprecatedWatchCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockDeprecatedWatch.RLock() + calls = mock.calls.DeprecatedWatch + mock.lockDeprecatedWatch.RUnlock() + return calls +} + +// Push calls PushFunc. +func (mock *HardwareServiceClientMock) Push(ctx context.Context, in *PushRequest, opts ...grpc.CallOption) (*Empty, error) { + if mock.PushFunc == nil { + panic("HardwareServiceClientMock.PushFunc: method is nil but HardwareServiceClient.Push was just called") + } + callInfo := struct { + Ctx context.Context + In *PushRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockPush.Lock() + mock.calls.Push = append(mock.calls.Push, callInfo) + mock.lockPush.Unlock() + return mock.PushFunc(ctx, in, opts...) +} + +// PushCalls gets all the calls that were made to Push. +// Check the length with: +// len(mockedHardwareServiceClient.PushCalls()) +func (mock *HardwareServiceClientMock) PushCalls() []struct { + Ctx context.Context + In *PushRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *PushRequest + Opts []grpc.CallOption + } + mock.lockPush.RLock() + calls = mock.calls.Push + mock.lockPush.RUnlock() + return calls +} + +// Ensure, that HardwareService_AllClientMock does implement HardwareService_AllClient. +// If this is not the case, regenerate this file with moq. +var _ HardwareService_AllClient = &HardwareService_AllClientMock{} + +// HardwareService_AllClientMock is a mock implementation of HardwareService_AllClient. +// +// func TestSomethingThatUsesHardwareService_AllClient(t *testing.T) { +// +// // make and configure a mocked HardwareService_AllClient +// mockedHardwareService_AllClient := &HardwareService_AllClientMock{ +// CloseSendFunc: func() error { +// panic("mock out the CloseSend method") +// }, +// ContextFunc: func() context.Context { +// panic("mock out the Context method") +// }, +// HeaderFunc: func() (metadata.MD, error) { +// panic("mock out the Header method") +// }, +// RecvFunc: func() (*Hardware, error) { +// panic("mock out the Recv method") +// }, +// RecvMsgFunc: func(m interface{}) error { +// panic("mock out the RecvMsg method") +// }, +// SendMsgFunc: func(m interface{}) error { +// panic("mock out the SendMsg method") +// }, +// TrailerFunc: func() metadata.MD { +// panic("mock out the Trailer method") +// }, +// } +// +// // use mockedHardwareService_AllClient in code that requires HardwareService_AllClient +// // and then make assertions. +// +// } +type HardwareService_AllClientMock struct { + // CloseSendFunc mocks the CloseSend method. + CloseSendFunc func() error + + // ContextFunc mocks the Context method. + ContextFunc func() context.Context + + // HeaderFunc mocks the Header method. + HeaderFunc func() (metadata.MD, error) + + // RecvFunc mocks the Recv method. + RecvFunc func() (*Hardware, error) + + // RecvMsgFunc mocks the RecvMsg method. + RecvMsgFunc func(m interface{}) error + + // SendMsgFunc mocks the SendMsg method. + SendMsgFunc func(m interface{}) error + + // TrailerFunc mocks the Trailer method. + TrailerFunc func() metadata.MD + + // calls tracks calls to the methods. + calls struct { + // CloseSend holds details about calls to the CloseSend method. + CloseSend []struct { + } + // Context holds details about calls to the Context method. + Context []struct { + } + // Header holds details about calls to the Header method. + Header []struct { + } + // Recv holds details about calls to the Recv method. + Recv []struct { + } + // RecvMsg holds details about calls to the RecvMsg method. + RecvMsg []struct { + // M is the m argument value. + M interface{} + } + // SendMsg holds details about calls to the SendMsg method. + SendMsg []struct { + // M is the m argument value. + M interface{} + } + // Trailer holds details about calls to the Trailer method. + Trailer []struct { + } + } + lockCloseSend sync.RWMutex + lockContext sync.RWMutex + lockHeader sync.RWMutex + lockRecv sync.RWMutex + lockRecvMsg sync.RWMutex + lockSendMsg sync.RWMutex + lockTrailer sync.RWMutex +} + +// CloseSend calls CloseSendFunc. +func (mock *HardwareService_AllClientMock) CloseSend() error { + if mock.CloseSendFunc == nil { + panic("HardwareService_AllClientMock.CloseSendFunc: method is nil but HardwareService_AllClient.CloseSend was just called") + } + callInfo := struct { + }{} + mock.lockCloseSend.Lock() + mock.calls.CloseSend = append(mock.calls.CloseSend, callInfo) + mock.lockCloseSend.Unlock() + return mock.CloseSendFunc() +} + +// CloseSendCalls gets all the calls that were made to CloseSend. +// Check the length with: +// len(mockedHardwareService_AllClient.CloseSendCalls()) +func (mock *HardwareService_AllClientMock) CloseSendCalls() []struct { +} { + var calls []struct { + } + mock.lockCloseSend.RLock() + calls = mock.calls.CloseSend + mock.lockCloseSend.RUnlock() + return calls +} + +// Context calls ContextFunc. +func (mock *HardwareService_AllClientMock) Context() context.Context { + if mock.ContextFunc == nil { + panic("HardwareService_AllClientMock.ContextFunc: method is nil but HardwareService_AllClient.Context was just called") + } + callInfo := struct { + }{} + mock.lockContext.Lock() + mock.calls.Context = append(mock.calls.Context, callInfo) + mock.lockContext.Unlock() + return mock.ContextFunc() +} + +// ContextCalls gets all the calls that were made to Context. +// Check the length with: +// len(mockedHardwareService_AllClient.ContextCalls()) +func (mock *HardwareService_AllClientMock) ContextCalls() []struct { +} { + var calls []struct { + } + mock.lockContext.RLock() + calls = mock.calls.Context + mock.lockContext.RUnlock() + return calls +} + +// Header calls HeaderFunc. +func (mock *HardwareService_AllClientMock) Header() (metadata.MD, error) { + if mock.HeaderFunc == nil { + panic("HardwareService_AllClientMock.HeaderFunc: method is nil but HardwareService_AllClient.Header was just called") + } + callInfo := struct { + }{} + mock.lockHeader.Lock() + mock.calls.Header = append(mock.calls.Header, callInfo) + mock.lockHeader.Unlock() + return mock.HeaderFunc() +} + +// HeaderCalls gets all the calls that were made to Header. +// Check the length with: +// len(mockedHardwareService_AllClient.HeaderCalls()) +func (mock *HardwareService_AllClientMock) HeaderCalls() []struct { +} { + var calls []struct { + } + mock.lockHeader.RLock() + calls = mock.calls.Header + mock.lockHeader.RUnlock() + return calls +} + +// Recv calls RecvFunc. +func (mock *HardwareService_AllClientMock) Recv() (*Hardware, error) { + if mock.RecvFunc == nil { + panic("HardwareService_AllClientMock.RecvFunc: method is nil but HardwareService_AllClient.Recv was just called") + } + callInfo := struct { + }{} + mock.lockRecv.Lock() + mock.calls.Recv = append(mock.calls.Recv, callInfo) + mock.lockRecv.Unlock() + return mock.RecvFunc() +} + +// RecvCalls gets all the calls that were made to Recv. +// Check the length with: +// len(mockedHardwareService_AllClient.RecvCalls()) +func (mock *HardwareService_AllClientMock) RecvCalls() []struct { +} { + var calls []struct { + } + mock.lockRecv.RLock() + calls = mock.calls.Recv + mock.lockRecv.RUnlock() + return calls +} + +// RecvMsg calls RecvMsgFunc. +func (mock *HardwareService_AllClientMock) RecvMsg(m interface{}) error { + if mock.RecvMsgFunc == nil { + panic("HardwareService_AllClientMock.RecvMsgFunc: method is nil but HardwareService_AllClient.RecvMsg was just called") + } + callInfo := struct { + M interface{} + }{ + M: m, + } + mock.lockRecvMsg.Lock() + mock.calls.RecvMsg = append(mock.calls.RecvMsg, callInfo) + mock.lockRecvMsg.Unlock() + return mock.RecvMsgFunc(m) +} + +// RecvMsgCalls gets all the calls that were made to RecvMsg. +// Check the length with: +// len(mockedHardwareService_AllClient.RecvMsgCalls()) +func (mock *HardwareService_AllClientMock) RecvMsgCalls() []struct { + M interface{} +} { + var calls []struct { + M interface{} + } + mock.lockRecvMsg.RLock() + calls = mock.calls.RecvMsg + mock.lockRecvMsg.RUnlock() + return calls +} + +// SendMsg calls SendMsgFunc. +func (mock *HardwareService_AllClientMock) SendMsg(m interface{}) error { + if mock.SendMsgFunc == nil { + panic("HardwareService_AllClientMock.SendMsgFunc: method is nil but HardwareService_AllClient.SendMsg was just called") + } + callInfo := struct { + M interface{} + }{ + M: m, + } + mock.lockSendMsg.Lock() + mock.calls.SendMsg = append(mock.calls.SendMsg, callInfo) + mock.lockSendMsg.Unlock() + return mock.SendMsgFunc(m) +} + +// SendMsgCalls gets all the calls that were made to SendMsg. +// Check the length with: +// len(mockedHardwareService_AllClient.SendMsgCalls()) +func (mock *HardwareService_AllClientMock) SendMsgCalls() []struct { + M interface{} +} { + var calls []struct { + M interface{} + } + mock.lockSendMsg.RLock() + calls = mock.calls.SendMsg + mock.lockSendMsg.RUnlock() + return calls +} + +// Trailer calls TrailerFunc. +func (mock *HardwareService_AllClientMock) Trailer() metadata.MD { + if mock.TrailerFunc == nil { + panic("HardwareService_AllClientMock.TrailerFunc: method is nil but HardwareService_AllClient.Trailer was just called") + } + callInfo := struct { + }{} + mock.lockTrailer.Lock() + mock.calls.Trailer = append(mock.calls.Trailer, callInfo) + mock.lockTrailer.Unlock() + return mock.TrailerFunc() +} + +// TrailerCalls gets all the calls that were made to Trailer. +// Check the length with: +// len(mockedHardwareService_AllClient.TrailerCalls()) +func (mock *HardwareService_AllClientMock) TrailerCalls() []struct { +} { + var calls []struct { + } + mock.lockTrailer.RLock() + calls = mock.calls.Trailer + mock.lockTrailer.RUnlock() + return calls +} diff --git a/protos/template/gen.go b/protos/template/gen.go new file mode 100644 index 000000000..e4011339d --- /dev/null +++ b/protos/template/gen.go @@ -0,0 +1,3 @@ +package template + +//go:generate moq -out mock.go . TemplateServiceClient TemplateService_ListTemplatesClient diff --git a/protos/template/mock.go b/protos/template/mock.go new file mode 100644 index 000000000..a44d26e73 --- /dev/null +++ b/protos/template/mock.go @@ -0,0 +1,597 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package template + +import ( + "context" + "sync" + + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +// Ensure, that TemplateServiceClientMock does implement TemplateServiceClient. +// If this is not the case, regenerate this file with moq. +var _ TemplateServiceClient = &TemplateServiceClientMock{} + +// TemplateServiceClientMock is a mock implementation of TemplateServiceClient. +// +// func TestSomethingThatUsesTemplateServiceClient(t *testing.T) { +// +// // make and configure a mocked TemplateServiceClient +// mockedTemplateServiceClient := &TemplateServiceClientMock{ +// CreateTemplateFunc: func(ctx context.Context, in *WorkflowTemplate, opts ...grpc.CallOption) (*CreateResponse, error) { +// panic("mock out the CreateTemplate method") +// }, +// DeleteTemplateFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the DeleteTemplate method") +// }, +// GetTemplateFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*WorkflowTemplate, error) { +// panic("mock out the GetTemplate method") +// }, +// ListTemplatesFunc: func(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (TemplateService_ListTemplatesClient, error) { +// panic("mock out the ListTemplates method") +// }, +// UpdateTemplateFunc: func(ctx context.Context, in *WorkflowTemplate, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the UpdateTemplate method") +// }, +// } +// +// // use mockedTemplateServiceClient in code that requires TemplateServiceClient +// // and then make assertions. +// +// } +type TemplateServiceClientMock struct { + // CreateTemplateFunc mocks the CreateTemplate method. + CreateTemplateFunc func(ctx context.Context, in *WorkflowTemplate, opts ...grpc.CallOption) (*CreateResponse, error) + + // DeleteTemplateFunc mocks the DeleteTemplate method. + DeleteTemplateFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Empty, error) + + // GetTemplateFunc mocks the GetTemplate method. + GetTemplateFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*WorkflowTemplate, error) + + // ListTemplatesFunc mocks the ListTemplates method. + ListTemplatesFunc func(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (TemplateService_ListTemplatesClient, error) + + // UpdateTemplateFunc mocks the UpdateTemplate method. + UpdateTemplateFunc func(ctx context.Context, in *WorkflowTemplate, opts ...grpc.CallOption) (*Empty, error) + + // calls tracks calls to the methods. + calls struct { + // CreateTemplate holds details about calls to the CreateTemplate method. + CreateTemplate []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *WorkflowTemplate + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // DeleteTemplate holds details about calls to the DeleteTemplate method. + DeleteTemplate []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetTemplate holds details about calls to the GetTemplate method. + GetTemplate []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ListTemplates holds details about calls to the ListTemplates method. + ListTemplates []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *ListRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // UpdateTemplate holds details about calls to the UpdateTemplate method. + UpdateTemplate []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *WorkflowTemplate + // Opts is the opts argument value. + Opts []grpc.CallOption + } + } + lockCreateTemplate sync.RWMutex + lockDeleteTemplate sync.RWMutex + lockGetTemplate sync.RWMutex + lockListTemplates sync.RWMutex + lockUpdateTemplate sync.RWMutex +} + +// CreateTemplate calls CreateTemplateFunc. +func (mock *TemplateServiceClientMock) CreateTemplate(ctx context.Context, in *WorkflowTemplate, opts ...grpc.CallOption) (*CreateResponse, error) { + if mock.CreateTemplateFunc == nil { + panic("TemplateServiceClientMock.CreateTemplateFunc: method is nil but TemplateServiceClient.CreateTemplate was just called") + } + callInfo := struct { + Ctx context.Context + In *WorkflowTemplate + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockCreateTemplate.Lock() + mock.calls.CreateTemplate = append(mock.calls.CreateTemplate, callInfo) + mock.lockCreateTemplate.Unlock() + return mock.CreateTemplateFunc(ctx, in, opts...) +} + +// CreateTemplateCalls gets all the calls that were made to CreateTemplate. +// Check the length with: +// len(mockedTemplateServiceClient.CreateTemplateCalls()) +func (mock *TemplateServiceClientMock) CreateTemplateCalls() []struct { + Ctx context.Context + In *WorkflowTemplate + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *WorkflowTemplate + Opts []grpc.CallOption + } + mock.lockCreateTemplate.RLock() + calls = mock.calls.CreateTemplate + mock.lockCreateTemplate.RUnlock() + return calls +} + +// DeleteTemplate calls DeleteTemplateFunc. +func (mock *TemplateServiceClientMock) DeleteTemplate(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Empty, error) { + if mock.DeleteTemplateFunc == nil { + panic("TemplateServiceClientMock.DeleteTemplateFunc: method is nil but TemplateServiceClient.DeleteTemplate was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockDeleteTemplate.Lock() + mock.calls.DeleteTemplate = append(mock.calls.DeleteTemplate, callInfo) + mock.lockDeleteTemplate.Unlock() + return mock.DeleteTemplateFunc(ctx, in, opts...) +} + +// DeleteTemplateCalls gets all the calls that were made to DeleteTemplate. +// Check the length with: +// len(mockedTemplateServiceClient.DeleteTemplateCalls()) +func (mock *TemplateServiceClientMock) DeleteTemplateCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockDeleteTemplate.RLock() + calls = mock.calls.DeleteTemplate + mock.lockDeleteTemplate.RUnlock() + return calls +} + +// GetTemplate calls GetTemplateFunc. +func (mock *TemplateServiceClientMock) GetTemplate(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*WorkflowTemplate, error) { + if mock.GetTemplateFunc == nil { + panic("TemplateServiceClientMock.GetTemplateFunc: method is nil but TemplateServiceClient.GetTemplate was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetTemplate.Lock() + mock.calls.GetTemplate = append(mock.calls.GetTemplate, callInfo) + mock.lockGetTemplate.Unlock() + return mock.GetTemplateFunc(ctx, in, opts...) +} + +// GetTemplateCalls gets all the calls that were made to GetTemplate. +// Check the length with: +// len(mockedTemplateServiceClient.GetTemplateCalls()) +func (mock *TemplateServiceClientMock) GetTemplateCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockGetTemplate.RLock() + calls = mock.calls.GetTemplate + mock.lockGetTemplate.RUnlock() + return calls +} + +// ListTemplates calls ListTemplatesFunc. +func (mock *TemplateServiceClientMock) ListTemplates(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (TemplateService_ListTemplatesClient, error) { + if mock.ListTemplatesFunc == nil { + panic("TemplateServiceClientMock.ListTemplatesFunc: method is nil but TemplateServiceClient.ListTemplates was just called") + } + callInfo := struct { + Ctx context.Context + In *ListRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockListTemplates.Lock() + mock.calls.ListTemplates = append(mock.calls.ListTemplates, callInfo) + mock.lockListTemplates.Unlock() + return mock.ListTemplatesFunc(ctx, in, opts...) +} + +// ListTemplatesCalls gets all the calls that were made to ListTemplates. +// Check the length with: +// len(mockedTemplateServiceClient.ListTemplatesCalls()) +func (mock *TemplateServiceClientMock) ListTemplatesCalls() []struct { + Ctx context.Context + In *ListRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *ListRequest + Opts []grpc.CallOption + } + mock.lockListTemplates.RLock() + calls = mock.calls.ListTemplates + mock.lockListTemplates.RUnlock() + return calls +} + +// UpdateTemplate calls UpdateTemplateFunc. +func (mock *TemplateServiceClientMock) UpdateTemplate(ctx context.Context, in *WorkflowTemplate, opts ...grpc.CallOption) (*Empty, error) { + if mock.UpdateTemplateFunc == nil { + panic("TemplateServiceClientMock.UpdateTemplateFunc: method is nil but TemplateServiceClient.UpdateTemplate was just called") + } + callInfo := struct { + Ctx context.Context + In *WorkflowTemplate + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockUpdateTemplate.Lock() + mock.calls.UpdateTemplate = append(mock.calls.UpdateTemplate, callInfo) + mock.lockUpdateTemplate.Unlock() + return mock.UpdateTemplateFunc(ctx, in, opts...) +} + +// UpdateTemplateCalls gets all the calls that were made to UpdateTemplate. +// Check the length with: +// len(mockedTemplateServiceClient.UpdateTemplateCalls()) +func (mock *TemplateServiceClientMock) UpdateTemplateCalls() []struct { + Ctx context.Context + In *WorkflowTemplate + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *WorkflowTemplate + Opts []grpc.CallOption + } + mock.lockUpdateTemplate.RLock() + calls = mock.calls.UpdateTemplate + mock.lockUpdateTemplate.RUnlock() + return calls +} + +// Ensure, that TemplateService_ListTemplatesClientMock does implement TemplateService_ListTemplatesClient. +// If this is not the case, regenerate this file with moq. +var _ TemplateService_ListTemplatesClient = &TemplateService_ListTemplatesClientMock{} + +// TemplateService_ListTemplatesClientMock is a mock implementation of TemplateService_ListTemplatesClient. +// +// func TestSomethingThatUsesTemplateService_ListTemplatesClient(t *testing.T) { +// +// // make and configure a mocked TemplateService_ListTemplatesClient +// mockedTemplateService_ListTemplatesClient := &TemplateService_ListTemplatesClientMock{ +// CloseSendFunc: func() error { +// panic("mock out the CloseSend method") +// }, +// ContextFunc: func() context.Context { +// panic("mock out the Context method") +// }, +// HeaderFunc: func() (metadata.MD, error) { +// panic("mock out the Header method") +// }, +// RecvFunc: func() (*WorkflowTemplate, error) { +// panic("mock out the Recv method") +// }, +// RecvMsgFunc: func(m interface{}) error { +// panic("mock out the RecvMsg method") +// }, +// SendMsgFunc: func(m interface{}) error { +// panic("mock out the SendMsg method") +// }, +// TrailerFunc: func() metadata.MD { +// panic("mock out the Trailer method") +// }, +// } +// +// // use mockedTemplateService_ListTemplatesClient in code that requires TemplateService_ListTemplatesClient +// // and then make assertions. +// +// } +type TemplateService_ListTemplatesClientMock struct { + // CloseSendFunc mocks the CloseSend method. + CloseSendFunc func() error + + // ContextFunc mocks the Context method. + ContextFunc func() context.Context + + // HeaderFunc mocks the Header method. + HeaderFunc func() (metadata.MD, error) + + // RecvFunc mocks the Recv method. + RecvFunc func() (*WorkflowTemplate, error) + + // RecvMsgFunc mocks the RecvMsg method. + RecvMsgFunc func(m interface{}) error + + // SendMsgFunc mocks the SendMsg method. + SendMsgFunc func(m interface{}) error + + // TrailerFunc mocks the Trailer method. + TrailerFunc func() metadata.MD + + // calls tracks calls to the methods. + calls struct { + // CloseSend holds details about calls to the CloseSend method. + CloseSend []struct { + } + // Context holds details about calls to the Context method. + Context []struct { + } + // Header holds details about calls to the Header method. + Header []struct { + } + // Recv holds details about calls to the Recv method. + Recv []struct { + } + // RecvMsg holds details about calls to the RecvMsg method. + RecvMsg []struct { + // M is the m argument value. + M interface{} + } + // SendMsg holds details about calls to the SendMsg method. + SendMsg []struct { + // M is the m argument value. + M interface{} + } + // Trailer holds details about calls to the Trailer method. + Trailer []struct { + } + } + lockCloseSend sync.RWMutex + lockContext sync.RWMutex + lockHeader sync.RWMutex + lockRecv sync.RWMutex + lockRecvMsg sync.RWMutex + lockSendMsg sync.RWMutex + lockTrailer sync.RWMutex +} + +// CloseSend calls CloseSendFunc. +func (mock *TemplateService_ListTemplatesClientMock) CloseSend() error { + if mock.CloseSendFunc == nil { + panic("TemplateService_ListTemplatesClientMock.CloseSendFunc: method is nil but TemplateService_ListTemplatesClient.CloseSend was just called") + } + callInfo := struct { + }{} + mock.lockCloseSend.Lock() + mock.calls.CloseSend = append(mock.calls.CloseSend, callInfo) + mock.lockCloseSend.Unlock() + return mock.CloseSendFunc() +} + +// CloseSendCalls gets all the calls that were made to CloseSend. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.CloseSendCalls()) +func (mock *TemplateService_ListTemplatesClientMock) CloseSendCalls() []struct { +} { + var calls []struct { + } + mock.lockCloseSend.RLock() + calls = mock.calls.CloseSend + mock.lockCloseSend.RUnlock() + return calls +} + +// Context calls ContextFunc. +func (mock *TemplateService_ListTemplatesClientMock) Context() context.Context { + if mock.ContextFunc == nil { + panic("TemplateService_ListTemplatesClientMock.ContextFunc: method is nil but TemplateService_ListTemplatesClient.Context was just called") + } + callInfo := struct { + }{} + mock.lockContext.Lock() + mock.calls.Context = append(mock.calls.Context, callInfo) + mock.lockContext.Unlock() + return mock.ContextFunc() +} + +// ContextCalls gets all the calls that were made to Context. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.ContextCalls()) +func (mock *TemplateService_ListTemplatesClientMock) ContextCalls() []struct { +} { + var calls []struct { + } + mock.lockContext.RLock() + calls = mock.calls.Context + mock.lockContext.RUnlock() + return calls +} + +// Header calls HeaderFunc. +func (mock *TemplateService_ListTemplatesClientMock) Header() (metadata.MD, error) { + if mock.HeaderFunc == nil { + panic("TemplateService_ListTemplatesClientMock.HeaderFunc: method is nil but TemplateService_ListTemplatesClient.Header was just called") + } + callInfo := struct { + }{} + mock.lockHeader.Lock() + mock.calls.Header = append(mock.calls.Header, callInfo) + mock.lockHeader.Unlock() + return mock.HeaderFunc() +} + +// HeaderCalls gets all the calls that were made to Header. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.HeaderCalls()) +func (mock *TemplateService_ListTemplatesClientMock) HeaderCalls() []struct { +} { + var calls []struct { + } + mock.lockHeader.RLock() + calls = mock.calls.Header + mock.lockHeader.RUnlock() + return calls +} + +// Recv calls RecvFunc. +func (mock *TemplateService_ListTemplatesClientMock) Recv() (*WorkflowTemplate, error) { + if mock.RecvFunc == nil { + panic("TemplateService_ListTemplatesClientMock.RecvFunc: method is nil but TemplateService_ListTemplatesClient.Recv was just called") + } + callInfo := struct { + }{} + mock.lockRecv.Lock() + mock.calls.Recv = append(mock.calls.Recv, callInfo) + mock.lockRecv.Unlock() + return mock.RecvFunc() +} + +// RecvCalls gets all the calls that were made to Recv. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.RecvCalls()) +func (mock *TemplateService_ListTemplatesClientMock) RecvCalls() []struct { +} { + var calls []struct { + } + mock.lockRecv.RLock() + calls = mock.calls.Recv + mock.lockRecv.RUnlock() + return calls +} + +// RecvMsg calls RecvMsgFunc. +func (mock *TemplateService_ListTemplatesClientMock) RecvMsg(m interface{}) error { + if mock.RecvMsgFunc == nil { + panic("TemplateService_ListTemplatesClientMock.RecvMsgFunc: method is nil but TemplateService_ListTemplatesClient.RecvMsg was just called") + } + callInfo := struct { + M interface{} + }{ + M: m, + } + mock.lockRecvMsg.Lock() + mock.calls.RecvMsg = append(mock.calls.RecvMsg, callInfo) + mock.lockRecvMsg.Unlock() + return mock.RecvMsgFunc(m) +} + +// RecvMsgCalls gets all the calls that were made to RecvMsg. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.RecvMsgCalls()) +func (mock *TemplateService_ListTemplatesClientMock) RecvMsgCalls() []struct { + M interface{} +} { + var calls []struct { + M interface{} + } + mock.lockRecvMsg.RLock() + calls = mock.calls.RecvMsg + mock.lockRecvMsg.RUnlock() + return calls +} + +// SendMsg calls SendMsgFunc. +func (mock *TemplateService_ListTemplatesClientMock) SendMsg(m interface{}) error { + if mock.SendMsgFunc == nil { + panic("TemplateService_ListTemplatesClientMock.SendMsgFunc: method is nil but TemplateService_ListTemplatesClient.SendMsg was just called") + } + callInfo := struct { + M interface{} + }{ + M: m, + } + mock.lockSendMsg.Lock() + mock.calls.SendMsg = append(mock.calls.SendMsg, callInfo) + mock.lockSendMsg.Unlock() + return mock.SendMsgFunc(m) +} + +// SendMsgCalls gets all the calls that were made to SendMsg. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.SendMsgCalls()) +func (mock *TemplateService_ListTemplatesClientMock) SendMsgCalls() []struct { + M interface{} +} { + var calls []struct { + M interface{} + } + mock.lockSendMsg.RLock() + calls = mock.calls.SendMsg + mock.lockSendMsg.RUnlock() + return calls +} + +// Trailer calls TrailerFunc. +func (mock *TemplateService_ListTemplatesClientMock) Trailer() metadata.MD { + if mock.TrailerFunc == nil { + panic("TemplateService_ListTemplatesClientMock.TrailerFunc: method is nil but TemplateService_ListTemplatesClient.Trailer was just called") + } + callInfo := struct { + }{} + mock.lockTrailer.Lock() + mock.calls.Trailer = append(mock.calls.Trailer, callInfo) + mock.lockTrailer.Unlock() + return mock.TrailerFunc() +} + +// TrailerCalls gets all the calls that were made to Trailer. +// Check the length with: +// len(mockedTemplateService_ListTemplatesClient.TrailerCalls()) +func (mock *TemplateService_ListTemplatesClientMock) TrailerCalls() []struct { +} { + var calls []struct { + } + mock.lockTrailer.RLock() + calls = mock.calls.Trailer + mock.lockTrailer.RUnlock() + return calls +} diff --git a/protos/workflow/gen.go b/protos/workflow/gen.go new file mode 100644 index 000000000..d2ecb4870 --- /dev/null +++ b/protos/workflow/gen.go @@ -0,0 +1,3 @@ +package workflow + +//go:generate moq -out mock.go . WorkflowServiceClient WorkflowService_ListWorkflowsClient diff --git a/protos/workflow/mock.go b/protos/workflow/mock.go new file mode 100644 index 000000000..7481db188 --- /dev/null +++ b/protos/workflow/mock.go @@ -0,0 +1,1092 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package workflow + +import ( + "context" + "sync" + + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +// Ensure, that WorkflowServiceClientMock does implement WorkflowServiceClient. +// If this is not the case, regenerate this file with moq. +var _ WorkflowServiceClient = &WorkflowServiceClientMock{} + +// WorkflowServiceClientMock is a mock implementation of WorkflowServiceClient. +// +// func TestSomethingThatUsesWorkflowServiceClient(t *testing.T) { +// +// // make and configure a mocked WorkflowServiceClient +// mockedWorkflowServiceClient := &WorkflowServiceClientMock{ +// CreateWorkflowFunc: func(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { +// panic("mock out the CreateWorkflow method") +// }, +// DeleteWorkflowFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the DeleteWorkflow method") +// }, +// GetWorkflowFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Workflow, error) { +// panic("mock out the GetWorkflow method") +// }, +// GetWorkflowActionsFunc: func(ctx context.Context, in *WorkflowActionsRequest, opts ...grpc.CallOption) (*WorkflowActionList, error) { +// panic("mock out the GetWorkflowActions method") +// }, +// GetWorkflowContextFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*WorkflowContext, error) { +// panic("mock out the GetWorkflowContext method") +// }, +// GetWorkflowContextListFunc: func(ctx context.Context, in *WorkflowContextRequest, opts ...grpc.CallOption) (*WorkflowContextList, error) { +// panic("mock out the GetWorkflowContextList method") +// }, +// GetWorkflowContextsFunc: func(ctx context.Context, in *WorkflowContextRequest, opts ...grpc.CallOption) (WorkflowService_GetWorkflowContextsClient, error) { +// panic("mock out the GetWorkflowContexts method") +// }, +// GetWorkflowDataFunc: func(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) { +// panic("mock out the GetWorkflowData method") +// }, +// GetWorkflowDataVersionFunc: func(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) { +// panic("mock out the GetWorkflowDataVersion method") +// }, +// GetWorkflowMetadataFunc: func(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) { +// panic("mock out the GetWorkflowMetadata method") +// }, +// ListWorkflowsFunc: func(ctx context.Context, in *Empty, opts ...grpc.CallOption) (WorkflowService_ListWorkflowsClient, error) { +// panic("mock out the ListWorkflows method") +// }, +// ReportActionStatusFunc: func(ctx context.Context, in *WorkflowActionStatus, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the ReportActionStatus method") +// }, +// ShowWorkflowEventsFunc: func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (WorkflowService_ShowWorkflowEventsClient, error) { +// panic("mock out the ShowWorkflowEvents method") +// }, +// UpdateWorkflowDataFunc: func(ctx context.Context, in *UpdateWorkflowDataRequest, opts ...grpc.CallOption) (*Empty, error) { +// panic("mock out the UpdateWorkflowData method") +// }, +// } +// +// // use mockedWorkflowServiceClient in code that requires WorkflowServiceClient +// // and then make assertions. +// +// } +type WorkflowServiceClientMock struct { + // CreateWorkflowFunc mocks the CreateWorkflow method. + CreateWorkflowFunc func(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) + + // DeleteWorkflowFunc mocks the DeleteWorkflow method. + DeleteWorkflowFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Empty, error) + + // GetWorkflowFunc mocks the GetWorkflow method. + GetWorkflowFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Workflow, error) + + // GetWorkflowActionsFunc mocks the GetWorkflowActions method. + GetWorkflowActionsFunc func(ctx context.Context, in *WorkflowActionsRequest, opts ...grpc.CallOption) (*WorkflowActionList, error) + + // GetWorkflowContextFunc mocks the GetWorkflowContext method. + GetWorkflowContextFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*WorkflowContext, error) + + // GetWorkflowContextListFunc mocks the GetWorkflowContextList method. + GetWorkflowContextListFunc func(ctx context.Context, in *WorkflowContextRequest, opts ...grpc.CallOption) (*WorkflowContextList, error) + + // GetWorkflowContextsFunc mocks the GetWorkflowContexts method. + GetWorkflowContextsFunc func(ctx context.Context, in *WorkflowContextRequest, opts ...grpc.CallOption) (WorkflowService_GetWorkflowContextsClient, error) + + // GetWorkflowDataFunc mocks the GetWorkflowData method. + GetWorkflowDataFunc func(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) + + // GetWorkflowDataVersionFunc mocks the GetWorkflowDataVersion method. + GetWorkflowDataVersionFunc func(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) + + // GetWorkflowMetadataFunc mocks the GetWorkflowMetadata method. + GetWorkflowMetadataFunc func(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) + + // ListWorkflowsFunc mocks the ListWorkflows method. + ListWorkflowsFunc func(ctx context.Context, in *Empty, opts ...grpc.CallOption) (WorkflowService_ListWorkflowsClient, error) + + // ReportActionStatusFunc mocks the ReportActionStatus method. + ReportActionStatusFunc func(ctx context.Context, in *WorkflowActionStatus, opts ...grpc.CallOption) (*Empty, error) + + // ShowWorkflowEventsFunc mocks the ShowWorkflowEvents method. + ShowWorkflowEventsFunc func(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (WorkflowService_ShowWorkflowEventsClient, error) + + // UpdateWorkflowDataFunc mocks the UpdateWorkflowData method. + UpdateWorkflowDataFunc func(ctx context.Context, in *UpdateWorkflowDataRequest, opts ...grpc.CallOption) (*Empty, error) + + // calls tracks calls to the methods. + calls struct { + // CreateWorkflow holds details about calls to the CreateWorkflow method. + CreateWorkflow []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *CreateRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // DeleteWorkflow holds details about calls to the DeleteWorkflow method. + DeleteWorkflow []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflow holds details about calls to the GetWorkflow method. + GetWorkflow []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowActions holds details about calls to the GetWorkflowActions method. + GetWorkflowActions []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *WorkflowActionsRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowContext holds details about calls to the GetWorkflowContext method. + GetWorkflowContext []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowContextList holds details about calls to the GetWorkflowContextList method. + GetWorkflowContextList []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *WorkflowContextRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowContexts holds details about calls to the GetWorkflowContexts method. + GetWorkflowContexts []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *WorkflowContextRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowData holds details about calls to the GetWorkflowData method. + GetWorkflowData []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetWorkflowDataRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowDataVersion holds details about calls to the GetWorkflowDataVersion method. + GetWorkflowDataVersion []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetWorkflowDataRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // GetWorkflowMetadata holds details about calls to the GetWorkflowMetadata method. + GetWorkflowMetadata []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetWorkflowDataRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ListWorkflows holds details about calls to the ListWorkflows method. + ListWorkflows []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *Empty + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ReportActionStatus holds details about calls to the ReportActionStatus method. + ReportActionStatus []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *WorkflowActionStatus + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // ShowWorkflowEvents holds details about calls to the ShowWorkflowEvents method. + ShowWorkflowEvents []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *GetRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + // UpdateWorkflowData holds details about calls to the UpdateWorkflowData method. + UpdateWorkflowData []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // In is the in argument value. + In *UpdateWorkflowDataRequest + // Opts is the opts argument value. + Opts []grpc.CallOption + } + } + lockCreateWorkflow sync.RWMutex + lockDeleteWorkflow sync.RWMutex + lockGetWorkflow sync.RWMutex + lockGetWorkflowActions sync.RWMutex + lockGetWorkflowContext sync.RWMutex + lockGetWorkflowContextList sync.RWMutex + lockGetWorkflowContexts sync.RWMutex + lockGetWorkflowData sync.RWMutex + lockGetWorkflowDataVersion sync.RWMutex + lockGetWorkflowMetadata sync.RWMutex + lockListWorkflows sync.RWMutex + lockReportActionStatus sync.RWMutex + lockShowWorkflowEvents sync.RWMutex + lockUpdateWorkflowData sync.RWMutex +} + +// CreateWorkflow calls CreateWorkflowFunc. +func (mock *WorkflowServiceClientMock) CreateWorkflow(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) { + if mock.CreateWorkflowFunc == nil { + panic("WorkflowServiceClientMock.CreateWorkflowFunc: method is nil but WorkflowServiceClient.CreateWorkflow was just called") + } + callInfo := struct { + Ctx context.Context + In *CreateRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockCreateWorkflow.Lock() + mock.calls.CreateWorkflow = append(mock.calls.CreateWorkflow, callInfo) + mock.lockCreateWorkflow.Unlock() + return mock.CreateWorkflowFunc(ctx, in, opts...) +} + +// CreateWorkflowCalls gets all the calls that were made to CreateWorkflow. +// Check the length with: +// len(mockedWorkflowServiceClient.CreateWorkflowCalls()) +func (mock *WorkflowServiceClientMock) CreateWorkflowCalls() []struct { + Ctx context.Context + In *CreateRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *CreateRequest + Opts []grpc.CallOption + } + mock.lockCreateWorkflow.RLock() + calls = mock.calls.CreateWorkflow + mock.lockCreateWorkflow.RUnlock() + return calls +} + +// DeleteWorkflow calls DeleteWorkflowFunc. +func (mock *WorkflowServiceClientMock) DeleteWorkflow(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Empty, error) { + if mock.DeleteWorkflowFunc == nil { + panic("WorkflowServiceClientMock.DeleteWorkflowFunc: method is nil but WorkflowServiceClient.DeleteWorkflow was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockDeleteWorkflow.Lock() + mock.calls.DeleteWorkflow = append(mock.calls.DeleteWorkflow, callInfo) + mock.lockDeleteWorkflow.Unlock() + return mock.DeleteWorkflowFunc(ctx, in, opts...) +} + +// DeleteWorkflowCalls gets all the calls that were made to DeleteWorkflow. +// Check the length with: +// len(mockedWorkflowServiceClient.DeleteWorkflowCalls()) +func (mock *WorkflowServiceClientMock) DeleteWorkflowCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockDeleteWorkflow.RLock() + calls = mock.calls.DeleteWorkflow + mock.lockDeleteWorkflow.RUnlock() + return calls +} + +// GetWorkflow calls GetWorkflowFunc. +func (mock *WorkflowServiceClientMock) GetWorkflow(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*Workflow, error) { + if mock.GetWorkflowFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowFunc: method is nil but WorkflowServiceClient.GetWorkflow was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflow.Lock() + mock.calls.GetWorkflow = append(mock.calls.GetWorkflow, callInfo) + mock.lockGetWorkflow.Unlock() + return mock.GetWorkflowFunc(ctx, in, opts...) +} + +// GetWorkflowCalls gets all the calls that were made to GetWorkflow. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflow.RLock() + calls = mock.calls.GetWorkflow + mock.lockGetWorkflow.RUnlock() + return calls +} + +// GetWorkflowActions calls GetWorkflowActionsFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowActions(ctx context.Context, in *WorkflowActionsRequest, opts ...grpc.CallOption) (*WorkflowActionList, error) { + if mock.GetWorkflowActionsFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowActionsFunc: method is nil but WorkflowServiceClient.GetWorkflowActions was just called") + } + callInfo := struct { + Ctx context.Context + In *WorkflowActionsRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowActions.Lock() + mock.calls.GetWorkflowActions = append(mock.calls.GetWorkflowActions, callInfo) + mock.lockGetWorkflowActions.Unlock() + return mock.GetWorkflowActionsFunc(ctx, in, opts...) +} + +// GetWorkflowActionsCalls gets all the calls that were made to GetWorkflowActions. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowActionsCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowActionsCalls() []struct { + Ctx context.Context + In *WorkflowActionsRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *WorkflowActionsRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowActions.RLock() + calls = mock.calls.GetWorkflowActions + mock.lockGetWorkflowActions.RUnlock() + return calls +} + +// GetWorkflowContext calls GetWorkflowContextFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowContext(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*WorkflowContext, error) { + if mock.GetWorkflowContextFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowContextFunc: method is nil but WorkflowServiceClient.GetWorkflowContext was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowContext.Lock() + mock.calls.GetWorkflowContext = append(mock.calls.GetWorkflowContext, callInfo) + mock.lockGetWorkflowContext.Unlock() + return mock.GetWorkflowContextFunc(ctx, in, opts...) +} + +// GetWorkflowContextCalls gets all the calls that were made to GetWorkflowContext. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowContextCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowContextCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowContext.RLock() + calls = mock.calls.GetWorkflowContext + mock.lockGetWorkflowContext.RUnlock() + return calls +} + +// GetWorkflowContextList calls GetWorkflowContextListFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowContextList(ctx context.Context, in *WorkflowContextRequest, opts ...grpc.CallOption) (*WorkflowContextList, error) { + if mock.GetWorkflowContextListFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowContextListFunc: method is nil but WorkflowServiceClient.GetWorkflowContextList was just called") + } + callInfo := struct { + Ctx context.Context + In *WorkflowContextRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowContextList.Lock() + mock.calls.GetWorkflowContextList = append(mock.calls.GetWorkflowContextList, callInfo) + mock.lockGetWorkflowContextList.Unlock() + return mock.GetWorkflowContextListFunc(ctx, in, opts...) +} + +// GetWorkflowContextListCalls gets all the calls that were made to GetWorkflowContextList. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowContextListCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowContextListCalls() []struct { + Ctx context.Context + In *WorkflowContextRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *WorkflowContextRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowContextList.RLock() + calls = mock.calls.GetWorkflowContextList + mock.lockGetWorkflowContextList.RUnlock() + return calls +} + +// GetWorkflowContexts calls GetWorkflowContextsFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowContexts(ctx context.Context, in *WorkflowContextRequest, opts ...grpc.CallOption) (WorkflowService_GetWorkflowContextsClient, error) { + if mock.GetWorkflowContextsFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowContextsFunc: method is nil but WorkflowServiceClient.GetWorkflowContexts was just called") + } + callInfo := struct { + Ctx context.Context + In *WorkflowContextRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowContexts.Lock() + mock.calls.GetWorkflowContexts = append(mock.calls.GetWorkflowContexts, callInfo) + mock.lockGetWorkflowContexts.Unlock() + return mock.GetWorkflowContextsFunc(ctx, in, opts...) +} + +// GetWorkflowContextsCalls gets all the calls that were made to GetWorkflowContexts. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowContextsCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowContextsCalls() []struct { + Ctx context.Context + In *WorkflowContextRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *WorkflowContextRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowContexts.RLock() + calls = mock.calls.GetWorkflowContexts + mock.lockGetWorkflowContexts.RUnlock() + return calls +} + +// GetWorkflowData calls GetWorkflowDataFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowData(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) { + if mock.GetWorkflowDataFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowDataFunc: method is nil but WorkflowServiceClient.GetWorkflowData was just called") + } + callInfo := struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowData.Lock() + mock.calls.GetWorkflowData = append(mock.calls.GetWorkflowData, callInfo) + mock.lockGetWorkflowData.Unlock() + return mock.GetWorkflowDataFunc(ctx, in, opts...) +} + +// GetWorkflowDataCalls gets all the calls that were made to GetWorkflowData. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowDataCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowDataCalls() []struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowData.RLock() + calls = mock.calls.GetWorkflowData + mock.lockGetWorkflowData.RUnlock() + return calls +} + +// GetWorkflowDataVersion calls GetWorkflowDataVersionFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowDataVersion(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) { + if mock.GetWorkflowDataVersionFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowDataVersionFunc: method is nil but WorkflowServiceClient.GetWorkflowDataVersion was just called") + } + callInfo := struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowDataVersion.Lock() + mock.calls.GetWorkflowDataVersion = append(mock.calls.GetWorkflowDataVersion, callInfo) + mock.lockGetWorkflowDataVersion.Unlock() + return mock.GetWorkflowDataVersionFunc(ctx, in, opts...) +} + +// GetWorkflowDataVersionCalls gets all the calls that were made to GetWorkflowDataVersion. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowDataVersionCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowDataVersionCalls() []struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowDataVersion.RLock() + calls = mock.calls.GetWorkflowDataVersion + mock.lockGetWorkflowDataVersion.RUnlock() + return calls +} + +// GetWorkflowMetadata calls GetWorkflowMetadataFunc. +func (mock *WorkflowServiceClientMock) GetWorkflowMetadata(ctx context.Context, in *GetWorkflowDataRequest, opts ...grpc.CallOption) (*GetWorkflowDataResponse, error) { + if mock.GetWorkflowMetadataFunc == nil { + panic("WorkflowServiceClientMock.GetWorkflowMetadataFunc: method is nil but WorkflowServiceClient.GetWorkflowMetadata was just called") + } + callInfo := struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockGetWorkflowMetadata.Lock() + mock.calls.GetWorkflowMetadata = append(mock.calls.GetWorkflowMetadata, callInfo) + mock.lockGetWorkflowMetadata.Unlock() + return mock.GetWorkflowMetadataFunc(ctx, in, opts...) +} + +// GetWorkflowMetadataCalls gets all the calls that were made to GetWorkflowMetadata. +// Check the length with: +// len(mockedWorkflowServiceClient.GetWorkflowMetadataCalls()) +func (mock *WorkflowServiceClientMock) GetWorkflowMetadataCalls() []struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetWorkflowDataRequest + Opts []grpc.CallOption + } + mock.lockGetWorkflowMetadata.RLock() + calls = mock.calls.GetWorkflowMetadata + mock.lockGetWorkflowMetadata.RUnlock() + return calls +} + +// ListWorkflows calls ListWorkflowsFunc. +func (mock *WorkflowServiceClientMock) ListWorkflows(ctx context.Context, in *Empty, opts ...grpc.CallOption) (WorkflowService_ListWorkflowsClient, error) { + if mock.ListWorkflowsFunc == nil { + panic("WorkflowServiceClientMock.ListWorkflowsFunc: method is nil but WorkflowServiceClient.ListWorkflows was just called") + } + callInfo := struct { + Ctx context.Context + In *Empty + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockListWorkflows.Lock() + mock.calls.ListWorkflows = append(mock.calls.ListWorkflows, callInfo) + mock.lockListWorkflows.Unlock() + return mock.ListWorkflowsFunc(ctx, in, opts...) +} + +// ListWorkflowsCalls gets all the calls that were made to ListWorkflows. +// Check the length with: +// len(mockedWorkflowServiceClient.ListWorkflowsCalls()) +func (mock *WorkflowServiceClientMock) ListWorkflowsCalls() []struct { + Ctx context.Context + In *Empty + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *Empty + Opts []grpc.CallOption + } + mock.lockListWorkflows.RLock() + calls = mock.calls.ListWorkflows + mock.lockListWorkflows.RUnlock() + return calls +} + +// ReportActionStatus calls ReportActionStatusFunc. +func (mock *WorkflowServiceClientMock) ReportActionStatus(ctx context.Context, in *WorkflowActionStatus, opts ...grpc.CallOption) (*Empty, error) { + if mock.ReportActionStatusFunc == nil { + panic("WorkflowServiceClientMock.ReportActionStatusFunc: method is nil but WorkflowServiceClient.ReportActionStatus was just called") + } + callInfo := struct { + Ctx context.Context + In *WorkflowActionStatus + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockReportActionStatus.Lock() + mock.calls.ReportActionStatus = append(mock.calls.ReportActionStatus, callInfo) + mock.lockReportActionStatus.Unlock() + return mock.ReportActionStatusFunc(ctx, in, opts...) +} + +// ReportActionStatusCalls gets all the calls that were made to ReportActionStatus. +// Check the length with: +// len(mockedWorkflowServiceClient.ReportActionStatusCalls()) +func (mock *WorkflowServiceClientMock) ReportActionStatusCalls() []struct { + Ctx context.Context + In *WorkflowActionStatus + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *WorkflowActionStatus + Opts []grpc.CallOption + } + mock.lockReportActionStatus.RLock() + calls = mock.calls.ReportActionStatus + mock.lockReportActionStatus.RUnlock() + return calls +} + +// ShowWorkflowEvents calls ShowWorkflowEventsFunc. +func (mock *WorkflowServiceClientMock) ShowWorkflowEvents(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (WorkflowService_ShowWorkflowEventsClient, error) { + if mock.ShowWorkflowEventsFunc == nil { + panic("WorkflowServiceClientMock.ShowWorkflowEventsFunc: method is nil but WorkflowServiceClient.ShowWorkflowEvents was just called") + } + callInfo := struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockShowWorkflowEvents.Lock() + mock.calls.ShowWorkflowEvents = append(mock.calls.ShowWorkflowEvents, callInfo) + mock.lockShowWorkflowEvents.Unlock() + return mock.ShowWorkflowEventsFunc(ctx, in, opts...) +} + +// ShowWorkflowEventsCalls gets all the calls that were made to ShowWorkflowEvents. +// Check the length with: +// len(mockedWorkflowServiceClient.ShowWorkflowEventsCalls()) +func (mock *WorkflowServiceClientMock) ShowWorkflowEventsCalls() []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *GetRequest + Opts []grpc.CallOption + } + mock.lockShowWorkflowEvents.RLock() + calls = mock.calls.ShowWorkflowEvents + mock.lockShowWorkflowEvents.RUnlock() + return calls +} + +// UpdateWorkflowData calls UpdateWorkflowDataFunc. +func (mock *WorkflowServiceClientMock) UpdateWorkflowData(ctx context.Context, in *UpdateWorkflowDataRequest, opts ...grpc.CallOption) (*Empty, error) { + if mock.UpdateWorkflowDataFunc == nil { + panic("WorkflowServiceClientMock.UpdateWorkflowDataFunc: method is nil but WorkflowServiceClient.UpdateWorkflowData was just called") + } + callInfo := struct { + Ctx context.Context + In *UpdateWorkflowDataRequest + Opts []grpc.CallOption + }{ + Ctx: ctx, + In: in, + Opts: opts, + } + mock.lockUpdateWorkflowData.Lock() + mock.calls.UpdateWorkflowData = append(mock.calls.UpdateWorkflowData, callInfo) + mock.lockUpdateWorkflowData.Unlock() + return mock.UpdateWorkflowDataFunc(ctx, in, opts...) +} + +// UpdateWorkflowDataCalls gets all the calls that were made to UpdateWorkflowData. +// Check the length with: +// len(mockedWorkflowServiceClient.UpdateWorkflowDataCalls()) +func (mock *WorkflowServiceClientMock) UpdateWorkflowDataCalls() []struct { + Ctx context.Context + In *UpdateWorkflowDataRequest + Opts []grpc.CallOption +} { + var calls []struct { + Ctx context.Context + In *UpdateWorkflowDataRequest + Opts []grpc.CallOption + } + mock.lockUpdateWorkflowData.RLock() + calls = mock.calls.UpdateWorkflowData + mock.lockUpdateWorkflowData.RUnlock() + return calls +} + +// Ensure, that WorkflowService_ListWorkflowsClientMock does implement WorkflowService_ListWorkflowsClient. +// If this is not the case, regenerate this file with moq. +var _ WorkflowService_ListWorkflowsClient = &WorkflowService_ListWorkflowsClientMock{} + +// WorkflowService_ListWorkflowsClientMock is a mock implementation of WorkflowService_ListWorkflowsClient. +// +// func TestSomethingThatUsesWorkflowService_ListWorkflowsClient(t *testing.T) { +// +// // make and configure a mocked WorkflowService_ListWorkflowsClient +// mockedWorkflowService_ListWorkflowsClient := &WorkflowService_ListWorkflowsClientMock{ +// CloseSendFunc: func() error { +// panic("mock out the CloseSend method") +// }, +// ContextFunc: func() context.Context { +// panic("mock out the Context method") +// }, +// HeaderFunc: func() (metadata.MD, error) { +// panic("mock out the Header method") +// }, +// RecvFunc: func() (*Workflow, error) { +// panic("mock out the Recv method") +// }, +// RecvMsgFunc: func(m interface{}) error { +// panic("mock out the RecvMsg method") +// }, +// SendMsgFunc: func(m interface{}) error { +// panic("mock out the SendMsg method") +// }, +// TrailerFunc: func() metadata.MD { +// panic("mock out the Trailer method") +// }, +// } +// +// // use mockedWorkflowService_ListWorkflowsClient in code that requires WorkflowService_ListWorkflowsClient +// // and then make assertions. +// +// } +type WorkflowService_ListWorkflowsClientMock struct { + // CloseSendFunc mocks the CloseSend method. + CloseSendFunc func() error + + // ContextFunc mocks the Context method. + ContextFunc func() context.Context + + // HeaderFunc mocks the Header method. + HeaderFunc func() (metadata.MD, error) + + // RecvFunc mocks the Recv method. + RecvFunc func() (*Workflow, error) + + // RecvMsgFunc mocks the RecvMsg method. + RecvMsgFunc func(m interface{}) error + + // SendMsgFunc mocks the SendMsg method. + SendMsgFunc func(m interface{}) error + + // TrailerFunc mocks the Trailer method. + TrailerFunc func() metadata.MD + + // calls tracks calls to the methods. + calls struct { + // CloseSend holds details about calls to the CloseSend method. + CloseSend []struct { + } + // Context holds details about calls to the Context method. + Context []struct { + } + // Header holds details about calls to the Header method. + Header []struct { + } + // Recv holds details about calls to the Recv method. + Recv []struct { + } + // RecvMsg holds details about calls to the RecvMsg method. + RecvMsg []struct { + // M is the m argument value. + M interface{} + } + // SendMsg holds details about calls to the SendMsg method. + SendMsg []struct { + // M is the m argument value. + M interface{} + } + // Trailer holds details about calls to the Trailer method. + Trailer []struct { + } + } + lockCloseSend sync.RWMutex + lockContext sync.RWMutex + lockHeader sync.RWMutex + lockRecv sync.RWMutex + lockRecvMsg sync.RWMutex + lockSendMsg sync.RWMutex + lockTrailer sync.RWMutex +} + +// CloseSend calls CloseSendFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) CloseSend() error { + if mock.CloseSendFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.CloseSendFunc: method is nil but WorkflowService_ListWorkflowsClient.CloseSend was just called") + } + callInfo := struct { + }{} + mock.lockCloseSend.Lock() + mock.calls.CloseSend = append(mock.calls.CloseSend, callInfo) + mock.lockCloseSend.Unlock() + return mock.CloseSendFunc() +} + +// CloseSendCalls gets all the calls that were made to CloseSend. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.CloseSendCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) CloseSendCalls() []struct { +} { + var calls []struct { + } + mock.lockCloseSend.RLock() + calls = mock.calls.CloseSend + mock.lockCloseSend.RUnlock() + return calls +} + +// Context calls ContextFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) Context() context.Context { + if mock.ContextFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.ContextFunc: method is nil but WorkflowService_ListWorkflowsClient.Context was just called") + } + callInfo := struct { + }{} + mock.lockContext.Lock() + mock.calls.Context = append(mock.calls.Context, callInfo) + mock.lockContext.Unlock() + return mock.ContextFunc() +} + +// ContextCalls gets all the calls that were made to Context. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.ContextCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) ContextCalls() []struct { +} { + var calls []struct { + } + mock.lockContext.RLock() + calls = mock.calls.Context + mock.lockContext.RUnlock() + return calls +} + +// Header calls HeaderFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) Header() (metadata.MD, error) { + if mock.HeaderFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.HeaderFunc: method is nil but WorkflowService_ListWorkflowsClient.Header was just called") + } + callInfo := struct { + }{} + mock.lockHeader.Lock() + mock.calls.Header = append(mock.calls.Header, callInfo) + mock.lockHeader.Unlock() + return mock.HeaderFunc() +} + +// HeaderCalls gets all the calls that were made to Header. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.HeaderCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) HeaderCalls() []struct { +} { + var calls []struct { + } + mock.lockHeader.RLock() + calls = mock.calls.Header + mock.lockHeader.RUnlock() + return calls +} + +// Recv calls RecvFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) Recv() (*Workflow, error) { + if mock.RecvFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.RecvFunc: method is nil but WorkflowService_ListWorkflowsClient.Recv was just called") + } + callInfo := struct { + }{} + mock.lockRecv.Lock() + mock.calls.Recv = append(mock.calls.Recv, callInfo) + mock.lockRecv.Unlock() + return mock.RecvFunc() +} + +// RecvCalls gets all the calls that were made to Recv. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.RecvCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) RecvCalls() []struct { +} { + var calls []struct { + } + mock.lockRecv.RLock() + calls = mock.calls.Recv + mock.lockRecv.RUnlock() + return calls +} + +// RecvMsg calls RecvMsgFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) RecvMsg(m interface{}) error { + if mock.RecvMsgFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.RecvMsgFunc: method is nil but WorkflowService_ListWorkflowsClient.RecvMsg was just called") + } + callInfo := struct { + M interface{} + }{ + M: m, + } + mock.lockRecvMsg.Lock() + mock.calls.RecvMsg = append(mock.calls.RecvMsg, callInfo) + mock.lockRecvMsg.Unlock() + return mock.RecvMsgFunc(m) +} + +// RecvMsgCalls gets all the calls that were made to RecvMsg. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.RecvMsgCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) RecvMsgCalls() []struct { + M interface{} +} { + var calls []struct { + M interface{} + } + mock.lockRecvMsg.RLock() + calls = mock.calls.RecvMsg + mock.lockRecvMsg.RUnlock() + return calls +} + +// SendMsg calls SendMsgFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) SendMsg(m interface{}) error { + if mock.SendMsgFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.SendMsgFunc: method is nil but WorkflowService_ListWorkflowsClient.SendMsg was just called") + } + callInfo := struct { + M interface{} + }{ + M: m, + } + mock.lockSendMsg.Lock() + mock.calls.SendMsg = append(mock.calls.SendMsg, callInfo) + mock.lockSendMsg.Unlock() + return mock.SendMsgFunc(m) +} + +// SendMsgCalls gets all the calls that were made to SendMsg. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.SendMsgCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) SendMsgCalls() []struct { + M interface{} +} { + var calls []struct { + M interface{} + } + mock.lockSendMsg.RLock() + calls = mock.calls.SendMsg + mock.lockSendMsg.RUnlock() + return calls +} + +// Trailer calls TrailerFunc. +func (mock *WorkflowService_ListWorkflowsClientMock) Trailer() metadata.MD { + if mock.TrailerFunc == nil { + panic("WorkflowService_ListWorkflowsClientMock.TrailerFunc: method is nil but WorkflowService_ListWorkflowsClient.Trailer was just called") + } + callInfo := struct { + }{} + mock.lockTrailer.Lock() + mock.calls.Trailer = append(mock.calls.Trailer, callInfo) + mock.lockTrailer.Unlock() + return mock.TrailerFunc() +} + +// TrailerCalls gets all the calls that were made to Trailer. +// Check the length with: +// len(mockedWorkflowService_ListWorkflowsClient.TrailerCalls()) +func (mock *WorkflowService_ListWorkflowsClientMock) TrailerCalls() []struct { +} { + var calls []struct { + } + mock.lockTrailer.RLock() + calls = mock.calls.Trailer + mock.lockTrailer.RUnlock() + return calls +}