Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make API not depend on SDK #18962

Merged
merged 10 commits into from
Feb 6, 2023
Prev Previous commit
Next Next commit
Still more plugin test fallout from moving plugin consts to api.
ncabatoff committed Feb 3, 2023

Verified

This commit was signed with the committer’s verified signature.
ndelangen Norbert de Langen
commit 594f24d11fa0c1fb948e6209e608ffae37b0435f
3 changes: 1 addition & 2 deletions command/auth_tune_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (
"github.com/go-test/deep"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/mitchellh/cli"
)

@@ -105,7 +104,7 @@ func TestAuthTuneCommand_Run(t *testing.T) {
t.Errorf("expected %q to be %q", mountInfo.PluginVersion, exp)
}

_, _, version := testPluginCreateAndRegisterVersioned(t, client, pluginDir, "userpass", consts.PluginTypeCredential)
_, _, version := testPluginCreateAndRegisterVersioned(t, client, pluginDir, "userpass", api.PluginTypeCredential)

code := cmd.Run([]string{
"-description", "new description",
14 changes: 7 additions & 7 deletions command/plugin_deregister_test.go
Original file line number Diff line number Diff line change
@@ -84,14 +84,14 @@ func TestPluginDeregisterCommand_Run(t *testing.T) {
defer closer()

pluginName := "my-plugin"
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, consts.PluginTypeCredential, "")
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, api.PluginTypeCredential, "")

ui, cmd := testPluginDeregisterCommand(t)
cmd.client = client

if err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{
Name: pluginName,
Type: consts.PluginTypeCredential,
Type: api.PluginTypeCredential,
Command: pluginName,
SHA256: sha256Sum,
}); err != nil {
@@ -113,7 +113,7 @@ func TestPluginDeregisterCommand_Run(t *testing.T) {
}

resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{
Type: consts.PluginTypeCredential,
Type: api.PluginTypeCredential,
})
if err != nil {
t.Fatal(err)
@@ -142,7 +142,7 @@ func TestPluginDeregisterCommand_Run(t *testing.T) {
defer closer()

pluginName := "my-plugin"
_, _, version := testPluginCreateAndRegisterVersioned(t, client, pluginDir, pluginName, consts.PluginTypeCredential)
_, _, version := testPluginCreateAndRegisterVersioned(t, client, pluginDir, pluginName, api.PluginTypeCredential)

ui, cmd := testPluginDeregisterCommand(t)
cmd.client = client
@@ -163,7 +163,7 @@ func TestPluginDeregisterCommand_Run(t *testing.T) {
}

resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{
Type: consts.PluginTypeUnknown,
Type: api.PluginTypeUnknown,
})
if err != nil {
t.Fatal(err)
@@ -190,7 +190,7 @@ func TestPluginDeregisterCommand_Run(t *testing.T) {
defer closer()

pluginName := "my-plugin"
testPluginCreateAndRegisterVersioned(t, client, pluginDir, pluginName, consts.PluginTypeCredential)
testPluginCreateAndRegisterVersioned(t, client, pluginDir, pluginName, api.PluginTypeCredential)

ui, cmd := testPluginDeregisterCommand(t)
cmd.client = client
@@ -210,7 +210,7 @@ func TestPluginDeregisterCommand_Run(t *testing.T) {
}

resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{
Type: consts.PluginTypeUnknown,
Type: api.PluginTypeUnknown,
})
if err != nil {
t.Fatal(err)
17 changes: 9 additions & 8 deletions command/plugin_info_test.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"strings"
"testing"

"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/helper/versions"
"github.com/hashicorp/vault/sdk/helper/consts"
@@ -38,7 +39,7 @@ func TestPluginInfoCommand_Run(t *testing.T) {
},
{
"no_plugin_exist",
[]string{consts.PluginTypeCredential.String(), "not-a-real-plugin-like-ever"},
[]string{api.PluginTypeCredential.String(), "not-a-real-plugin-like-ever"},
"Error reading plugin",
2,
},
@@ -82,13 +83,13 @@ func TestPluginInfoCommand_Run(t *testing.T) {
defer closer()

pluginName := "my-plugin"
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, consts.PluginTypeCredential, "")
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, api.PluginTypeCredential, "")

ui, cmd := testPluginInfoCommand(t)
cmd.client = client

code := cmd.Run([]string{
consts.PluginTypeCredential.String(), pluginName,
api.PluginTypeCredential.String(), pluginName,
})
if exp := 0; code != exp {
t.Errorf("expected %d to be %d", code, exp)
@@ -113,7 +114,7 @@ func TestPluginInfoCommand_Run(t *testing.T) {
defer closer()

const pluginName = "azure"
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, consts.PluginTypeCredential, "v1.0.0")
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, api.PluginTypeCredential, "v1.0.0")

for name, tc := range map[string]struct {
version string
@@ -128,7 +129,7 @@ func TestPluginInfoCommand_Run(t *testing.T) {

code := cmd.Run([]string{
"-version=" + tc.version,
consts.PluginTypeCredential.String(), pluginName,
api.PluginTypeCredential.String(), pluginName,
})

combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
@@ -159,14 +160,14 @@ func TestPluginInfoCommand_Run(t *testing.T) {
defer closer()

pluginName := "my-plugin"
testPluginCreateAndRegister(t, client, pluginDir, pluginName, consts.PluginTypeCredential, "")
testPluginCreateAndRegister(t, client, pluginDir, pluginName, api.PluginTypeCredential, "")

ui, cmd := testPluginInfoCommand(t)
cmd.client = client

code := cmd.Run([]string{
"-field", "builtin",
consts.PluginTypeCredential.String(), pluginName,
api.PluginTypeCredential.String(), pluginName,
})
if exp := 0; code != exp {
t.Errorf("expected %d to be %d", code, exp)
@@ -188,7 +189,7 @@ func TestPluginInfoCommand_Run(t *testing.T) {
cmd.client = client

code := cmd.Run([]string{
consts.PluginTypeCredential.String(), "my-plugin",
api.PluginTypeCredential.String(), "my-plugin",
})
if exp := 2; code != exp {
t.Errorf("expected %d to be %d", code, exp)
12 changes: 6 additions & 6 deletions command/plugin_register_test.go
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
}

resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{
Type: consts.PluginTypeCredential,
Type: api.PluginTypeCredential,
})
if err != nil {
t.Fatal(err)
@@ -138,7 +138,7 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
const pluginName = "my-plugin"
versions := []string{"v1.0.0", "v2.0.1"}
_, sha256Sum := testPluginCreate(t, pluginDir, pluginName)
types := []consts.PluginType{consts.PluginTypeCredential, consts.PluginTypeDatabase, consts.PluginTypeSecrets}
types := []api.PluginType{api.PluginTypeCredential, api.PluginTypeDatabase, api.PluginTypeSecrets}

for _, typ := range types {
for _, version := range versions {
@@ -164,17 +164,17 @@ func TestPluginRegisterCommand_Run(t *testing.T) {
}

resp, err := client.Sys().ListPlugins(&api.ListPluginsInput{
Type: consts.PluginTypeUnknown,
Type: api.PluginTypeUnknown,
})
if err != nil {
t.Fatal(err)
}

found := make(map[consts.PluginType]int)
versionsFound := make(map[consts.PluginType][]string)
found := make(map[api.PluginType]int)
versionsFound := make(map[api.PluginType][]string)
for _, p := range resp.Details {
if p.Name == pluginName {
typ, err := consts.ParsePluginType(p.Type)
typ, err := api.ParsePluginType(p.Type)
if err != nil {
t.Fatal(err)
}
5 changes: 2 additions & 3 deletions command/plugin_reload_test.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (

"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/mitchellh/cli"
)

@@ -90,14 +89,14 @@ func TestPluginReloadCommand_Run(t *testing.T) {
defer closer()

pluginName := "my-plugin"
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, consts.PluginTypeCredential, "")
_, sha256Sum := testPluginCreateAndRegister(t, client, pluginDir, pluginName, api.PluginTypeCredential, "")

ui, cmd := testPluginReloadCommand(t)
cmd.client = client

if err := client.Sys().RegisterPlugin(&api.RegisterPluginInput{
Name: pluginName,
Type: consts.PluginTypeCredential,
Type: api.PluginTypeCredential,
Command: pluginName,
SHA256: sha256Sum,
}); err != nil {
5 changes: 2 additions & 3 deletions command/plugin_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import (
"testing"

"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/sdk/helper/consts"
)

// testPluginCreate creates a sample plugin in a tempdir and returns the shasum
@@ -38,7 +37,7 @@ func testPluginCreate(tb testing.TB, dir, name string) (string, string) {
}

// testPluginCreateAndRegister creates a plugin and registers it in the catalog.
func testPluginCreateAndRegister(tb testing.TB, client *api.Client, dir, name string, pluginType consts.PluginType, version string) (string, string) {
func testPluginCreateAndRegister(tb testing.TB, client *api.Client, dir, name string, pluginType api.PluginType, version string) (string, string) {
tb.Helper()

pth, sha256Sum := testPluginCreate(tb, dir, name)
@@ -57,7 +56,7 @@ func testPluginCreateAndRegister(tb testing.TB, client *api.Client, dir, name st
}

// testPluginCreateAndRegisterVersioned creates a versioned plugin and registers it in the catalog.
func testPluginCreateAndRegisterVersioned(tb testing.TB, client *api.Client, dir, name string, pluginType consts.PluginType) (string, string, string) {
func testPluginCreateAndRegisterVersioned(tb testing.TB, client *api.Client, dir, name string, pluginType api.PluginType) (string, string, string) {
tb.Helper()

pth, sha256Sum := testPluginCreate(tb, dir, name)
3 changes: 1 addition & 2 deletions command/secrets_tune_test.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ import (
"github.com/go-test/deep"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/helper/testhelpers/corehelpers"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/mitchellh/cli"
)

@@ -179,7 +178,7 @@ func TestSecretsTuneCommand_Run(t *testing.T) {
t.Errorf("expected %q to be %q", mountInfo.PluginVersion, exp)
}

_, _, version := testPluginCreateAndRegisterVersioned(t, client, pluginDir, "pki", consts.PluginTypeSecrets)
_, _, version := testPluginCreateAndRegisterVersioned(t, client, pluginDir, "pki", api.PluginTypeSecrets)

code := cmd.Run([]string{
"-description", "new description",