Skip to content
Draft
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added
- managed load balancer: add `WaitForLoadBalancerState` and `WaitForLoadBalancerDeletion` helpers for waiting load-balancer state and deletion

## [8.18.0]

### Added
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.22

require (
github.com/davecgh/go-spew v1.1.1
github.com/dnaeon/go-vcr v1.2.0
github.com/stretchr/testify v1.9.0
gopkg.in/dnaeon/go-vcr.v4 v4.0.2
)

require (
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -21,8 +18,7 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/dnaeon/go-vcr.v4 v4.0.2 h1:7T5VYf2ifyK01ETHbJPl5A6XTpUljD4Trw3GEDcdedk=
gopkg.in/dnaeon/go-vcr.v4 v4.0.2/go.mod h1:65yxh9goQVrudqofKtHA4JNFWd6XZRkWfKN4YpMx7KI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 20 additions & 1 deletion upcloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,32 @@ func (c *Client) Do(r *http.Request) ([]byte, error) {
return c.handleResponse(response)
}

type clientContextKey string

const fragmentContextKey clientContextKey = "fragment"

func WithFragment(ctx context.Context, fragment string) context.Context {
return context.WithValue(ctx, fragmentContextKey, fragment)
}

func GetFragment(ctx context.Context) string {
if hash, ok := ctx.Value(fragmentContextKey).(string); ok {
return hash
}
return ""
}

func (c *Client) createRequest(ctx context.Context, method, path string, body []byte) (*http.Request, error) {
var bodyReader io.Reader

if body != nil {
bodyReader = bytes.NewBuffer(body)
}
req, err := http.NewRequestWithContext(ctx, method, c.createRequestURL(path), bodyReader)
url := c.createRequestURL(path)
if fragment := GetFragment(ctx); fragment != "" {
url = fmt.Sprintf("%s#%s", url, fragment)
}
req, err := http.NewRequestWithContext(ctx, method, url, bodyReader)
if err != nil {
return nil, err
}
Expand Down
9 changes: 9 additions & 0 deletions upcloud/request/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,12 @@ type GetLoadBalancerDNSChallengeDomainRequest struct{}
func (r *GetLoadBalancerDNSChallengeDomainRequest) RequestURL() string {
return "/load-balancer/certificate-bundles/dns-challenge-domain"
}

type WaitForLoadBalancerStateRequest struct {
UUID string
DesiredState upcloud.LoadBalancerOperationalState
}

type WaitForLoadBalancerDeletionRequest struct {
UUID string `json:"-"`
}
24 changes: 13 additions & 11 deletions upcloud/service/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/client"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
"github.com/dnaeon/go-vcr/cassette"
"github.com/dnaeon/go-vcr/recorder"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/dnaeon/go-vcr.v4/pkg/cassette"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)

// TestGetAccount tests that the GetAccount() method returns proper data
Expand Down Expand Up @@ -49,16 +49,18 @@ func TestGetAccount(t *testing.T) {
// - Get account list and check that subaccount and main account is listed
// - Delete tag and subaccount
func TestListDetailsCreateModifyDeleteSubaccount(t *testing.T) {
mainAccount := "testuser"

// Mask username from recording just in case if developer forgets to review it before commit
hook := func(i *cassette.Interaction) error {
testuser, _ := getCredentials()
i.Request.Body = strings.Replace(i.Request.Body, testuser, mainAccount, -1)
i.Response.Body = strings.Replace(i.Response.Body, testuser, mainAccount, -1)
return nil
}

record(t, "createmodifydeletesubaccount", func(ctx context.Context, t *testing.T, rec *recorder.Recorder, svc *Service) {
var err error
mainAccount := "testuser"
rec.AddFilter(func(i *cassette.Interaction) error {
// try to mask username from recording just in case if developer forgets to review it before commit
testuser, _ := getCredentials()
i.Request.Body = strings.Replace(i.Request.Body, testuser, mainAccount, -1)
i.Response.Body = strings.Replace(i.Response.Body, testuser, mainAccount, -1)
return nil
})
username := "sdk_test_subaccount"
tagName := fmt.Sprintf("sdk_test_tag_%s", username)

Expand Down Expand Up @@ -235,5 +237,5 @@ func TestListDetailsCreateModifyDeleteSubaccount(t *testing.T) {
}
assert.False(t, subAccountNotFound, "subaccount not found from list of accounts")
assert.False(t, mainAccountNotFound, "main account not found from list of accounts")
})
}, recorder.WithHook(hook, recorder.BeforeSaveHook))
}
2 changes: 1 addition & 1 deletion upcloud/service/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"testing"

"github.com/dnaeon/go-vcr/recorder"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"

"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
)
Expand Down
2 changes: 1 addition & 1 deletion upcloud/service/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
"github.com/dnaeon/go-vcr/recorder"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)

// TestFirewallRules performs the following actions with context:
Expand Down
Loading
Loading