Skip to content

Commit

Permalink
fix: correctly format record names to ensure matching coordinates (#2)
Browse files Browse the repository at this point in the history
* fix: correctly format record names to ensure matching coordinates

* chore: go mod tidy
  • Loading branch information
Niallfitzy1 authored Sep 5, 2023
1 parent 27b0dc3 commit f7c6860
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 193 deletions.
52 changes: 42 additions & 10 deletions _test/test.go → _test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/joho/godotenv"
"github.com/libdns/libdns"
porkbun "github.com/libdns/porkbun"
"github.com/libdns/porkbun"
)

func main() {
Expand All @@ -36,17 +36,17 @@ func main() {
_, err := provider.CheckCredentials(context.TODO())

if err != nil {
log.Fatalln("Credential check failed: %s\n", err.Error())
log.Fatalf("Credential check failed: %s\n", err.Error())
}

//Get records
records, err := provider.GetRecords(context.TODO(), zone)
initialRecords, err := provider.GetRecords(context.TODO(), zone)
if err != nil {
log.Fatalln("Failed to fetch records: %s\n", err.Error())
log.Fatalf("Failed to fetch records: %s\n", err.Error())
}

log.Println("Records fetched:")
for _, record := range records {
for _, record := range initialRecords {
fmt.Printf("%s (.%s): %s, %s\n", record.Name, zone, record.Value, record.Type)
}

Expand All @@ -58,7 +58,7 @@ func main() {

//Create record
appendedRecords, err := provider.AppendRecords(context.TODO(), zone, []libdns.Record{
libdns.Record{
{
Type: recordType,
Name: testFullName,
TTL: ttl,
Expand All @@ -67,13 +67,24 @@ func main() {
})

if err != nil {
log.Fatalln("ERROR: %s\n", err.Error())
log.Fatalf("ERROR: %s\n", err.Error())
}

//Get records
postCreatedRecords, err := provider.GetRecords(context.TODO(), zone)
if err != nil {
log.Fatalf("Failed to fetch records: %s\n", err.Error())
}

if len(postCreatedRecords) != len(initialRecords)+1 {
log.Fatalln("Additional record not created")
}

fmt.Printf("Created record: \n%v\n", appendedRecords[0])

// Update record
updatedRecords, err := provider.SetRecords(context.TODO(), zone, []libdns.Record{
libdns.Record{
{
Type: recordType,
Name: testFullName,
TTL: ttl,
Expand All @@ -82,13 +93,23 @@ func main() {
})

if err != nil {
log.Fatalln("ERROR: %s\n", err.Error())
log.Fatalf("ERROR: %s\n", err.Error())
}
fmt.Printf("Updated record: \n%v\n", updatedRecords[0])

//Get records
updatedRecords, err = provider.GetRecords(context.TODO(), zone)
if err != nil {
log.Fatalf("Failed to fetch records: %s\n", err.Error())
}

if len(updatedRecords) != len(initialRecords)+1 {
log.Fatalln("Additional record created instead of updating existing")
}

// Delete record
deleteRecords, err := provider.DeleteRecords(context.TODO(), zone, []libdns.Record{
libdns.Record{
{
Type: recordType,
Name: testFullName,
},
Expand All @@ -97,6 +118,17 @@ func main() {
if err != nil {
log.Fatalln("ERROR: %s\n", err.Error())
}

//Get records
updatedRecords, err = provider.GetRecords(context.TODO(), zone)
if err != nil {
log.Fatalf("Failed to fetch records: %s\n", err.Error())
}

if len(updatedRecords) != len(initialRecords) {
log.Fatalln("Additional record not cleaned up")
}

fmt.Printf("Deleted record: \n%v\n", deleteRecords[0])

}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module github.com/libdns/porkbun

go 1.18
go 1.20

require github.com/libdns/libdns v0.2.1

require github.com/joho/godotenv v1.4.0 // indirect
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
Loading

0 comments on commit f7c6860

Please sign in to comment.