Skip to content

Commit

Permalink
tools: skip contract date rendering, small CI fixups. (#1812)
Browse files Browse the repository at this point in the history
Fixes #1806
  • Loading branch information
cpu authored Aug 2, 2023
1 parent 4e6c53c commit c6d22c8
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 89 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ permissions:

jobs:
make-test:
name: make test
name: Unit tests
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 'stable'

- name: Run Go unit tests
run: go test tools/*.go

- name: Install dependencies
run: sudo apt install -y autopoint

- name: Run test
- name: Run makefile tests
run: make test
3 changes: 1 addition & 2 deletions .github/workflows/tld-update.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Put this automation on hold, until it is able to ignore changes that only update the header timestamp.
name: tld-update
on:
workflow_dispatch:
Expand All @@ -17,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '^1.15'
go-version: 'stable'

- name: Run unit tests
run: go test tools/*.go
Expand Down
21 changes: 7 additions & 14 deletions tools/newgtlds.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ type pslEntry struct {
// RegistryOperator holds the name of the registry operator that operates the
// gTLD (may be empty).
RegistryOperator string
// DateOfContractSignature holds the date the gTLD contract was signed (may be empty).
DateOfContractSignature string
// ContractTerminated indicates whether the contract has been terminated by
// ICANN. When rendered by the pslTemplate only entries with
// ContractTerminated = false are included.
Expand All @@ -118,7 +116,6 @@ func (e *pslEntry) normalize() {
e.ALabel = strings.TrimSpace(e.ALabel)
e.ULabel = strings.TrimSpace(e.ULabel)
e.RegistryOperator = strings.TrimSpace(e.RegistryOperator)
e.DateOfContractSignature = strings.TrimSpace(e.DateOfContractSignature)

// If there is no explicit uLabel use the gTLD as the uLabel.
if e.ULabel == "" {
Expand All @@ -131,23 +128,19 @@ func (e *pslEntry) normalize() {
//
// If the registry operator field is empty the comment will be of the form:
//
// '// <ALabel> : <DateOfContractSignature>'
// '// <ALabel>
//
// If the registry operator field is not empty the comment will be of the form:
//
// '// <ALabel> : <DateOfContractSignature> <RegistryOperator>'
//
// In both cases the <DateOfContractSignature> may be empty.
// '// <ALabel> : <RegistryOperator>'
func (e pslEntry) Comment() string {
parts := []string{
"//",
e.ALabel,
":",
e.DateOfContractSignature,
}
// Avoid two trailing spaces if registry operator is empty
if e.RegistryOperator != "" {
parts = append(parts, e.RegistryOperator)
parts = append(parts, []string{":", e.RegistryOperator}...)
}
return strings.Join(parts, " ")
}
Expand Down Expand Up @@ -365,10 +358,10 @@ func filterGTLDs(entries []*pslEntry) []*pslEntry {
}

// getPSLEntries fetches a list of pslEntry objects (or returns an error) by:
// 1. getting the raw JSON data from the provided url string.
// 2. unmarshaling the JSON data to create pslEntry objects.
// 3. normalizing the pslEntry objects.
// 4. filtering out any legacy or contract terminated gTLDs
// 1. getting the raw JSON data from the provided url string.
// 2. unmarshaling the JSON data to create pslEntry objects.
// 3. normalizing the pslEntry objects.
// 4. filtering out any legacy or contract terminated gTLDs
//
// If there are no pslEntry objects after unmarshaling the data in step 2 or
// filtering the gTLDs in step 4 it is considered an error condition.
Expand Down
121 changes: 50 additions & 71 deletions tools/newgtlds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,41 @@ func TestEntryNormalize(t *testing.T) {
{
name: "already normalized",
inputEntry: pslEntry{
ALabel: "cpu",
ULabel: "cpu",
DateOfContractSignature: "2019-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "cpu",
ULabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
expectedEntry: pslEntry{
ALabel: "cpu",
ULabel: "cpu",
DateOfContractSignature: "2019-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "cpu",
ULabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
},
{
name: "extra whitespace",
inputEntry: pslEntry{
ALabel: " cpu ",
ULabel: " cpu ",
DateOfContractSignature: " 2019-06-13 ",
ALabel: " cpu ",
ULabel: " cpu ",
RegistryOperator: " @cpu's bargain gTLD emporium " +
"(now with bonus whitespace) ",
},
expectedEntry: pslEntry{
ALabel: "cpu",
ULabel: "cpu",
DateOfContractSignature: "2019-06-13",
ALabel: "cpu",
ULabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium " +
"(now with bonus whitespace)",
},
},
{
name: "no explicit uLabel",
inputEntry: pslEntry{
ALabel: "cpu",
DateOfContractSignature: "2019-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
expectedEntry: pslEntry{
ALabel: "cpu",
ULabel: "cpu",
DateOfContractSignature: "2019-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "cpu",
ULabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
},
}
Expand All @@ -89,26 +83,25 @@ func TestEntryComment(t *testing.T) {
{
name: "Full entry",
entry: pslEntry{
ALabel: "cpu",
DateOfContractSignature: "2019-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
expected: "// cpu : 2019-06-13 @cpu's bargain gTLD emporium",
expected: "// cpu : @cpu's bargain gTLD emporium",
},
{
name: "Entry with empty contract signature date and operator",
name: "Entry without operator",
entry: pslEntry{
ALabel: "cpu",
},
expected: "// cpu : ",
expected: "// cpu",
},
{
name: "Entry with empty contract signature and non-empty operator",
name: "Entry with non-empty operator",
entry: pslEntry{
ALabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
expected: "// cpu : @cpu's bargain gTLD emporium",
expected: "// cpu : @cpu's bargain gTLD emporium",
},
}

Expand Down Expand Up @@ -162,29 +155,25 @@ func TestGetPSLEntries(t *testing.T) {
}{
GTLDs: []pslEntry{
{
ALabel: "ceepeeyou",
DateOfContractSignature: "2099-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "ceepeeyou",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
{
// NOTE: we include whitespace in this entry to test that normalization
// occurs.
ALabel: " cpu ",
ULabel: " cpu ",
DateOfContractSignature: " 2019-06-13 ",
ALabel: " cpu ",
ULabel: " cpu ",
RegistryOperator: " @cpu's bargain gTLD emporium " +
"(now with bonus whitespace) ",
},
{
// NOTE: we include a legacy gTLD here to test that filtering of legacy
// gTLDs occurs.
ALabel: "aero",
DateOfContractSignature: "1999-10-31",
RegistryOperator: "Department of Historical Baggage and Technical Debt",
ALabel: "aero",
RegistryOperator: "Department of Historical Baggage and Technical Debt",
},
{
ALabel: "terminated",
DateOfContractSignature: "1987-10-31",
ALabel: "terminated",
// NOTE: we include a contract terminated = true entry here to test that
// filtering of terminated entries occurs.
ContractTerminated: true,
Expand All @@ -197,15 +186,13 @@ func TestGetPSLEntries(t *testing.T) {

expectedEntries := []pslEntry{
{
ALabel: "ceepeeyou",
ULabel: "ceepeeyou",
DateOfContractSignature: "2099-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "ceepeeyou",
ULabel: "ceepeeyou",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
{
ALabel: "cpu",
ULabel: "cpu",
DateOfContractSignature: "2019-06-13",
ALabel: "cpu",
ULabel: "cpu",
RegistryOperator: "@cpu's bargain gTLD emporium " +
"(now with bonus whitespace)",
},
Expand Down Expand Up @@ -265,21 +252,18 @@ func TestGetPSLEntriesEmptyFilteredResults(t *testing.T) {
GTLDs: []pslEntry{
{
// NOTE: GTLD matches a legacyGTLDs map entry to ensure filtering.
ALabel: "aero",
DateOfContractSignature: "1999-10-31",
RegistryOperator: "Department of Historical Baggage and Technical Debt",
ALabel: "aero",
RegistryOperator: "Department of Historical Baggage and Technical Debt",
},
{
ALabel: "terminated",
DateOfContractSignature: "1987-10-31",
ALabel: "terminated",
// NOTE: Setting ContractTerminated to ensure filtering.
ContractTerminated: true,
},
{
ALabel: "removed",
DateOfContractSignature: "1999-10-31",
RegistryOperator: "Department of Historical Baggage and Technical Debt",
RemovalDate: "2019-08-06",
ALabel: "removed",
RegistryOperator: "Department of Historical Baggage and Technical Debt",
RemovalDate: "2019-08-06",
},
},
}
Expand All @@ -301,22 +285,20 @@ func TestGetPSLEntriesEmptyFilteredResults(t *testing.T) {
func TestRenderData(t *testing.T) {
entries := []*pslEntry{
{
ALabel: "ceepeeyou",
ULabel: "ceepeeyou",
DateOfContractSignature: "2099-06-13",
RegistryOperator: "@cpu's bargain gTLD emporium",
ALabel: "ceepeeyou",
ULabel: "ceepeeyou",
RegistryOperator: "@cpu's bargain gTLD emporium",
},
{
ALabel: "cpu",
ULabel: "cpu",
DateOfContractSignature: "2019-06-13",
ALabel: "cpu",
ULabel: "cpu",
},
}

expectedList := `// ceepeeyou : 2099-06-13 @cpu's bargain gTLD emporium
expectedList := `// ceepeeyou : @cpu's bargain gTLD emporium
ceepeeyou
// cpu : 2019-06-13
// cpu
cpu
`
Expand Down Expand Up @@ -675,7 +657,7 @@ func TestProcess(t *testing.T) {
// List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2021-02-07T13:25:56-05:00
// This list is auto-generated, don't edit it manually.
// aaa : 2015-02-26 American Automobile Association, Inc.
// aaa : American Automobile Association, Inc.
aaa
Expand All @@ -688,7 +670,6 @@ aaa
"gTLDs": [
{
"contractTerminated": false,
"dateOfContractSignature": "2015-02-26",
"gTLD": "aaa",
"registryOperator": "American Automobile Association, Inc.",
"removalDate": null,
Expand All @@ -703,15 +684,13 @@ aaa
"gTLDs": [
{
"contractTerminated": false,
"dateOfContractSignature": "2015-02-26",
"gTLD": "aaa",
"registryOperator": "American Automobile Association, Inc.",
"removalDate": null,
"uLabel": null
},
{
"contractTerminated": false,
"dateOfContractSignature": "2014-03-20",
"gTLD": "accountants",
"registryOperator": "Binky Moon, LLC",
"removalDate": null,
Expand All @@ -731,10 +710,10 @@ aaa
// List of new gTLDs imported from https://www.icann.org/resources/registries/gtlds/v2/gtlds.json on 2021-02-10T00:24:14Z
// This list is auto-generated, don't edit it manually.
// aaa : 2015-02-26 American Automobile Association, Inc.
// aaa : American Automobile Association, Inc.
aaa
// accountants : 2014-03-20 Binky Moon, LLC
// accountants : Binky Moon, LLC
accountants
Expand Down

0 comments on commit c6d22c8

Please sign in to comment.