Files
terraform-provider-rancherv…/internal/provider/conversions_test.go
T
Ben Vincent c69b27826d Initial terraform-provider-ranchervaultsecret scaffold
Terraform provider (plugin-framework) for the vault-plugin-secrets-rancher
secrets engine, modeled on terraform-provider-litellmvaultsecret.

Resources:
- rancher_secret_backend: mount the engine + write config (rancher_url, ca_cert,
  tls_skip_verify, request_timeout_seconds).
- rancher_secret_backend_service_account: seed an auto-rotated Rancher token
  (write-only token; token_ttl / rotation_period; computed token_name,
  last_rotated).
- rancher_secret_backend_role: minting role (service_account, cluster_name,
  ttl, max_ttl, description).

Source address git.unkin.net/unkin/ranchervaultsecret, resources prefixed
rancher_. Ports the litellm Woodpecker terraform-registry release + nfpm-less
zip packaging, examples, and a provider e2e (Vault + mock Rancher from the
sibling plugin repo). Unit tests cover the coercion/import-ID helpers.
2026-07-15 22:20:03 +10:00

49 lines
1.2 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 TestSplitBackendName(t *testing.T) {
cases := []struct {
id, marker, backend, name string
ok bool
}{
{"rancher/roles/ci", "roles", "rancher", "ci", true},
{"team/rancher/service-accounts/admin", "service-accounts", "team/rancher", "admin", true},
{"rancher/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)
}
}
}