Skip to content

Commit

Permalink
refactor: reorganize code
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <felix.gateru@gmail.com>
  • Loading branch information
felixgateru authored and dborovcanin committed Jun 28, 2024
1 parent d465cbd commit e8dbc1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions pkg/sdk/go/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ func (sdk mgSDK) CreateDomain(domain Domain, token string) (Domain, errors.SDKEr
}

func (sdk mgSDK) UpdateDomain(domain Domain, token string) (Domain, errors.SDKError) {
data, err := json.Marshal(domain)
if err != nil {
return Domain{}, errors.NewSDKError(err)
}

if domain.ID == "" {
return Domain{}, errors.NewSDKError(apiutil.ErrMissingID)
}
url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, domainsEndpoint, domain.ID)

data, err := json.Marshal(domain)
if err != nil {
return Domain{}, errors.NewSDKError(err)
}

_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
if sdkerr != nil {
return Domain{}, sdkerr
Expand Down
14 changes: 7 additions & 7 deletions pkg/sdk/go/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
Tags: sdkDomain.Tags,
Alias: sdkDomain.Alias,
}
updatedName = "updated-domain"
updatedDomianName = "updated-domain"
)

func setupDomains() (*httptest.Server, *authmocks.Service) {
Expand Down Expand Up @@ -177,9 +177,9 @@ func TestUpdateDomain(t *testing.T) {
mgsdk := sdk.NewSDK(sdkConf)

upDomainSDK := sdkDomain
upDomainSDK.Name = updatedName
upDomainSDK.Name = updatedDomianName
upDomainAuth := authDomain
upDomainAuth.Name = updatedName
upDomainAuth.Name = updatedDomianName

cases := []struct {
desc string
Expand All @@ -197,7 +197,7 @@ func TestUpdateDomain(t *testing.T) {
domainID: sdkDomain.ID,
domain: sdk.Domain{
ID: sdkDomain.ID,
Name: updatedName,
Name: updatedDomianName,
},
svcRes: upDomainAuth,
svcErr: nil,
Expand All @@ -210,7 +210,7 @@ func TestUpdateDomain(t *testing.T) {
domainID: sdkDomain.ID,
domain: sdk.Domain{
ID: sdkDomain.ID,
Name: updatedName,
Name: updatedDomianName,
},
svcRes: auth.Domain{},
svcErr: svcerr.ErrAuthentication,
Expand All @@ -223,7 +223,7 @@ func TestUpdateDomain(t *testing.T) {
domainID: sdkDomain.ID,
domain: sdk.Domain{
ID: sdkDomain.ID,
Name: updatedName,
Name: updatedDomianName,
},
svcRes: auth.Domain{},
svcErr: nil,
Expand All @@ -236,7 +236,7 @@ func TestUpdateDomain(t *testing.T) {
domainID: wrongID,
domain: sdk.Domain{
ID: wrongID,
Name: updatedName,
Name: updatedDomianName,
},
svcRes: auth.Domain{},
svcErr: svcerr.ErrAuthorization,
Expand Down

0 comments on commit e8dbc1f

Please sign in to comment.