Skip to content

Commit

Permalink
Add test for WithComments function
Browse files Browse the repository at this point in the history
  • Loading branch information
verscheures authored and joeig committed Feb 9, 2024
1 parent 1c118e7 commit fb38b65
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions records_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"math/rand"
"net/http"
"reflect"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -139,7 +140,6 @@ func registerRecordMockResponder(testDomain, testRecord string) {
)
httpmock.RegisterResponder(http.MethodGet, generateTestAPIVHostURL()+"/zones/"+testDomainCanonical+"?rrset_name="+testRecordCanonical+"&rrset_type=TXT",
func(req *http.Request) (*http.Response, error) {

if res := verifyAPIKey(req); res != nil {
return res, nil
}
Expand All @@ -165,7 +165,6 @@ func registerRecordMockResponder(testDomain, testRecord string) {
)
httpmock.RegisterResponder(http.MethodGet, generateTestAPIVHostURL()+"/zones/"+testDomainCanonical+"?rrset_name="+testRecordCanonical,
func(req *http.Request) (*http.Response, error) {

if res := verifyAPIKey(req); res != nil {
return res, nil
}
Expand Down Expand Up @@ -211,7 +210,6 @@ func registerRecordMockResponder(testDomain, testRecord string) {
)
httpmock.RegisterResponder(http.MethodGet, generateTestAPIVHostURL()+"/zones/"+testDomainCanonical+"?rrset_name="+makeDomainCanonical(testRecord+"notfound"),
func(req *http.Request) (*http.Response, error) {

if res := verifyAPIKey(req); res != nil {
return res, nil
}
Expand All @@ -225,6 +223,35 @@ func registerRecordMockResponder(testDomain, testRecord string) {
)
}

func TestWithComments(t *testing.T) {
now := uint64(time.Now().Unix())
rrset := &RRset{}
comment1 := Comment{
Content: String("Example comment 1"),
Account: String("example account 1"),
ModifiedAt: Uint64(now),
}
comment2 := Comment{
Content: String("Example comment 2"),
Account: String("example account 2"),
ModifiedAt: Uint64(now + 1),
}

withCommentsFunc := WithComments(comment1, comment2)
withCommentsFunc(rrset)
if len(rrset.Comments) != 2 {
t.Errorf("Expected 2 comments, got %d", len(rrset.Comments))
}

if !reflect.DeepEqual(rrset.Comments[0], comment1) {
t.Errorf("Expected first comment to be %v, got %v", comment1, rrset.Comments[0])
}

if !reflect.DeepEqual(rrset.Comments[1], comment2) {
t.Errorf("Expected second comment to be %v, got %v", comment2, rrset.Comments[1])
}
}

func TestAddRecord(t *testing.T) {
testDomain := generateNativeZone(true)

Expand Down Expand Up @@ -462,7 +489,6 @@ func TestGetRecord(t *testing.T) {

for n, tc := range testCases {
t.Run(fmt.Sprintf("TestCase%d - %s", n, tc.testDesc), func(t *testing.T) {

fmt.Println("Get ", tc.testRecordName)
rrsets, err := p.Records.Get(context.Background(), testDomain, tc.testRecordName, tc.testRecordType)
if err != nil {
Expand Down Expand Up @@ -520,8 +546,10 @@ func TestPatchRRSets(t *testing.T) {

rrSets := RRsets{}
rrSetName := makeDomainCanonical(testRecordName)
rrSets.Sets = []RRset{{Name: &rrSetName, Type: RRTypePtr(RRTypeTXT),
ChangeType: ChangeTypePtr(ChangeTypeDelete)}}
rrSets.Sets = []RRset{{
Name: &rrSetName, Type: RRTypePtr(RRTypeTXT),
ChangeType: ChangeTypePtr(ChangeTypeDelete),
}}

if err := p.Records.Patch(context.Background(), testDomain, &rrSets); err != nil {
t.Errorf("%s", err)
Expand Down

0 comments on commit fb38b65

Please sign in to comment.