gokeenrestapi

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InterfaceTypeWireguard = "Wireguard"
	InterfaceTypePPPoE     = "PPPoE"
)

Interface types

View Source
const (
	StateUp           = "up"
	StateDown         = "down"
	StateConnected    = "yes"
	StateDisconnected = "no"
)

Connection states

View Source
const (
	StatusOK    = "ok"
	StatusError = "error"
)

Parse status

Variables

View Source
var (
	// AwgConf provides WireGuard (AWG) configuration management functionality
	AwgConf keeneticAwgconf
)
View Source
var (
	// Checks provides validation functions for router interface and configuration checks
	Checks = checks{}
)
View Source
var (

	// Common provides core API functionality for authentication and router communication
	Common keeneticCommon
)
View Source
var (
	Components keeneticComponents
)
View Source
var (
	// DnsRouting provides DNS-routing functionality for domain-based routing policies
	DnsRouting keeneticDnsRouting
)
View Source
var (
	// Interface provides network interface management functionality for the router
	Interface keeneticInterface
)
View Source
var (

	// Ip provides IP-related functionality including routing, DNS, and host management
	Ip keeneticIp
)

Functions

func NewMockRouterServer added in v1.6.0

func NewMockRouterServer(opts ...MockRouterOption) *httptest.Server

NewMockRouterServer creates an httptest.Server with the mock router It registers all endpoint handlers and returns a test server ready for use

func SetupMockRouterForTest added in v1.6.0

func SetupMockRouterForTest(opts ...MockRouterOption) *httptest.Server

SetupMockRouterForTest is a convenience function for test suites with default config. It creates a mock server and automatically configures the global API client to use it. This is the recommended way to set up mock servers in tests.

func SetupTestConfig added in v1.2.1

func SetupTestConfig(serverURL string)

SetupTestConfig configures the global API client for testing with the given server URL. This is a test helper that encapsulates the necessary global state mutation.

Note: This function modifies global state (config.Cfg and restyClient) which is necessary for the current API client architecture. Tests should call this after creating a mock server.

Types

type MockAllowedIP added in v1.6.0

type MockAllowedIP struct {
	Address string
	Mask    string
}

MockAllowedIP represents an allowed IP range for a WireGuard peer

type MockAsc added in v1.6.0

type MockAsc struct {
	Jc   string
	Jmin string
	Jmax string
	S1   string
	S2   string
	H1   string
	H2   string
	H3   string
	H4   string
}

MockAsc represents AWG (Amnezia WireGuard) configuration parameters

type MockDnsProxyRoute added in v1.6.0

type MockDnsProxyRoute struct {
	GroupName   string
	InterfaceID string
	Mode        string // typically "auto"
}

MockDnsProxyRoute represents a dns-proxy route in the mock router

type MockDnsRoutingGroup added in v1.6.0

type MockDnsRoutingGroup struct {
	Name    string
	Domains []string
}

MockDnsRoutingGroup represents a DNS-routing object-group in the mock router

type MockHost added in v1.6.0

type MockHost struct {
	Name       string
	Mac        string
	IP         string
	Hostname   string
	Registered bool
	Link       string
	Via        string
}

MockHost represents a device connected to the router (hotspot)

type MockIP added in v1.6.0

type MockIP struct {
	Address string
}

MockIP represents IP configuration for SC interfaces

type MockInterface added in v1.6.0

type MockInterface struct {
	ID          string
	Type        string
	Description string
	Address     string
	Connected   string
	Link        string
	State       string
	DefaultGw   bool
}

MockInterface represents a network interface in the mock router

type MockPeer added in v1.6.0

type MockPeer struct {
	Key               string
	Comment           string
	Endpoint          string
	KeepaliveInterval int
	PresharedKey      string
	AllowedIPs        []MockAllowedIP
}

MockPeer represents a WireGuard peer configuration

type MockRoute added in v1.6.0

type MockRoute struct {
	Network   string
	Host      string
	Mask      string
	Interface string
	Auto      bool
}

MockRoute represents a static route in the mock router

type MockRouter added in v1.6.0

type MockRouter struct {
	// contains filtered or unexported fields
}

MockRouter is a comprehensive mock implementation of the Keenetic router API It maintains stateful behavior and supports all API endpoints for testing

func NewMockRouter added in v1.6.0

func NewMockRouter(opts ...MockRouterOption) *MockRouter

NewMockRouter creates a new mock router with default state and optional configuration

func (*MockRouter) GetState added in v1.6.0

func (m *MockRouter) GetState() MockRouterState

GetState returns a snapshot of the current mock state (for test assertions)

func (*MockRouter) ResetState added in v1.6.0

func (m *MockRouter) ResetState()

ResetState resets the mock to its initial state

type MockRouterOption added in v1.6.0

type MockRouterOption func(*MockRouter)

MockRouterOption is a functional option for configuring the mock router

func WithDNSRecords added in v1.6.0

func WithDNSRecords(records map[string]string) MockRouterOption

WithDNSRecords sets custom initial DNS records for the mock router

func WithDnsRoutingGroups added in v1.6.0

func WithDnsRoutingGroups(groups []MockDnsRoutingGroup, routes []MockDnsProxyRoute) MockRouterOption

WithDnsRoutingGroups sets custom initial DNS-routing groups for the mock router

func WithHotspotDevices added in v1.6.0

func WithHotspotDevices(devices []MockHost) MockRouterOption

WithHotspotDevices sets custom initial hotspot devices for the mock router

func WithInterfaces added in v1.6.0

func WithInterfaces(interfaces []MockInterface) MockRouterOption

WithInterfaces sets custom initial interfaces for the mock router

func WithRoutes added in v1.6.0

func WithRoutes(routes []MockRoute) MockRouterOption

WithRoutes sets custom initial routes for the mock router

func WithScInterfaces added in v1.6.0

func WithScInterfaces(scInterfaces map[string]MockScInterface) MockRouterOption

WithScInterfaces sets custom initial SC interfaces for the mock router

func WithStaticRunningConfig added in v1.6.0

func WithStaticRunningConfig(lines []string) MockRouterOption

WithStaticRunningConfig sets static running config lines (overrides generated config)

func WithSystemMode added in v1.6.0

func WithSystemMode(mode MockSystemMode) MockRouterOption

WithSystemMode sets custom system mode for the mock router

func WithVersion added in v1.6.0

func WithVersion(version string) MockRouterOption

WithVersion sets custom firmware version for the mock router

type MockRouterState added in v1.6.0

type MockRouterState struct {
	Interfaces       map[string]*MockInterface
	ScInterfaces     map[string]*MockScInterface
	Routes           []MockRoute
	DNSRecords       map[string]string
	HotspotDevices   []MockHost
	SystemMode       MockSystemMode
	DnsRoutingGroups []MockDnsRoutingGroup
	DnsProxyRoutes   []MockDnsProxyRoute
}

MockRouterState represents a snapshot of the mock router's state

type MockScInterface added in v1.6.0

type MockScInterface struct {
	Description string
	IP          MockIP
	Wireguard   MockWireguard
}

MockScInterface represents the SC (system configuration) view of an interface

type MockSystemMode added in v1.6.0

type MockSystemMode struct {
	Active   string
	Selected string
}

MockSystemMode represents the system mode configuration

type MockWireguard added in v1.6.0

type MockWireguard struct {
	Asc  MockAsc
	Peer []MockPeer
}

MockWireguard represents WireGuard configuration for SC interfaces

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL