mirror of
https://github.com/LukeHagar/sailpoint-cli.git
synced 2025-12-09 20:57:44 +00:00
PLTCONN-2935: More unit tests
This commit is contained in:
84
cmd/connector/conn_invoke_account_create_test.go
Normal file
84
cmd/connector/conn_invoke_account_create_test.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// 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 TestAccountCreateWithoutInput(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:create","config":{},"input":{"identity":null,"attributes":{}}}`
|
||||
|
||||
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 := newConnInvokeAccountCreateCmd(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("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountCreateWithIdentity(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:create","config":{},"input":{"identity":"john.doe","attributes":{}}}`
|
||||
|
||||
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 := newConnInvokeAccountCreateCmd(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("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountCreateWithIdentityAndAttributes(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:create","config":{},"input":{"identity":"john.doe","attributes":{"foo":"bar"}}}`
|
||||
|
||||
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 := newConnInvokeAccountCreateCmd(client)
|
||||
addRequiredFlagsFromParentCmd(cmd)
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
cmd.SetOut(b)
|
||||
cmd.SetArgs([]string{"john.doe", "-c", "test-connector", "--config-json", "{}", "--attributes", `{"foo":"bar"}`})
|
||||
|
||||
err := cmd.Execute()
|
||||
if err != nil {
|
||||
t.Errorf("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
55
cmd/connector/conn_invoke_account_delete_test.go
Normal file
55
cmd/connector/conn_invoke_account_delete_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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 TestAccountDeleteWithoutInput(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
client := mocks.NewMockClient(ctrl)
|
||||
|
||||
cmd := newConnInvokeAccountDeleteCmd(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: deleting account without identity")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountDeleteWithIdentity(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:delete","config":{},"input":{"identity":"john.doe","key":{"simple":{"id":"john.doe"}}}}`
|
||||
|
||||
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 := newConnInvokeAccountDeleteCmd(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("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,11 @@ func TestAccountListWithoutInput(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
p := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:list","config":{},"input":{}}`
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:list","config":{},"input":{}}`
|
||||
|
||||
client := mocks.NewMockClient(ctrl)
|
||||
client.EXPECT().
|
||||
Post(gomock.Any(), gomock.Any(), "application/json", bytes.NewReader([]byte(p))).
|
||||
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 := newConnInvokeAccountListCmd(client)
|
||||
@@ -43,11 +43,11 @@ func TestAccountListWithState(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
p := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:list","config":{},"input":{"stateful":true,"stateId":"123"}}`
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:list","config":{},"input":{"stateful":true,"stateId":"123"}}`
|
||||
|
||||
client := mocks.NewMockClient(ctrl)
|
||||
client.EXPECT().
|
||||
Post(gomock.Any(), gomock.Any(), "application/json", bytes.NewReader([]byte(p))).
|
||||
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 := newConnInvokeAccountListCmd(client)
|
||||
@@ -68,7 +68,7 @@ func TestAccountListWithSchema(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
|
||||
schema := `{"attributes":[{"description":"The identity of the account","name":"identity","type":"string"}]}`
|
||||
p := fmt.Sprintf(`{"connectorRef":"test-connector","tag":"latest","type":"std:account:list","config":{},"input":{"schema":%s}}`, schema)
|
||||
i := fmt.Sprintf(`{"connectorRef":"test-connector","tag":"latest","type":"std:account:list","config":{},"input":{"schema":%s}}`, schema)
|
||||
|
||||
file, err := ioutil.TempFile("", "config.json")
|
||||
if err != nil {
|
||||
@@ -81,7 +81,7 @@ func TestAccountListWithSchema(t *testing.T) {
|
||||
|
||||
client := mocks.NewMockClient(ctrl)
|
||||
client.EXPECT().
|
||||
Post(gomock.Any(), gomock.Any(), "application/json", bytes.NewReader([]byte(p))).
|
||||
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 := newConnInvokeAccountListCmd(client)
|
||||
|
||||
55
cmd/connector/conn_invoke_account_read_test.go
Normal file
55
cmd/connector/conn_invoke_account_read_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// 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 TestAccountReadWithoutInput(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
client := mocks.NewMockClient(ctrl)
|
||||
|
||||
cmd := newConnInvokeAccountReadCmd(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 account without identity")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountReadWithIdentity(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:read","config":{},"input":{"identity":"john.doe","key":{"simple":{"id":"john.doe"}}}}`
|
||||
|
||||
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 := newConnInvokeAccountReadCmd(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("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
81
cmd/connector/conn_invoke_account_update_test.go
Normal file
81
cmd/connector/conn_invoke_account_update_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved.
|
||||
package connector
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/sailpoint-oss/sailpoint-cli/internal/mocks"
|
||||
)
|
||||
|
||||
func TestAccounUpdateWithoutInput(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
client := mocks.NewMockClient(ctrl)
|
||||
|
||||
cmd := newConnInvokeAccountUpdateCmd(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: updating account without identity")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountUpdateWithIdentity(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
i := `{"connectorRef":"test-connector","tag":"latest","type":"std:account:update","config":{},"input":{"identity":"john.doe","key":{"simple":{"id":"john.doe"}},"changes":[]}}`
|
||||
|
||||
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 := newConnInvokeAccountUpdateCmd(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("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountUpdateWithIdentityAndChanges(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
c := `[{"op":"Add","attribute":"location","value":"austin"}]`
|
||||
i := fmt.Sprintf(`{"connectorRef":"test-connector","tag":"latest","type":"std:account:update","config":{},"input":{"identity":"john.doe","key":{"simple":{"id":"john.doe"}},"changes":%s}}`, c)
|
||||
|
||||
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 := newConnInvokeAccountUpdateCmd(client)
|
||||
addRequiredFlagsFromParentCmd(cmd)
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
cmd.SetOut(b)
|
||||
cmd.SetArgs([]string{"john.doe", "-c", "test-connector", "--config-json", "{}", "--changes", c})
|
||||
|
||||
err := cmd.Execute()
|
||||
if err != nil {
|
||||
t.Errorf("command failed with err: %s", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user