Skip to content

Commit

Permalink
Merge pull request #30 from dchudik/master
Browse files Browse the repository at this point in the history
DNSv2. Rename uuid to id in rrset and zone. Rename zone to zone_id in rrset.
  • Loading branch information
tarry-dvice authored Jan 25, 2024
2 parents 143c8b6 + 2f2df33 commit 4796afa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func main() {
}

// Create rrset type TXT
selectelCreatedRrset, err := client.CreateRRSet(context.Background(), selectelCreatedZone.UUID, createRrsetOpts)
selectelCreatedRrset, err := client.CreateRRSet(context.Background(), selectelCreatedZone.ID, createRrsetOpts)
if err != nil {
log.Fatal(err)
}
Expand All @@ -120,7 +120,6 @@ func main() {
}
```


## Current version vs Legacy version

Current version is `github.com/selectel/domains-go/pkg/v2`
Expand Down
4 changes: 2 additions & 2 deletions pkg/v2/rrsetManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type (

// RRSet is list of records grouped by their name and type.
RRSet struct {
UUID string `json:"uuid"`
ZoneUUID string `json:"zone"` //nolint: tagliatelle
ID string `json:"id"`
ZoneID string `json:"zone_id"`
Name string `json:"name"`
TTL int `json:"ttl"`
Type RecordType `json:"type"`
Expand Down
24 changes: 12 additions & 12 deletions pkg/v2/testing/rrsetManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ func (s *RRSetManagerSuite) TearDownTest() {
}

func (s *RRSetManagerSuite) TestGetRRSet_ok() {
path := fmt.Sprintf(singleRRSetPath, testUUID, testUUID)
path := fmt.Sprintf(singleRRSetPath, testID, testID)
httpmock.RegisterResponder(
http.MethodGet,
fmt.Sprintf("%s%s", testAPIURL, path),
httpmock.NewStringResponder(http.StatusOK, mockGetRRSetResponse()),
)

rrset, err := testClient.GetRRSet(testCtx, testUUID, testUUID)
rrset, err := testClient.GetRRSet(testCtx, testID, testID)

s.Nil(err)
//nolint: exhaustruct
s.IsType(&v2.RRSet{}, rrset)
s.NotNil(rrset.Records)
s.Equal(testUUID, rrset.UUID)
s.Equal(testID, rrset.ID)
s.Len(rrset.Records, 2)
}

func (s *RRSetManagerSuite) TestListRRSets_ok() {
path := fmt.Sprintf(rrsetPath, testUUID)
path := fmt.Sprintf(rrsetPath, testID)
testCount := 10
httpmock.RegisterResponder(
http.MethodGet,
fmt.Sprintf("%s%s", testAPIURL, path),
httpmock.NewStringResponder(http.StatusOK, mockListRRSetResponse(testCount)),
)

rrsetList, err := testClient.ListRRSets(testCtx, testUUID, nil)
rrsetList, err := testClient.ListRRSets(testCtx, testID, nil)

s.Nil(err)
//nolint: exhaustruct
Expand All @@ -67,7 +67,7 @@ func (s *RRSetManagerSuite) TestListRRSets_ok() {
}

func (s *RRSetManagerSuite) TestCreateRRSet_ok() {
path := fmt.Sprintf(rrsetPath, testUUID)
path := fmt.Sprintf(rrsetPath, testID)
httpmock.RegisterResponder(
http.MethodPost,
fmt.Sprintf("%s%s", testAPIURL, path),
Expand All @@ -83,28 +83,28 @@ func (s *RRSetManagerSuite) TestCreateRRSet_ok() {
{Content: "", Disabled: false},
},
}
rrset, err := testClient.CreateRRSet(testCtx, testUUID, newRRSet)
rrset, err := testClient.CreateRRSet(testCtx, testID, newRRSet)

s.Nil(err)
//nolint: exhaustruct
s.IsType(&v2.RRSet{}, rrset)
s.Equal(testUUID, rrset.UUID)
s.Equal(testID, rrset.ID)
}

func (s *RRSetManagerSuite) TestDeleteRRSet_ok() {
path := fmt.Sprintf(singleRRSetPath, testUUID, testUUID)
path := fmt.Sprintf(singleRRSetPath, testID, testID)
httpmock.RegisterResponder(
http.MethodDelete,
fmt.Sprintf("%s%s", testAPIURL, path),
httpmock.NewBytesResponder(http.StatusNoContent, []byte{}),
)

err := testClient.DeleteRRSet(testCtx, testUUID, testUUID)
err := testClient.DeleteRRSet(testCtx, testID, testID)
s.Nil(err)
}

func (s *RRSetManagerSuite) TestUpdateRRSet_ok() {
path := fmt.Sprintf(singleRRSetPath, testUUID, testUUID)
path := fmt.Sprintf(singleRRSetPath, testID, testID)
httpmock.RegisterResponder(
http.MethodPatch,
fmt.Sprintf("%s%s", testAPIURL, path),
Expand All @@ -118,6 +118,6 @@ func (s *RRSetManagerSuite) TestUpdateRRSet_ok() {
{Content: "content", Disabled: false},
},
}
err := testClient.UpdateRRSet(testCtx, testUUID, testUUID, changeForm)
err := testClient.UpdateRRSet(testCtx, testID, testID, changeForm)
s.Nil(err)
}
16 changes: 8 additions & 8 deletions pkg/v2/testing/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const (
testDomainName = "bonnie-test.com"
testUUID = "a1b1a1e3-6cc2-4578-8ec7-5c4b2fcba3f7"
testID = "a1b1a1e3-6cc2-4578-8ec7-5c4b2fcba3f7"
testAPIURL = "http://api.test.bonnie.com"
testIPv4 = "10.20.30.40"
testTTL = 60
Expand All @@ -33,7 +33,7 @@ func mockGetZoneResponse() string {
return fmt.Sprintf(
`
{
"uuid": "%v",
"id": "%v",
"project_id": "%v",
"name": "%v",
"created_at": "2023-03-09T18:47:25Z",
Expand All @@ -44,8 +44,8 @@ func mockGetZoneResponse() string {
"last_delegated_at": null
}
`,
testUUID,
testUUID,
testID,
testID,
testDomainName,
)
}
Expand All @@ -66,17 +66,17 @@ func mockListZonesResponse(count int) string {
func mockGetRRSetResponse() string {
return fmt.Sprintf(
`{
"uuid": "%v",
"zone": "%v",
"id": "%v",
"zone_id": "%v",
"name": "go-test-record.%v",
"type": "%v",
"ttl": %v,
"comment": "I am mock response from bonnie-go",
"managed_by": null,
"records": [{"content":"%v", "disabled": true},{"content":"%v", "disabled":false}]
}`,
testUUID,
testUUID,
testID,
testID,
testDomainName,
v2.A,
testTTL,
Expand Down
16 changes: 8 additions & 8 deletions pkg/v2/testing/zoneManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ func (s *ZoneManageSuite) TestCreateZone_ok() {
//nolint: exhaustruct
s.IsType(&v2.Zone{}, zone)
s.Equal(testDomainName, zone.Name)
s.Equal(testUUID, zone.UUID)
s.Equal(testUUID, zone.ProjectID)
s.Equal(testID, zone.ID)
s.Equal(testID, zone.ProjectID)
}

func (s *ZoneManageSuite) TestGetZone_ok() {
path := fmt.Sprintf(zonePath, testUUID)
path := fmt.Sprintf(zonePath, testID)
httpmock.RegisterResponder(
http.MethodGet,
fmt.Sprintf("%s%s", testAPIURL, path),
httpmock.NewStringResponder(http.StatusOK, mockGetZoneResponse()),
)

zone, err := testClient.GetZone(testCtx, testUUID, nil)
zone, err := testClient.GetZone(testCtx, testID, nil)

s.Nil(err)
//nolint: exhaustruct
s.IsType(&v2.Zone{}, zone)
s.Equal(testDomainName, zone.Name)
s.Equal(testUUID, zone.UUID)
s.Equal(testUUID, zone.ProjectID)
s.Equal(testID, zone.ID)
s.Equal(testID, zone.ProjectID)
}

func (s *ZoneManageSuite) TestListZones_ok() {
Expand All @@ -87,14 +87,14 @@ func (s *ZoneManageSuite) TestListZones_ok() {
}

func (s *ZoneManageSuite) TestDeleteZone_ok() {
path := fmt.Sprintf(zonePath, testUUID)
path := fmt.Sprintf(zonePath, testID)
httpmock.RegisterResponder(
http.MethodDelete,
fmt.Sprintf("%s%s", testAPIURL, path),
httpmock.NewBytesResponder(http.StatusNoContent, []byte{}),
)

err := testClient.DeleteZone(testCtx, testUUID)
err := testClient.DeleteZone(testCtx, testID)

s.Nil(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/v2/zoneManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type (
// Zone represents an unmarshalled zone body from API response.
Zone struct {
UUID string `json:"uuid"`
ID string `json:"id"`
ProjectID string `json:"project_id"`
Name string `json:"name"`
Comment string `json:"comment"`
Expand Down

0 comments on commit 4796afa

Please sign in to comment.