-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add support for agent settings (#323)
- Loading branch information
1 parent
a5b9ad5
commit 6209d6a
Showing
7 changed files
with
248 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package client | ||
|
||
// Key is project id. | ||
// Value is agent id. | ||
type AssignProjectsAgentsAssignmentsPayload map[string]interface{} | ||
|
||
type ProjectsAgentsAssignments struct { | ||
DefaultAgent string `json:"defaultAgent"` | ||
ProjectsAgents map[string]interface{} `json:"ProjectsAgents"` | ||
} | ||
|
||
func (client *ApiClient) AssignAgentsToProjects(payload AssignProjectsAgentsAssignmentsPayload) (*ProjectsAgentsAssignments, error) { | ||
organizationId, err := client.organizationId() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var result ProjectsAgentsAssignments | ||
if err := client.http.Post("/agents/projects-assignments?organizationId="+organizationId, payload, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (client *ApiClient) ProjectsAgentsAssignments() (*ProjectsAgentsAssignments, error) { | ||
organizationId, err := client.organizationId() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var result ProjectsAgentsAssignments | ||
err = client.http.Get("/agents/projects-assignments", map[string]string{"organizationId": organizationId}, &result) | ||
if 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,141 @@ | ||
package client_test | ||
|
||
import ( | ||
"errors" | ||
|
||
. "github.com/env0/terraform-provider-env0/client" | ||
"github.com/golang/mock/gomock" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// mockOrganizationIdCall(organizationId) | ||
|
||
var _ = Describe("Agent Project Assignment", func() { | ||
psas := map[string]interface{}{ | ||
"pid1": "aid1", | ||
"pid2": "aid2", | ||
} | ||
|
||
expectedResponse := ProjectsAgentsAssignments{ | ||
ProjectsAgents: psas, | ||
} | ||
|
||
errorMock := errors.New("error") | ||
|
||
Describe("AssignAgentsToProjects", func() { | ||
|
||
Describe("Successful", func() { | ||
var actualResult *ProjectsAgentsAssignments | ||
var err error | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Post("/agents/projects-assignments?organizationId="+organizationId, gomock.Any(), gomock.Any()). | ||
Do(func(path string, request interface{}, response *ProjectsAgentsAssignments) { | ||
*response = expectedResponse | ||
}).Times(1) | ||
actualResult, err = apiClient.AssignAgentsToProjects(psas) | ||
|
||
}) | ||
|
||
It("Should get organization id", func() { | ||
organizationIdCall.Times(1) | ||
}) | ||
|
||
It("Should send POST request with params", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("should return the POST result", func() { | ||
Expect(*actualResult).To(Equal(expectedResponse)) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("Failure", func() { | ||
var actualResult *ProjectsAgentsAssignments | ||
var err error | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Post("/agents/projects-assignments?organizationId="+organizationId, gomock.Any(), gomock.Any()). | ||
Return(errorMock) | ||
|
||
actualResult, err = apiClient.AssignAgentsToProjects(psas) | ||
}) | ||
|
||
It("Should fail if API call fails", func() { | ||
Expect(err).To(Equal(errorMock)) | ||
}) | ||
|
||
It("Should not return results", func() { | ||
Expect(actualResult).To(BeNil()) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("ProjectsAgentsAssignments", func() { | ||
Describe("Successful", func() { | ||
var actualResult *ProjectsAgentsAssignments | ||
var err error | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/agents/projects-assignments", gomock.Any(), gomock.Any()). | ||
Do(func(path string, request interface{}, response *ProjectsAgentsAssignments) { | ||
*response = expectedResponse | ||
}) | ||
actualResult, err = apiClient.ProjectsAgentsAssignments() | ||
}) | ||
|
||
It("Should get organization id", func() { | ||
organizationIdCall.Times(1) | ||
}) | ||
|
||
It("Should send GET request with params", func() { | ||
httpCall.Times(1) | ||
}) | ||
|
||
It("Should return the GET result", func() { | ||
Expect(*actualResult).To(Equal(expectedResponse)) | ||
}) | ||
|
||
It("Should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("Failure", func() { | ||
var actualResult *ProjectsAgentsAssignments | ||
var err error | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/agents/projects-assignments", gomock.Any(), gomock.Any()). | ||
Return(errorMock) | ||
|
||
actualResult, err = apiClient.ProjectsAgentsAssignments() | ||
}) | ||
|
||
It("Should fail if API call fails", func() { | ||
Expect(err).To(Equal(errorMock)) | ||
}) | ||
|
||
It("Should not return results", func() { | ||
Expect(actualResult).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
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
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