add very basic tests and action

includes action for build. plus tests, fmt and vet
This commit is contained in:
Enot (ded) Skelly committed 2026-06-05 10:26:49 -07:00
1 parent d9a641b99c
commit 9a1b1d27ee
2 files changed
+145

No files matched your search

+35
View File
@@ -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 ./...
+110
View File
@@ -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")
}
}