mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-10 04:21:26 +00:00
Unit tests
This commit is contained in:
@@ -910,7 +910,7 @@ func (cc *ConnClient) SourceDataDiscover(ctx context.Context, queryInput map[str
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cc.client.Post(ctx, connResourceUrl(cc.endpoint, cc.connectorRef, "invoke-direct"), "application/json", bytes.NewReader(cmdRaw))
|
resp, err := cc.client.Post(ctx, connResourceUrl(cc.endpoint), "application/json", bytes.NewReader(cmdRaw))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const (
|
|||||||
connectorsEndpoint = "/beta/platform-connectors"
|
connectorsEndpoint = "/beta/platform-connectors"
|
||||||
connectorInstancesEndpoint = "/beta/connector-instances"
|
connectorInstancesEndpoint = "/beta/connector-instances"
|
||||||
connectorCustomizersEndpoint = "/beta/connector-customizers"
|
connectorCustomizersEndpoint = "/beta/connector-customizers"
|
||||||
|
connectorRuntimeDirectExecuteEndpoint = "/sp-conn-runtime-exec/runtime-connector-invoke"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewConnCmd(term terminal.Terminal) *cobra.Command {
|
func NewConnCmd(term terminal.Terminal) *cobra.Command {
|
||||||
|
|||||||
@@ -102,6 +102,28 @@ func connClient(cmd *cobra.Command, spClient client.Client) (*connclient.ConnCli
|
|||||||
return cc, nil
|
return cc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func connRuntimeClient(cmd *cobra.Command, spClient client.Client) (*connclient.ConnClient, error) {
|
||||||
|
connectorRef := cmd.Flags().Lookup("id").Value.String()
|
||||||
|
version := cmd.Flags().Lookup("version").Value.String()
|
||||||
|
|
||||||
|
var v *int
|
||||||
|
if version != "" {
|
||||||
|
ver, err := strconv.Atoi(version)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
v = &ver
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, err := invokeConfig(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cc := connclient.NewConnClient(spClient, v, cfg, connectorRef, connectorRuntimeDirectExecuteEndpoint)
|
||||||
|
|
||||||
|
return cc, nil
|
||||||
|
}
|
||||||
|
|
||||||
func connClientWithCustomParams(spClient client.Client, cfg json.RawMessage, connectorID, version, endpoint string) (*connclient.ConnClient, error) {
|
func connClientWithCustomParams(spClient client.Client, cfg json.RawMessage, connectorID, version, endpoint string) (*connclient.ConnClient, error) {
|
||||||
v, err := strconv.Atoi(version)
|
v, err := strconv.Atoi(version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func newConnInvokeSourceDataDiscoverCmd(client client.Client) *cobra.Command {
|
|||||||
Args: cobra.RangeArgs(0, 1),
|
Args: cobra.RangeArgs(0, 1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
cc, err := connClient(cmd, client)
|
cc, err := connRuntimeClient(cmd, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
35
cmd/connector/conn_invoke_source_data_discover_test.go
Normal file
35
cmd/connector/conn_invoke_source_data_discover_test.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved.
|
||||||
|
package connector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/mocks"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSourceDataDiscoverWithoutInput(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:source-data:discover","config":{},"input":{"queryInput":{}}}`
|
||||||
|
|
||||||
|
client := mocks.NewMockClient(ctrl)
|
||||||
|
client.EXPECT().
|
||||||
|
Post(gomock.Any(), gomock.Any(), "application/json", bytes.NewReader([]byte(i))).
|
||||||
|
Return(&http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader([]byte("{}")))}, nil)
|
||||||
|
|
||||||
|
cmd := newConnInvokeSourceDataDiscoverCmd(client)
|
||||||
|
addRequiredFlagsFromParentCmd(cmd)
|
||||||
|
|
||||||
|
b := new(bytes.Buffer)
|
||||||
|
cmd.SetOut(b)
|
||||||
|
cmd.SetArgs([]string{"-c", "test-connector", "--config-json", "{}"})
|
||||||
|
|
||||||
|
err := cmd.Execute()
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("failed to detect error: reading source data discover")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ func newConnInvokeSourceDataReadCmd(client client.Client) *cobra.Command {
|
|||||||
Args: cobra.RangeArgs(1, 1),
|
Args: cobra.RangeArgs(1, 1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
cc, err := connClient(cmd, client)
|
cc, err := connRuntimeClient(cmd, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
35
cmd/connector/conn_invoke_source_data_read_test.go
Normal file
35
cmd/connector/conn_invoke_source_data_read_test.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved.
|
||||||
|
package connector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/sailpoint-oss/sailpoint-cli/internal/mocks"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSourceDataReadWithInput(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:source-data:read","config":{},"input":{"sourceDataKey":"john.doe","queryInput":{}}}`
|
||||||
|
|
||||||
|
client := mocks.NewMockClient(ctrl)
|
||||||
|
client.EXPECT().
|
||||||
|
Post(gomock.Any(), gomock.Any(), "application/json", bytes.NewReader([]byte(i))).
|
||||||
|
Return(&http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader([]byte("{}")))}, nil)
|
||||||
|
|
||||||
|
cmd := newConnInvokeSourceDataReadCmd(client)
|
||||||
|
addRequiredFlagsFromParentCmd(cmd)
|
||||||
|
|
||||||
|
b := new(bytes.Buffer)
|
||||||
|
cmd.SetOut(b)
|
||||||
|
cmd.SetArgs([]string{"john.doe", "-c", "test-connector", "--config-json", "{}"})
|
||||||
|
|
||||||
|
err := cmd.Execute()
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("failed to detect error: reading source data discover")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user