-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add support for libdns ZoneLister #9
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -693,3 +693,51 @@ func TestDeleteRecords(t *testing.T) { | |
| t.Fatalf("p.GetRecords() unexpected diff [-want +got]: %s", diff) | ||
| } | ||
| } | ||
|
|
||
| func TestListZones(t *testing.T) { | ||
| if *token == "" || *domain == "" { | ||
| t.Skip("skipping integration test; both -token and -domain must be set") | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
| if deadline, ok := t.Deadline(); ok { | ||
| var cancel context.CancelFunc | ||
| ctx, cancel = context.WithDeadline(ctx, deadline) | ||
| t.Cleanup(cancel) | ||
| } | ||
|
|
||
| p := &desec.Provider{ | ||
| Token: *token, | ||
| } | ||
|
|
||
| testDomains := []string{ | ||
| *domain, | ||
| "test1-" + *domain, | ||
| "test2-" + *domain, | ||
| } | ||
|
|
||
| for _, testDomain := range testDomains { | ||
| if domainExists(ctx, t, testDomain) { | ||
| t.Fatalf("domain %q exists, but it should not", testDomain) | ||
| } | ||
| createDomain(ctx, t, testDomain) | ||
| domain := testDomain | ||
| t.Cleanup(func() { deleteDomain(ctx, t, domain) }) | ||
| } | ||
|
|
||
| zones, err := p.ListZones(ctx) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| zoneMap := make(map[string]bool) | ||
| for _, zone := range zones { | ||
| zoneMap[zone.Name] = true | ||
| } | ||
|
|
||
| for _, testDomain := range testDomains { | ||
| if !zoneMap[testDomain] { | ||
| t.Errorf("Failed to find %s in ListZones call", testDomain) | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the intend is to make sure to allow domains that are not part of the test domains to be part of the result, because there can be preexisting domains (good idea, btw). This is not immediately clear from the code (at first I thought this was a bug). Also I generally prefer using go-cmp for things like this. In this case, I would use something like the (untested) code below: testDomains := map[string]bool{
// ...
}
// ...
got, err := p.ListZones()
if err != nil {
t.Fatal(err)
}
var want []libdns.Zone
for domain := range testDomains {
want = append(want, libdns.Zone{Name: domain})
}
// We only control a limited number of zones in the test account, there may be preexisting zones that
// are unknown to us. Ignore all unknown zones.
opts := cmp.Options{
cmpopts.IgnoreSliceElements(func(zone libdns.Zone) bool { return !testDomain[zone.Name] }),
comports.SortSlices(func(a, b libdns.Zone) int { return cmp.Compare(a.Name, b.Name) }),
}
if diff := cmp.Diff(want, got, opts); diff != "" {
t.Errorf("ListZones() unexpected diff [-want +got]: %s", diff)
} |
||
| } | ||
haylinmoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.