Пример #1
0
func TestGetOrganizationReturnOrganizationIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)

	organizationService := OrganizationApi{
		configurationService: mockConfigurationService,
	}

	expectedOrganization := Organization{Id: TEST_ORGANIZATION_ID,
		Name:         TEST_ORGANIZATION_NAME,
		EntryPoint:   TEST_ORGANIZATION_ENTRYPOINT,
		Users:        TEST_ORGANIZATION_USERS,
		Environments: TEST_ORGANIZATION_ENVIRONMENTS,
		Roles:        TEST_ORGANIZATION_ROLES}

	mockConfigurationService.EXPECT().Get(TEST_ORGANIZATION_ID, gomock.Any()).Return(buildOrganizationJsonResponse(&expectedOrganization), nil)

	//when
	organization, _ := organizationService.Get(TEST_ORGANIZATION_ID)

	//then
	if assert.NotNil(t, organization) {
		assert.Equal(t, expectedOrganization, *organization)
	}
}
func TestListServiceConnectionReturnDiskOfferingsIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)

	serviceConnectionService := ServiceConnectionApi{
		configurationService: mockConfigurationService,
	}

	expectedServiceConnections := []ServiceConnection{
		ServiceConnection{
			Id:          "connection_1",
			Name:        "connection_name_1",
			ServiceCode: "connection_code_1",
		},
		ServiceConnection{
			Id:          "connection_2",
			Name:        "connection_name_2",
			ServiceCode: "connection_code_2",
		},
	}

	mockConfigurationService.EXPECT().List(gomock.Any()).Return(buildListServiceConnectionJsonResponse(expectedServiceConnections), nil)

	//when
	serviceConnections, _ := serviceConnectionService.List()

	//then
	if assert.NotNil(t, serviceConnections) {
		assert.Equal(t, expectedServiceConnections, serviceConnections)
	}
}
func TestGetServiceConnectionReturnServiceConnectionIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)

	serviceConnectionService := ServiceConnectionApi{
		configurationService: mockConfigurationService,
	}

	expectedServiceConnection := ServiceConnection{Id: TEST_SERVICE_CONNECTION_ID,
		Name:        TEST_SERVICE_CONNECTION_NAME,
		ServiceCode: TEST_SERVICE_CONNECTION_SERVICE_CODE}

	mockConfigurationService.EXPECT().Get(TEST_SERVICE_CONNECTION_ID, gomock.Any()).Return(buildServiceConnectionJsonResponse(&expectedServiceConnection), nil)

	//when
	serviceConnection, _ := serviceConnectionService.Get(TEST_SERVICE_CONNECTION_ID)

	//then
	if assert.NotNil(t, serviceConnection) {
		assert.Equal(t, expectedServiceConnection, *serviceConnection)
	}
}
Пример #4
0
func TestListOrganizationReturnDiskOfferingsIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)

	organizationService := OrganizationApi{
		configurationService: mockConfigurationService,
	}

	expectedOrganizations := []Organization{
		Organization{
			Id:           "org_id_1",
			Name:         "org_name_1",
			EntryPoint:   "org_entrypoint_1",
			Users:        []User{User{Id: "user1"}},
			Environments: []Environment{},
			Roles:        []Role{Role{Id: "test_role_1"}},
		},
		Organization{
			Id:           "org_id_2",
			Name:         "org_name_2",
			EntryPoint:   "org_entrypoint_2",
			Users:        []User{User{Id: "user2"}},
			Environments: []Environment{Environment{Id: "env1"}},
			Roles:        []Role{Role{Id: "test_role_2"}},
		},
	}

	mockConfigurationService.EXPECT().List(gomock.Any()).Return(buildListOrganizationJsonResponse(expectedOrganizations), nil)

	//when
	organizations, _ := organizationService.List()

	//then
	if assert.NotNil(t, organizations) {
		assert.Equal(t, expectedOrganizations, organizations)
	}
}
Пример #5
0
func TestGetOrganizationReturnNilWithErrorIfError(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)

	organizationService := OrganizationApi{
		configurationService: mockConfigurationService,
	}

	mockError := mocks.MockError{"some_get_error"}

	mockConfigurationService.EXPECT().Get(TEST_ORGANIZATION_ID, gomock.Any()).Return(nil, mockError)

	//when
	organization, err := organizationService.Get(TEST_ORGANIZATION_ID)

	//then
	assert.Nil(t, organization)
	assert.Equal(t, mockError, err)

}
Пример #6
0
func TestListOrganizationReturnNilWithErrorIfError(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)

	organizationService := OrganizationApi{
		configurationService: mockConfigurationService,
	}

	mockError := mocks.MockError{"some_list_error"}

	mockConfigurationService.EXPECT().List(gomock.Any()).Return(nil, mockError)

	//when
	organizations, err := organizationService.List()

	//then
	assert.Nil(t, organizations)
	assert.Equal(t, mockError, err)

}
Пример #7
0
func TestListEnvironmentReturnEnvironmentIfSuccess(t *testing.T) {
	//given
	ctrl := gomock.NewController(t)
	defer ctrl.Finish()

	mockConfigurationService := configuration_mocks.NewMockConfigurationService(ctrl)
	environmentService := EnvironmentApi{
		configurationService: mockConfigurationService,
	}

	response := `[{"id":"13ca7410-9b4a-4fd7-ae2e-e5455b664faf",
                 "name":"patdev1",
                 "description":"pat dev 1",
                 "membership":"MANY_USERS",
                 "serviceConnection":{"id":"73983e63-e404-48aa-a89c-f41ca93af9cd","category":"IAAS","name":"patDev1","serviceCode":"dev1","type":"CloudCA"},
                 "organization":{"id":"4b5e5c55-7aea-48e4-9287-d63b36457c51","entryPoint":"pat","name":"Test"},
                 "users":[{"id":"062445f9-11d3-4e7b-9a84-908272a72250","userName":"******"}],
                 "roles":[{"id":"32a25a1e-0506-429f-a731-e8fcaaa01c4d","users":[],"isDefault":false,"name":"Read-only"},
                          {"id":"517b40e5-20a8-44f0-a5d0-06ed20ee4d43","users":[{"id":"062445f9-11d3-4e7b-9a84-908272a72250","userName":"******"}],"isDefault":false,"name":"Environment Admin"}
                         ],
                 "deleted":false,
                 "version":5}]`

	expectedEnvironments := []Environment{
		Environment{
			Id:          "13ca7410-9b4a-4fd7-ae2e-e5455b664faf",
			Name:        "patdev1",
			Description: "pat dev 1",
			ServiceConnection: ServiceConnection{
				Id:          "73983e63-e404-48aa-a89c-f41ca93af9cd",
				Name:        "patDev1",
				ServiceCode: "dev1",
			},
			Organization: Organization{
				Id:         "4b5e5c55-7aea-48e4-9287-d63b36457c51",
				Name:       "Test",
				EntryPoint: "pat",
			},
			Users: []User{
				User{
					Id:       "062445f9-11d3-4e7b-9a84-908272a72250",
					Username: "******",
				},
			},
			Roles: []Role{
				Role{
					Id:    "32a25a1e-0506-429f-a731-e8fcaaa01c4d",
					Name:  "Read-only",
					Users: []User{},
				},
				Role{
					Id:   "517b40e5-20a8-44f0-a5d0-06ed20ee4d43",
					Name: "Environment Admin",
					Users: []User{
						User{
							Id:       "062445f9-11d3-4e7b-9a84-908272a72250",
							Username: "******",
						},
					},
				},
			},
		},
	}

	mockConfigurationService.EXPECT().List(gomock.Any()).Return([]byte(response), nil)

	//when
	environments, _ := environmentService.List()

	//then
	if assert.NotNil(t, environments) {
		assert.Equal(t, expectedEnvironments, environments)
	}
}