Private
Public Access
feat: initial Go/JS/Rust Origin check-in client SDKs
CI / rust (push) Successful in 3m6s
CI / go (push) Successful in 33s
CI / js (push) Successful in 34s
CI / rust (push) Successful in 3m6s
CI / go (push) Successful in 33s
CI / js (push) Successful in 34s
Standalone clients that resolve a machine unique ID (OS machine ID first, falling back to a generated UUID persisted to disk), detect hostname/IP/ container/orchestrator, and register+re-ping origin.warky.dev's public service-checkin endpoint on a daily interval. Ported from icy2's internal origincheckin package but extended to the full check-in contract and made dependency-light for external reuse. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package originclient
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseCgroupContainerID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
data string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "cgroup v1 docker path",
|
||||
data: "12:memory:/docker/9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b\n",
|
||||
want: "9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b",
|
||||
},
|
||||
{
|
||||
name: "cgroup v2 systemd scope",
|
||||
data: "0::/system.slice/docker-9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b.scope\n",
|
||||
want: "9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b",
|
||||
},
|
||||
{
|
||||
name: "non-container host",
|
||||
data: "0::/user.slice/user-1000.slice/session-2.scope\n",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
data: "",
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.want, parseCgroupContainerID([]byte(tc.data)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsContainerIDLike(t *testing.T) {
|
||||
assert.True(t, isContainerIDLike("9f8b7c6d5e4f"))
|
||||
assert.False(t, isContainerIDLike("short"))
|
||||
assert.False(t, isContainerIDLike("session-2"))
|
||||
assert.False(t, isContainerIDLike(""))
|
||||
}
|
||||
|
||||
func TestOrchestrator_Kubernetes(t *testing.T) {
|
||||
t.Setenv("KUBERNETES_SERVICE_HOST", "10.0.0.1")
|
||||
assert.Equal(t, "kubernetes", Orchestrator())
|
||||
}
|
||||
|
||||
func TestHostname_NotEmpty(t *testing.T) {
|
||||
assert.NotEmpty(t, Hostname())
|
||||
}
|
||||
Reference in New Issue
Block a user