-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare for dnsx.Manager to operate on zones (#43)
* Add new package for naming dns objects * Extend dnsiface.Service interface * Use dnsnames and complete dnsiface for tests * Use NewCloudDNSService function in main
- Loading branch information
1 parent
47f4567
commit af21ff6
Showing
11 changed files
with
157 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dnsname | ||
|
||
import "strings" | ||
|
||
// ProjectZone returns the project zone name, e.g. "autojoin-sandbox-measurement-lab-org". | ||
func ProjectZone(project string) string { | ||
return "autojoin-" + strings.TrimPrefix(project, "mlab-") + "-measurement-lab-org" | ||
} | ||
|
||
// OrgZone returns the organization zone name based on the given organization and | ||
// project, e.g. "autojoin-foo-sandbox-measurement-lab-org". | ||
func OrgZone(org, project string) string { | ||
// NOTE: prefix prevents name collision with existing zones when the org is "mlab". | ||
return "autojoin-" + org + "-" + strings.TrimPrefix(project, "mlab-") + "-measurement-lab-org" | ||
} | ||
|
||
// OrgDNS returns the DNS name for the given org and project, e.g. "foo.autojoin.measurement-lab.org." | ||
func OrgDNS(org, project string) string { | ||
return org + "." + strings.TrimPrefix(project, "mlab-") + ".measurement-lab.org." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package dnsname | ||
|
||
import "testing" | ||
|
||
func TestProjectZone(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
project string | ||
want string | ||
}{ | ||
{ | ||
name: "success", | ||
project: "mlab-sandbox", | ||
want: "autojoin-sandbox-measurement-lab-org", | ||
}, | ||
{ | ||
name: "success", | ||
project: "mlab-autojoin", | ||
want: "autojoin-autojoin-measurement-lab-org", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ProjectZone(tt.project); got != tt.want { | ||
t.Errorf("ProjectZone() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOrgZone(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
org string | ||
project string | ||
want string | ||
}{ | ||
{ | ||
name: "success", | ||
org: "mlab", | ||
project: "mlab-sandbox", | ||
want: "autojoin-mlab-sandbox-measurement-lab-org", | ||
}, | ||
{ | ||
name: "success", | ||
org: "rnp", | ||
project: "mlab-autojoin", | ||
want: "autojoin-rnp-autojoin-measurement-lab-org", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := OrgZone(tt.org, tt.project); got != tt.want { | ||
t.Errorf("OrgZone() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOrgDNS(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
org string | ||
project string | ||
want string | ||
}{ | ||
{ | ||
name: "success", | ||
org: "foo", | ||
project: "mlab-sandbox", | ||
want: "foo.sandbox.measurement-lab.org.", | ||
}, | ||
{ | ||
name: "success", | ||
org: "mlab", | ||
project: "mlab-autojoin", | ||
want: "mlab.autojoin.measurement-lab.org.", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := OrgDNS(tt.org, tt.project); got != tt.want { | ||
t.Errorf("OrgDNS() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters