mirror of
https://github.com/hanzozt/sdk-golang.git
synced 2026-10-30 14:46:37 +00:00
Add three new packages for ZT SDK integration: - zap/: ZAP transport adapter with 4-byte length-prefix framing over ZT connections - auth/hanzo/: Hanzo IAM JWT credential resolution (env + auth file) - billing/: Commerce API billing guard with balance check and usage recording (no free tier)
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package hanzo
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestFromToken(t *testing.T) {
|
|
creds := FromToken("test-token-123")
|
|
if creds.Token != "test-token-123" {
|
|
t.Errorf("expected token 'test-token-123', got '%s'", creds.Token)
|
|
}
|
|
if creds.AuthMethod() != "ext-jwt" {
|
|
t.Errorf("expected auth method 'ext-jwt', got '%s'", creds.AuthMethod())
|
|
}
|
|
}
|
|
|
|
func TestResolveFromEnv(t *testing.T) {
|
|
os.Setenv("HANZO_API_KEY", "test-env-key")
|
|
defer os.Unsetenv("HANZO_API_KEY")
|
|
|
|
creds, err := Resolve()
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if creds.Token != "test-env-key" {
|
|
t.Errorf("expected token 'test-env-key', got '%s'", creds.Token)
|
|
}
|
|
}
|
|
|
|
func TestDisplay(t *testing.T) {
|
|
creds := &JwtCredentials{Token: "my-long-secret-token", Email: "[email protected]"}
|
|
display := creds.Display()
|
|
if display != "Hanzo IAM ([email protected])" {
|
|
t.Errorf("unexpected display: %s", display)
|
|
}
|
|
|
|
creds2 := &JwtCredentials{Token: "my-long-secret-token"}
|
|
display2 := creds2.Display()
|
|
if display2 != "Hanzo API key (...token)" {
|
|
t.Errorf("unexpected display: %s", display2)
|
|
}
|
|
}
|