forked from woodpecker-ci/woodpecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split client into multiple files and add more tests (woodpecker-ci#3647)
All the client functions were in a single file, which was already very long, and the test file gets even longer as more tests are added. I split it into separate files representing the API path and started adding some tests.
- Loading branch information
Showing
16 changed files
with
1,499 additions
and
582 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 |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
*.so | ||
*.dylib | ||
vendor/ | ||
__debug_bin | ||
__debug_bin* | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
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,50 @@ | ||
package woodpecker | ||
|
||
import "fmt" | ||
|
||
const ( | ||
pathAgents = "%s/api/agents" | ||
pathAgent = "%s/api/agents/%d" | ||
pathAgentTasks = "%s/api/agents/%d/tasks" | ||
) | ||
|
||
// AgentCreate creates a new agent. | ||
func (c *client) AgentCreate(in *Agent) (*Agent, error) { | ||
out := new(Agent) | ||
uri := fmt.Sprintf(pathAgents, c.addr) | ||
return out, c.post(uri, in, out) | ||
} | ||
|
||
// AgentList returns a list of all registered agents. | ||
func (c *client) AgentList() ([]*Agent, error) { | ||
out := make([]*Agent, 0, 5) | ||
uri := fmt.Sprintf(pathAgents, c.addr) | ||
return out, c.get(uri, &out) | ||
} | ||
|
||
// Agent returns an agent by id. | ||
func (c *client) Agent(agentID int64) (*Agent, error) { | ||
out := new(Agent) | ||
uri := fmt.Sprintf(pathAgent, c.addr, agentID) | ||
return out, c.get(uri, out) | ||
} | ||
|
||
// AgentUpdate updates the agent with the provided Agent struct. | ||
func (c *client) AgentUpdate(in *Agent) (*Agent, error) { | ||
out := new(Agent) | ||
uri := fmt.Sprintf(pathAgent, c.addr, in.ID) | ||
return out, c.patch(uri, in, out) | ||
} | ||
|
||
// AgentDelete deletes the agent with the given id. | ||
func (c *client) AgentDelete(agentID int64) error { | ||
uri := fmt.Sprintf(pathAgent, c.addr, agentID) | ||
return c.delete(uri) | ||
} | ||
|
||
// AgentTasksList returns a list of all tasks for the agent with the given id. | ||
func (c *client) AgentTasksList(agentID int64) ([]*Task, error) { | ||
out := make([]*Task, 0, 5) | ||
uri := fmt.Sprintf(pathAgentTasks, c.addr, agentID) | ||
return out, c.get(uri, &out) | ||
} |
Oops, something went wrong.