Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly format record names to ensure matching coordinates #2

Merged
merged 2 commits into from
Sep 5, 2023
Merged
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
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