-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: support new vcs_connection resource (#999)
* Feat: support new vcs_connection resource * disable integration test * update description
- Loading branch information
1 parent
b666191
commit ffd28c4
Showing
16 changed files
with
1,518 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package client | ||
|
||
type VcsConnection struct { | ||
Id string `json:"id"` | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Url string `json:"url"` | ||
VcsAgentKey string `json:"vcsAgentKey"` | ||
} | ||
|
||
type VcsConnectionCreatePayload struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
Url string `json:"url"` | ||
VcsAgentKey string `json:"vcsAgentKey,omitempty"` | ||
} | ||
|
||
type VcsConnectionUpdatePayload struct { | ||
Name string `json:"name"` | ||
VcsAgentKey string `json:"vcsAgentKey,omitempty"` | ||
} | ||
|
||
func (client *ApiClient) VcsConnection(id string) (*VcsConnection, error) { | ||
var result VcsConnection | ||
|
||
if err := client.http.Get("/vcs/connections/"+id, nil, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (client *ApiClient) VcsConnectionCreate(payload VcsConnectionCreatePayload) (*VcsConnection, error) { | ||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
payloadWithOrg := struct { | ||
VcsConnectionCreatePayload | ||
OrganizationId string `json:"organizationId"` | ||
}{ | ||
VcsConnectionCreatePayload: payload, | ||
OrganizationId: organizationId, | ||
} | ||
|
||
var result VcsConnection | ||
if err := client.http.Post("/vcs/connections", payloadWithOrg, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (client *ApiClient) VcsConnectionUpdate(id string, payload VcsConnectionUpdatePayload) (*VcsConnection, error) { | ||
var result VcsConnection | ||
|
||
if err := client.http.Put("/vcs/connections/"+id, payload, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (client *ApiClient) VcsConnectionDelete(id string) error { | ||
return client.http.Delete("/vcs/connections/"+id, nil) | ||
} | ||
|
||
func (client *ApiClient) VcsConnections() ([]VcsConnection, error) { | ||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var result []VcsConnection | ||
if err := client.http.Get("/vcs/connections", map[string]string{"organizationId": organizationId}, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package client_test | ||
|
||
import ( | ||
. "github.com/env0/terraform-provider-env0/client" | ||
"github.com/jinzhu/copier" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("VcsConnection Client", func() { | ||
mockVcsConnection := VcsConnection{ | ||
Id: "id0", | ||
Name: "test-connection", | ||
Type: "GitHubEnterprise", | ||
Url: "https://github.example.com", | ||
VcsAgentKey: "ENV0_DEFAULT", | ||
} | ||
|
||
Describe("Get VcsConnection", func() { | ||
var returnedVcsConnection *VcsConnection | ||
var err error | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/vcs/connections/"+mockVcsConnection.Id, nil, gomock.Any()). | ||
Do(func(path string, request interface{}, response *VcsConnection) { | ||
*response = mockVcsConnection | ||
}) | ||
returnedVcsConnection, err = apiClient.VcsConnection(mockVcsConnection.Id) | ||
}) | ||
|
||
It("Should send GET request", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should return vcs connection", func() { | ||
Expect(*returnedVcsConnection).To(Equal(mockVcsConnection)) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("Create VcsConnection", func() { | ||
var createdVcsConnection *VcsConnection | ||
var err error | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall() | ||
|
||
createPayload := VcsConnectionCreatePayload{} | ||
_ = copier.Copy(&createPayload, &mockVcsConnection) | ||
|
||
expectedCreateRequest := struct { | ||
VcsConnectionCreatePayload | ||
OrganizationId string `json:"organizationId"` | ||
}{ | ||
VcsConnectionCreatePayload: createPayload, | ||
OrganizationId: organizationId, | ||
} | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Post("/vcs/connections", expectedCreateRequest, gomock.Any()). | ||
Do(func(path string, request interface{}, response *VcsConnection) { | ||
*response = mockVcsConnection | ||
}) | ||
|
||
createdVcsConnection, err = apiClient.VcsConnectionCreate(createPayload) | ||
}) | ||
|
||
It("Should get organization id", func() { | ||
organizationIdCall.Times(1) | ||
}) | ||
|
||
It("Should send POST request with params", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
It("Should return created vcs connection", func() { | ||
Expect(*createdVcsConnection).To(Equal(mockVcsConnection)) | ||
}) | ||
}) | ||
|
||
Describe("Update VcsConnection", func() { | ||
var updatedVcsConnection *VcsConnection | ||
var err error | ||
|
||
BeforeEach(func() { | ||
updatePayload := VcsConnectionUpdatePayload{ | ||
Name: mockVcsConnection.Name, | ||
VcsAgentKey: mockVcsConnection.VcsAgentKey, | ||
} | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Put("/vcs/connections/"+mockVcsConnection.Id, updatePayload, gomock.Any()). | ||
Do(func(path string, request interface{}, response *VcsConnection) { | ||
*response = mockVcsConnection | ||
}) | ||
|
||
updatedVcsConnection, err = apiClient.VcsConnectionUpdate(mockVcsConnection.Id, updatePayload) | ||
}) | ||
|
||
It("Should send PUT request with params", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
|
||
It("Should return updated vcs connection", func() { | ||
Expect(*updatedVcsConnection).To(Equal(mockVcsConnection)) | ||
}) | ||
}) | ||
|
||
Describe("Delete VcsConnection", func() { | ||
var err error | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT().Delete("/vcs/connections/"+mockVcsConnection.Id, nil) | ||
err = apiClient.VcsConnectionDelete(mockVcsConnection.Id) | ||
}) | ||
|
||
It("Should send DELETE request", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("List VcsConnections", func() { | ||
var returnedVcsConnections []VcsConnection | ||
var err error | ||
mockVcsConnections := []VcsConnection{mockVcsConnection} | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall() | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/vcs/connections", map[string]string{"organizationId": organizationId}, gomock.Any()). | ||
Do(func(path string, request interface{}, response *[]VcsConnection) { | ||
*response = mockVcsConnections | ||
}) | ||
returnedVcsConnections, err = apiClient.VcsConnections() | ||
}) | ||
|
||
It("Should get organization id", func() { | ||
organizationIdCall.Times(1) | ||
}) | ||
|
||
It("Should send GET request", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should return vcs connections", func() { | ||
Expect(returnedVcsConnections).To(Equal(mockVcsConnections)) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.