986aecd28f
Model the provider on terraform-provider-giteavaultsecret, adjusting the schemas to the ghp engine (vault-plugin-secrets-ghp) so its mount, config, and roles can be managed declaratively. - Add provider (local name ghpvaultsecret, source git.unkin.net/unkin/ghpvaultsecret) with VAULT_ADDR/VAULT_TOKEN fallback. - Add ghpvaultsecret_secret_backend: mounts the engine and writes config (base_url, write-only admin_token, write-only ca_cert, tls_skip_verify, request_timeout_seconds); read never returns the sensitive fields. - Add ghpvaultsecret_secret_role: token_type, installation_id, app_record_id, repositories, scopes, session_prefix, ttl, max_ttl; validate that agent roles set installation_id. - Add unit tests for the value conversions and the role/backend field mapping. - Mirror the woodpecker pre-commit/build/test (PR) and tag release (package + PUT zip to the artifactapi terraform registry) pipelines, Makefile version bump/package targets, examples, README, and a Docker e2e harness.
70 lines
1.8 KiB
Go
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{}{"contents:read", "pull_requests:write"}, []string{"contents:read", "pull_requests:write"}},
|
|
{"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
|
|
}{
|
|
{"ghp/roles/ci", "roles", "ghp", "ci", true},
|
|
{"team/ghp/roles/ci", "roles", "team/ghp", "ci", true},
|
|
{"ghp/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)
|
|
}
|
|
}
|
|
}
|