Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgrade to Go 1.15 ([#77])
- Removed playbook.yml from project and replaced with ad-hoc command ([#79])
- Update default Steward version ([#82])
- Make the tenant GitRepo URL required ([#83])

## [v0.2.0] - 2020-07-23
### Changed
Expand Down Expand Up @@ -58,3 +59,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#71]: https://github.com/projectsyn/lieutenant-api/pull/71
[#77]: https://github.com/projectsyn/lieutenant-api/pull/77
[#82]: https://github.com/projectsyn/lieutenant-api/pull/82
[#83]: https://github.com/projectsyn/lieutenant-api/pull/83
4 changes: 1 addition & 3 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ paths:
The ID is generated by the API (in the form `t-<adjective>-<noun>-<digits>` where
all the words are lowercase, max 63 characters in total).
It generates the `Tenant` object in the configured namespace (usually the same namespace where the API runs).
The customer config Git repository (the `<GitRepoSpec>`) is automatically
generated based on default configuration or using the provided values.
If `gitRepo` is already set on creation, no `<GitRepoSpec>` will be added.
The customer config Git repository URL is required.
tags:
- tenant
requestBody:
Expand Down
117 changes: 58 additions & 59 deletions pkg/api/openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/service/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func (s *APIImpl) CreateTenant(c echo.Context) error {
if err := ctx.Bind(&newTenant); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
if newTenant.GitRepo == nil ||
newTenant.GitRepo.Url == nil ||
*newTenant.GitRepo.Url == "" {
return echo.NewHTTPError(http.StatusBadRequest, "GitRepo URL is required")
}
apiTenant := &api.Tenant{
TenantProperties: api.TenantProperties(*newTenant),
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/service/tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func TestCreateTenant(t *testing.T) {

newTenant := api.TenantProperties{
DisplayName: pointer.ToString("My test Tenant"),
GitRepo: &api.GitRepo{
Url: pointer.ToString("ssh://git@git.example.com/test.git"),
},
}
result := testutil.NewRequest().
Post("/tenants").
Expand All @@ -48,8 +51,10 @@ func TestCreateTenant(t *testing.T) {
err := result.UnmarshalJsonToObject(tenant)
assert.NoError(t, err)
assert.NotNil(t, tenant)
assert.NotNil(t, tenant.GitRepo)
assert.Contains(t, tenant.Id, api.TenantIDPrefix)
assert.Equal(t, newTenant.DisplayName, tenant.DisplayName)
assert.Equal(t, newTenant.GitRepo.Url, tenant.GitRepo.Url)
}

func TestCreateTenantFail(t *testing.T) {
Expand Down Expand Up @@ -82,6 +87,25 @@ func TestCreateTenantEmpty(t *testing.T) {
assert.Contains(t, reason.Reason, "must have a value")
}

func TestCreateTenantNoGitURL(t *testing.T) {
e, _ := setupTest(t)

newTenant := api.TenantProperties{
DisplayName: pointer.ToString("Tenant without a Git URL"),
}

result := testutil.NewRequest().
Post("/tenants/").
WithHeader(echo.HeaderAuthorization, bearerToken).
WithJsonBody(newTenant).
Go(t, e)
assert.Equal(t, http.StatusBadRequest, result.Code())
reason := &api.Reason{}
err := result.UnmarshalJsonToObject(reason)
assert.NoError(t, err)
assert.Contains(t, reason.Reason, "required")
}

func TestTenantDelete(t *testing.T) {
e, _ := setupTest(t)

Expand Down