Files
terraform-provider-giteavau…/internal/provider/conversions_test.go
T
unkinben 646fa0f840 Initial terraform-provider-giteavaultsecret
Add a Terraform provider that manages the Gitea token secrets engine
(vault-plugin-secrets-gitea) on Vault/OpenBao, so terraform-vault can drive
the engine's mount, config, and roles declaratively.

- add the provider (source git.unkin.net/unkin/giteavaultsecret, prefix gitea_)
- add gitea_secret_backend (mount + config with seeded admin credentials)
- add gitea_secret_backend_role (username, scopes list, ttls, token_name_prefix)
- add the Vault API client plumbing, conversions, and unit tests
- add examples, a real terraform+Vault+mock-Gitea e2e, and Woodpecker pipelines
  releasing the provider zip to the artifactapi terraform registry

Claude-Session: https://claude.ai/code/session_015ur3i7D2azsMAWTSVABApv
2026-07-27 00:55:09 +10:00

70 lines
1.8 KiB
Go

package provider
import (
"encoding/json"
"strings"
"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 TestToStringSlice(t *testing.T) {
cases := []struct {
name string
in interface{}
want []string
}{
{"nil", nil, []string{}},
{"string-slice", []string{"a", "b"}, []string{"a", "b"}},
{"iface-slice", []interface{}{"read:repository", "write:issue"}, []string{"read:repository", "write:issue"}},
{"mixed", []interface{}{"ok", 3, "two"}, []string{"ok", "two"}},
{"wrong-type", "notalist", []string{}},
}
for _, c := range cases {
got := toStringSlice(c.in)
if strings.Join(got, ",") != strings.Join(c.want, ",") {
t.Errorf("%s: toStringSlice(%v) = %v, want %v", c.name, c.in, got, c.want)
}
}
}
func TestSplitBackendName(t *testing.T) {
cases := []struct {
id, marker, backend, name string
ok bool
}{
{"gitea/roles/teabot", "roles", "gitea", "teabot", true},
{"team/gitea/roles/ci", "roles", "team/gitea", "ci", true},
{"gitea/roles/", "roles", "", "", false},
{"/roles/teabot", "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)
}
}
}