From 9a1b1d27ee0073d1f004e86ad15c982f2e225efd Mon Sep 17 00:00:00 2001 From: "Enot (ded) Skelly" Date: Fri, 5 Jun 2026 10:26:49 -0700 Subject: [PATCH] add very basic tests and action includes action for build. plus tests, fmt and vet --- .github/workflows/ci.yml | 35 +++++++++++ internal/iatadb/iatadb_test.go | 110 +++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 internal/iatadb/iatadb_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e7d62e8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Build + run: go build ./... + + - name: Format check + run: | + if [ -n "$(gofmt -l .)" ]; then + echo "The following files are not formatted:" + gofmt -l . + exit 1 + fi + + - name: Vet + run: go vet ./... + + - name: Test + run: go test ./... diff --git a/internal/iatadb/iatadb_test.go b/internal/iatadb/iatadb_test.go new file mode 100644 index 0000000..161cf22 --- /dev/null +++ b/internal/iatadb/iatadb_test.go @@ -0,0 +1,110 @@ +package iatadb_test + +import ( + "testing" + + "github.com/MeshCore-Beacon/beacon-server/internal/iatadb" +) + +func TestLookup_KnownIATA(t *testing.T) { + entry, ok := iatadb.Lookup("YVR") + if !ok { + t.Fatal("expected YVR to be found") + } + if entry.Country != "CA" { + t.Errorf("expected country CA, got %s", entry.Country) + } + if entry.Continent != "NA" { + t.Errorf("expected continent NA, got %s", entry.Continent) + } +} + +func TestLookup_UnknownIATA(t *testing.T) { + entry, ok := iatadb.Lookup("ZZZZZ") + if ok { + t.Fatal("expected ZZZZZ not to be found") + } + if entry.Country != "" { + t.Errorf("expected country to be empty, got %s", entry.Country) + } + if entry.Continent != "" { + t.Errorf("expected continent to be empty, got %s", entry.Continent) + } +} + +func TestCountryFor_Known(t *testing.T) { + country := iatadb.CountryFor("YVR") + if country != "CA" { + t.Fatalf("expected country for YVR to be CA, got %s", country) + } +} + +func TestCountryFor_Unknown(t *testing.T) { + country := iatadb.CountryFor("ZZZZZ") + if country != "" { + t.Fatalf("expected no country for IATA ZZZZZ, got %s", country) + } +} + +func TestContinentFor_Known(t *testing.T) { + continent := iatadb.ContinentFor("YVR") + if continent != "NA" { + t.Fatalf("expected continent for YVR to be NA, got %s", continent) + } +} + +func TestContinentFor_Unknown(t *testing.T) { + continent := iatadb.ContinentFor("ZZZZZ") + if continent != "" { + t.Fatalf("expected no continient for IATA ZZZZZ, got %s", continent) + } +} + +func TestBuildAllowedSet_Empty(t *testing.T) { + result := iatadb.BuildAllowedSet(nil, nil) + if result != nil { + t.Error("expected nil for empty filter") + } +} + +func TestBuildAllowedSet_ByCountry(t *testing.T) { + allowed := iatadb.BuildAllowedSet([]string{"CA"}, nil) + if allowed == nil { + t.Fatal("expected non-nil result") + } + if _, ok := allowed["YVR"]; !ok { + t.Error("expected YVR to be allowed") + } + if _, ok := allowed["JFK"]; ok { + t.Error("expected JFK to be excluded") + } +} + +func TestBuildAllowedSet_ByContinent(t *testing.T) { + allowed := iatadb.BuildAllowedSet(nil, []string{"NA"}) + if allowed == nil { + t.Fatal("expected non-nil result") + } + if _, ok := allowed["YVR"]; !ok { + t.Error("expected YVR to be allowed") + } + if _, ok := allowed["LHR"]; ok { + t.Error("expected LHR (EU) to be excluded") + } +} + +func TestBuildAllowedSet_ORSemantics(t *testing.T) { + allowed := iatadb.BuildAllowedSet([]string{"CA"}, []string{"EU"}) + if allowed == nil { + t.Fatal("expected non-nil result") + } + if _, ok := allowed["YVR"]; !ok { + t.Error("expected YVR (CA) to be allowed") + } + if _, ok := allowed["LHR"]; !ok { + t.Error("expected LHR (EU) to be allowed") + } + if _, ok := allowed["GRU"]; ok { + t.Error("expected GRU (SA/BR) to be excluded") + } +}