mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-23 00:41:29 +00:00
add very basic tests and action
includes action for build. plus tests, fmt and vet
This commit is contained in:
2 files changed
+145
No files matched your search
@@ -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 ./...
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user