Skip to content

Commit

Permalink
wip for deployment freeze service
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Nov 15, 2024
1 parent 0878671 commit 92b4c45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
14 changes: 8 additions & 6 deletions pkg/deploymentfreezes/deploymentfreeze_service_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package deploymentfreezes

import (
client2 "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"github.com/stretchr/testify/require"
"testing"
)

func createService(t *testing.T) *DeploymentFreezeService {

func createClient() newclient.Client {
return newclient.NewClient(&newclient.HttpSession{})
}

func TestFreezeAddGetDelete(t *testing.T) {
service := createService(t)
client := client2.Client{}
func TestAddParameterValidation(t *testing.T) {
client := createClient()
_, err := Add(client, nil)
require.Error(t, err)
}
28 changes: 22 additions & 6 deletions pkg/deploymentfreezes/deploymentfreezes_service.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package deploymentfreezes

import (
"math"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient"
"math"
)

const template = "/api/deploymentfreezes{/id}{?skip,take,ids,projectIds,tenantIds,environmentIds,includeComplete,status}"

type DeploymentFreezeService struct {
}

func NewDeploymentFreezeService() *DeploymentFreezeService {
return &DeploymentFreezeService{}
}

func Get(client newclient.Client, deploymentFreezesQuery *DeploymentFreezeQuery) (*DeploymentFreezes, error) {
path, err := client.URITemplateCache().Expand(template, deploymentFreezesQuery)
if err != nil {
Expand All @@ -30,11 +27,13 @@ func Get(client newclient.Client, deploymentFreezesQuery *DeploymentFreezeQuery)
}

func GetAll(client newclient.Client) ([]*DeploymentFreeze, error) {
res, err := Get[[]*DeploymentFreeze](client, &DeploymentFreezeQuery{Skip: 0, Take: math.MaxInt32})
path, err := client.URITemplateCache().Expand(template, &DeploymentFreezeQuery{Skip: 0, Take: math.MaxInt32})
if err != nil {
return nil, err
}

res, err := newclient.Get[DeploymentFreezes](client.HttpSession(), path)

freezes := make([]*DeploymentFreeze, 0)
for _, freeze := range res.Items {
freezes = append(freezes, &freeze)
Expand All @@ -43,6 +42,23 @@ func GetAll(client newclient.Client) ([]*DeploymentFreeze, error) {
return freezes, nil
}

func Add(client newclient.Client, deploymentFreeze *DeploymentFreeze) (*DeploymentFreeze, error) {
if deploymentFreeze == nil {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("deploymentFreeze")
}

path, err := client.URITemplateCache().Expand(template, deploymentFreeze)
if err != nil {
return nil, err
}

res, err := newclient.Post[DeploymentFreeze](client.HttpSession(), path, deploymentFreeze)
if err != nil {
return nil, err
}
return res, nil
}

func Update(client newclient.Client, deploymentFreeze *DeploymentFreeze) (*DeploymentFreeze, error) {
if deploymentFreeze == nil {
return nil, internal.CreateRequiredParameterIsEmptyOrNilError("deploymentFreeze")
Expand Down

0 comments on commit 92b4c45

Please sign in to comment.