mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
8ff017b5e8
下游 OpenFlare 的边缘守护进程与发布流程需要这些与业务无关的纯函数, 按上游/下游归属规约回流到平台层,避免下游在上游目录里长期携带本地文件: - version / version_compare:CompareVersions、ParseVersionInfo(版本区间比较) - network:GetIP、IsPrivateIPv4 - format / value / string / slice:Bytes2Size、Seconds2Time、Interface2String、 TrimStringFields、UniqueAndCleanStringSlice 与 IdentifiableTimeRecord 验证:go build 通过;go test ./... exit 0(48 包 ok); check_cordis_architecture.sh 0 violations;golangci-lint 0 issues;gofmt 干净。
37 lines
780 B
Go
37 lines
780 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package util
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestIsPrivateIPv4(t *testing.T) {
|
|
tests := []struct {
|
|
ip string
|
|
expected bool
|
|
}{
|
|
{"127.0.0.1", false}, // Loopback is not in RFC 1918 private range
|
|
{"10.0.0.1", true},
|
|
{"172.16.0.1", true},
|
|
{"192.168.1.1", true},
|
|
{"8.8.8.8", false},
|
|
{"invalid-ip", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
result := isPrivateIPv4(tt.ip)
|
|
if result != tt.expected {
|
|
t.Errorf("isPrivateIPv4(%q) = %v, expected %v", tt.ip, result, tt.expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetIP(t *testing.T) {
|
|
ip := GetIP()
|
|
// GetIP should return empty if no private IPv4 address is configured, or a valid IP.
|
|
// We just ensure it doesn't panic.
|
|
t.Logf("GetIP returned: %q", ip)
|
|
}
|