File: api_test.go

package info (click to toggle)
pat 0.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,296 kB
  • sloc: javascript: 3,891; sh: 124; makefile: 11
file content (41 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download
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
34
35
36
37
38
39
40
41
// Copyright 2023 Martin Hebnes Pedersen (LA5NTA). All rights reserved.
// Use of this source code is governed by the MIT-license that can be
// found in the LICENSE file.

package cmsapi

import (
	"encoding/json"
	"testing"
)

func TestGetGatewayStatusEmbedded(t *testing.T) {
	// Get the embedded gateway status
	reader, err := getGatewayStatusEmbedded()
	if err != nil {
		t.Fatalf("Failed to get embedded gateway status: %v", err)
	}
	defer reader.Close()

	// Unmarshal into GatewayStatus struct
	var status GatewayStatus
	if err := json.NewDecoder(reader).Decode(&status); err != nil {
		t.Fatalf("Failed to unmarshal gateway status data: %v", err)
	}

	// Check that Gateways slice is not empty
	if len(status.Gateways) == 0 {
		t.Error("Gateway status contains empty Gateways slice")
	}

	// Test at least one gateway has valid data
	if len(status.Gateways) > 0 {
		gateway := status.Gateways[0]
		if gateway.Callsign == "" {
			t.Error("First gateway has empty Callsign")
		}
		if gateway.Latitude == 0 && gateway.Longitude == 0 {
			t.Error("First gateway has invalid coordinates (0,0)")
		}
	}
}