summaryrefslogtreecommitdiff
path: root/lex-serve/data_test.go
blob: 7093b9ff13477e8112a98549690caa60e6a5210f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
	"bytes"
	"os"
	"slices"
	"strings"
	"testing"

	"github.com/BurntSushi/toml"
)

func TestCountryCodesAreInCCTLDs(t *testing.T) {
	countries := map[string]country{}
	_, err := toml.NewDecoder(bytes.NewReader(countriesTOML)).Decode(&countries)
	if err != nil {
		t.Fatalf("failed to parse countries.toml: %s", err)
	}

	if err != nil {
		t.Fatalf("expected no error, got %s", err)
	}
	tldBytes, err := os.ReadFile("../cc-tlds.txt")
	if err != nil {
		t.Fatalf("expected no error, got %s", err)
	}
	ccTLDs := strings.Split(string(tldBytes), "\n")
	for code, _ := range countries {
		if !slices.Contains(ccTLDs, code) {
			t.Fatalf("expected country code (%s) defined in countries.toml to also be in cc-tlds.txt", code)
		}
	}
}