diff --git a/internal/auth0/flow.go b/internal/auth0/flow.go index 106085b9..ead68348 100644 --- a/internal/auth0/flow.go +++ b/internal/auth0/flow.go @@ -1,4 +1,4 @@ -//go:generate mockgen -source=flow.go -destination=flow/flow_mock.go -package=mock +//go:generate mockgen -source=flow.go -destination=mock/flow_mock.go -package=mock package auth0 diff --git a/internal/auth0/form.go b/internal/auth0/form.go index ec23c336..20d562b4 100644 --- a/internal/auth0/form.go +++ b/internal/auth0/form.go @@ -1,4 +1,4 @@ -//go:generate mockgen -source=form.go -destination=form/form_mock.go -package=mock +//go:generate mockgen -source=form.go -destination=mock/form_mock.go -package=mock package auth0 diff --git a/internal/auth0/mock/flow_mock.go b/internal/auth0/mock/flow_mock.go new file mode 100644 index 00000000..8a0e7c38 --- /dev/null +++ b/internal/auth0/mock/flow_mock.go @@ -0,0 +1,253 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: flow.go + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + management "github.com/auth0/go-auth0/management" + gomock "github.com/golang/mock/gomock" +) + +// MockFlowAPI is a mock of FlowAPI interface. +type MockFlowAPI struct { + ctrl *gomock.Controller + recorder *MockFlowAPIMockRecorder +} + +// MockFlowAPIMockRecorder is the mock recorder for MockFlowAPI. +type MockFlowAPIMockRecorder struct { + mock *MockFlowAPI +} + +// NewMockFlowAPI creates a new mock instance. +func NewMockFlowAPI(ctrl *gomock.Controller) *MockFlowAPI { + mock := &MockFlowAPI{ctrl: ctrl} + mock.recorder = &MockFlowAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFlowAPI) EXPECT() *MockFlowAPIMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockFlowAPI) Create(ctx context.Context, r *management.Flow, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Create", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Create indicates an expected call of Create. +func (mr *MockFlowAPIMockRecorder) Create(ctx, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFlowAPI)(nil).Create), varargs...) +} + +// Delete mocks base method. +func (m *MockFlowAPI) Delete(ctx context.Context, id string, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Delete", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockFlowAPIMockRecorder) Delete(ctx, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockFlowAPI)(nil).Delete), varargs...) +} + +// List mocks base method. +func (m *MockFlowAPI) List(ctx context.Context, opts ...management.RequestOption) (*management.FlowList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(*management.FlowList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockFlowAPIMockRecorder) List(ctx interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockFlowAPI)(nil).List), varargs...) +} + +// Read mocks base method. +func (m *MockFlowAPI) Read(ctx context.Context, id string, opts ...management.RequestOption) (*management.Flow, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Read", varargs...) + ret0, _ := ret[0].(*management.Flow) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockFlowAPIMockRecorder) Read(ctx, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockFlowAPI)(nil).Read), varargs...) +} + +// Update mocks base method. +func (m *MockFlowAPI) Update(ctx context.Context, id string, r *management.Flow, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Update", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Update indicates an expected call of Update. +func (mr *MockFlowAPIMockRecorder) Update(ctx, id, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockFlowAPI)(nil).Update), varargs...) +} + +// MockFlowVaultConnectionAPI is a mock of FlowVaultConnectionAPI interface. +type MockFlowVaultConnectionAPI struct { + ctrl *gomock.Controller + recorder *MockFlowVaultConnectionAPIMockRecorder +} + +// MockFlowVaultConnectionAPIMockRecorder is the mock recorder for MockFlowVaultConnectionAPI. +type MockFlowVaultConnectionAPIMockRecorder struct { + mock *MockFlowVaultConnectionAPI +} + +// NewMockFlowVaultConnectionAPI creates a new mock instance. +func NewMockFlowVaultConnectionAPI(ctrl *gomock.Controller) *MockFlowVaultConnectionAPI { + mock := &MockFlowVaultConnectionAPI{ctrl: ctrl} + mock.recorder = &MockFlowVaultConnectionAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFlowVaultConnectionAPI) EXPECT() *MockFlowVaultConnectionAPIMockRecorder { + return m.recorder +} + +// CreateConnection mocks base method. +func (m *MockFlowVaultConnectionAPI) CreateConnection(ctx context.Context, r *management.FlowVaultConnection, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "CreateConnection", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// CreateConnection indicates an expected call of CreateConnection. +func (mr *MockFlowVaultConnectionAPIMockRecorder) CreateConnection(ctx, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateConnection", reflect.TypeOf((*MockFlowVaultConnectionAPI)(nil).CreateConnection), varargs...) +} + +// DeleteConnection mocks base method. +func (m *MockFlowVaultConnectionAPI) DeleteConnection(ctx context.Context, id string, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "DeleteConnection", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteConnection indicates an expected call of DeleteConnection. +func (mr *MockFlowVaultConnectionAPIMockRecorder) DeleteConnection(ctx, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteConnection", reflect.TypeOf((*MockFlowVaultConnectionAPI)(nil).DeleteConnection), varargs...) +} + +// GetConnection mocks base method. +func (m *MockFlowVaultConnectionAPI) GetConnection(ctx context.Context, id string, opts ...management.RequestOption) (*management.FlowVaultConnection, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetConnection", varargs...) + ret0, _ := ret[0].(*management.FlowVaultConnection) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetConnection indicates an expected call of GetConnection. +func (mr *MockFlowVaultConnectionAPIMockRecorder) GetConnection(ctx, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConnection", reflect.TypeOf((*MockFlowVaultConnectionAPI)(nil).GetConnection), varargs...) +} + +// GetConnectionList mocks base method. +func (m *MockFlowVaultConnectionAPI) GetConnectionList(ctx context.Context, opts ...management.RequestOption) (*management.FlowVaultConnectionList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "GetConnectionList", varargs...) + ret0, _ := ret[0].(*management.FlowVaultConnectionList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetConnectionList indicates an expected call of GetConnectionList. +func (mr *MockFlowVaultConnectionAPIMockRecorder) GetConnectionList(ctx interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConnectionList", reflect.TypeOf((*MockFlowVaultConnectionAPI)(nil).GetConnectionList), varargs...) +} + +// UpdateConnection mocks base method. +func (m *MockFlowVaultConnectionAPI) UpdateConnection(ctx context.Context, id string, r *management.FlowVaultConnection, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "UpdateConnection", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpdateConnection indicates an expected call of UpdateConnection. +func (mr *MockFlowVaultConnectionAPIMockRecorder) UpdateConnection(ctx, id, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateConnection", reflect.TypeOf((*MockFlowVaultConnectionAPI)(nil).UpdateConnection), varargs...) +} diff --git a/internal/auth0/mock/form_mock.go b/internal/auth0/mock/form_mock.go new file mode 100644 index 00000000..73161402 --- /dev/null +++ b/internal/auth0/mock/form_mock.go @@ -0,0 +1,133 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: form.go + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + management "github.com/auth0/go-auth0/management" + gomock "github.com/golang/mock/gomock" +) + +// MockFormAPI is a mock of FormAPI interface. +type MockFormAPI struct { + ctrl *gomock.Controller + recorder *MockFormAPIMockRecorder +} + +// MockFormAPIMockRecorder is the mock recorder for MockFormAPI. +type MockFormAPIMockRecorder struct { + mock *MockFormAPI +} + +// NewMockFormAPI creates a new mock instance. +func NewMockFormAPI(ctrl *gomock.Controller) *MockFormAPI { + mock := &MockFormAPI{ctrl: ctrl} + mock.recorder = &MockFormAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockFormAPI) EXPECT() *MockFormAPIMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockFormAPI) Create(ctx context.Context, r *management.Form, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Create", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Create indicates an expected call of Create. +func (mr *MockFormAPIMockRecorder) Create(ctx, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockFormAPI)(nil).Create), varargs...) +} + +// Delete mocks base method. +func (m *MockFormAPI) Delete(ctx context.Context, id string, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Delete", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockFormAPIMockRecorder) Delete(ctx, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockFormAPI)(nil).Delete), varargs...) +} + +// List mocks base method. +func (m *MockFormAPI) List(ctx context.Context, opts ...management.RequestOption) (*management.FormList, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(*management.FormList) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// List indicates an expected call of List. +func (mr *MockFormAPIMockRecorder) List(ctx interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockFormAPI)(nil).List), varargs...) +} + +// Read mocks base method. +func (m *MockFormAPI) Read(ctx context.Context, id string, opts ...management.RequestOption) (*management.Form, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Read", varargs...) + ret0, _ := ret[0].(*management.Form) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockFormAPIMockRecorder) Read(ctx, id interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockFormAPI)(nil).Read), varargs...) +} + +// Update mocks base method. +func (m *MockFormAPI) Update(ctx context.Context, id string, r *management.Form, opts ...management.RequestOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx, id, r} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Update", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Update indicates an expected call of Update. +func (mr *MockFormAPIMockRecorder) Update(ctx, id, r interface{}, opts ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx, id, r}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockFormAPI)(nil).Update), varargs...) +} diff --git a/internal/cli/terraform_fetcher_test.go b/internal/cli/terraform_fetcher_test.go index 4466266e..aa793145 100644 --- a/internal/cli/terraform_fetcher_test.go +++ b/internal/cli/terraform_fetcher_test.go @@ -563,6 +563,153 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) { }) } +func TestFormResourceFetcher_FetchData(t *testing.T) { + t.Run("it successfully generates form import data", func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + formAPI := mock.NewMockFormAPI(ctrl) + formAPI.EXPECT(). + List(gomock.Any(), gomock.Any()).Return( + &management.FormList{ + List: management.List{ + Start: 0, + Limit: 1, + Total: 2, + }, + Forms: []*management.Form{ + { + ID: auth0.String("form_id1"), + Name: auth0.String("Form 1"), + }, + { + ID: auth0.String("form_id2"), + Name: auth0.String("Form 2"), + }, + }, + }, nil) + + fetcher := formResourceFetcher{ + api: &auth0.API{ + Form: formAPI, + }, + } + + expectedData := importDataList{ + { + ResourceName: "auth0_form.form_1", + ImportID: "form_id1", + }, + { + ResourceName: "auth0_form.form_2", + ImportID: "form_id2", + }, + } + + data, err := fetcher.FetchData(context.Background()) + assert.NoError(t, err) + assert.Equal(t, expectedData, data) + }) +} + +func TestFlowResourceFetcher_FetchData(t *testing.T) { + t.Run("it successfully generates form import data", func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + flowAPI := mock.NewMockFlowAPI(ctrl) + flowAPI.EXPECT(). + List(gomock.Any(), gomock.Any()).Return( + &management.FlowList{ + List: management.List{ + Start: 0, + Limit: 1, + Total: 2, + }, + Flows: []*management.Flow{ + { + ID: auth0.String("flow_id1"), + Name: auth0.String("Flow 1"), + }, + { + ID: auth0.String("flow_id2"), + Name: auth0.String("Flow 2"), + }, + }, + }, nil) + + fetcher := flowResourceFetcher{ + api: &auth0.API{ + Flow: flowAPI, + }, + } + + expectedData := importDataList{ + { + ResourceName: "auth0_flow.flow_1", + ImportID: "flow_id1", + }, + { + ResourceName: "auth0_flow.flow_2", + ImportID: "flow_id2", + }, + } + + data, err := fetcher.FetchData(context.Background()) + assert.NoError(t, err) + assert.Equal(t, expectedData, data) + }) +} + +func TestFlowVaultConnectionResourceFetcher_FetchData(t *testing.T) { + t.Run("it successfully generates form import data", func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + flowVaultAPI := mock.NewMockFlowVaultConnectionAPI(ctrl) + flowVaultAPI.EXPECT(). + GetConnectionList(gomock.Any()).Return( + &management.FlowVaultConnectionList{ + List: management.List{ + Start: 0, + Limit: 1, + Total: 2, + }, + Connections: []*management.FlowVaultConnection{ + { + ID: auth0.String("flow_vault_connection1"), + Name: auth0.String("Flow Vault Connection 1"), + }, + { + ID: auth0.String("flow_vault_connection2"), + Name: auth0.String("Flow Vault Connection 2"), + }, + }, + }, nil) + + fetcher := flowVaultConnectionResourceFetcher{ + api: &auth0.API{ + FlowVaultConnection: flowVaultAPI, + }, + } + + expectedData := importDataList{ + { + ResourceName: "auth0_flow_vault_connection.flow_vault_connection_1", + ImportID: "flow_vault_connection1", + }, + { + ResourceName: "auth0_flow_vault_connection.flow_vault_connection_2", + ImportID: "flow_vault_connection2", + }, + } + + data, err := fetcher.FetchData(context.Background()) + assert.NoError(t, err) + assert.Equal(t, expectedData, data) + }) +} + func TestGuardianResourceFetcher_FetchData(t *testing.T) { t.Run("it successfully generates pages guardian data", func(t *testing.T) { fetcher := guardianResourceFetcher{}