Files
terraform-provider-vault-se…/internal/provider/conversions_test.go
T
Ben Vincent bff97965a9
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
Initial terraform-provider-vault-secrets-netbox
Terraform/OpenBao-Vault provider that manages the vault-plugin-secrets-netbox
engine: netbox_secret_backend (mount + connection config incl. seeded admin
token) and netbox_secret_backend_role (per-user mint policy: write_enabled,
ttl/max_ttl). Framework + Vault API client mirrored from the ranchervaultsecret
provider. Unit tests for conversions/import parsing; tag-driven zip release to
the artifactapi terraform-unkin registry.

Claude-Session: https://claude.ai/code/session_01JUoARVdmhxKQHyyyp1pxeT
2026-08-08 20:09:28 +10:00

58 lines
1.4 KiB
Go

package provider
import (
"encoding/json"
"testing"
)
func TestToInt64(t *testing.T) {
cases := []struct {
in interface{}
want int64
ok bool
}{
{json.Number("42"), 42, true},
{json.Number("3.0"), 3, true},
{float64(7), 7, true},
{int(9), 9, true},
{int64(11), 11, true},
{"nope", 0, false},
{nil, 0, false},
}
for _, c := range cases {
got, ok := toInt64(c.in)
if ok != c.ok || got != c.want {
t.Errorf("toInt64(%v) = (%d,%v), want (%d,%v)", c.in, got, ok, c.want, c.ok)
}
}
}
func TestToBool(t *testing.T) {
if b, ok := toBool(true); !ok || !b {
t.Errorf("toBool(true) = (%v,%v), want (true,true)", b, ok)
}
if _, ok := toBool("no"); ok {
t.Error("toBool(string) should not be ok")
}
}
func TestSplitBackendName(t *testing.T) {
cases := []struct {
id, marker, backend, name string
ok bool
}{
{"netbox/roles/ci", "roles", "netbox", "ci", true},
{"team/netbox/roles/puppet-facts", "roles", "team/netbox", "puppet-facts", true},
{"netbox/roles/", "roles", "", "", false},
{"/roles/ci", "roles", "", "", false},
{"nomarker", "roles", "", "", false},
}
for _, c := range cases {
b, n, ok := splitBackendName(c.id, c.marker)
if ok != c.ok || b != c.backend || n != c.name {
t.Errorf("splitBackendName(%q,%q) = (%q,%q,%v), want (%q,%q,%v)",
c.id, c.marker, b, n, ok, c.backend, c.name, c.ok)
}
}
}