Files
threshold/internal/plugin/testing.go
T
Johan Brandhorst-Satzkorn 7f9b294a7e refact(all): Use testing.TB for test helpers
Our test helper packages were not possible to use
with benchmarks. This refactor switches to testing.TB
to allow both tests and benchmarks to use the helpers.
2022-04-29 16:33:44 -04:00

55 lines
1.2 KiB
Go

package plugin
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/plugin/store"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/require"
)
// A typeless plugin used for tests.
type plugin struct {
*store.Plugin
tableName string `gorm:"-"`
}
// newPlugin is used in tests and creates a typeless plugin in the global scope.
func newPlugin(name string) *plugin {
p := &plugin{
Plugin: &store.Plugin{
ScopeId: scope.Global.String(),
Name: name,
},
}
return p
}
// TableName returns the table name for the host plugin.
func (c *plugin) TableName() string {
if c.tableName != "" {
return c.tableName
}
return "plugin"
}
// SetTableName sets the table name. If the caller attempts to
// set the name to "" the name will be reset to the default name.
func (c *plugin) SetTableName(n string) {
c.tableName = n
}
func testPlugin(t testing.TB, conn *db.DB, name string) *plugin {
t.Helper()
p := newPlugin(name)
id, err := db.NewPublicId("plg")
require.NoError(t, err)
p.PublicId = id
w := db.New(conn)
require.NoError(t, w.Create(context.Background(), p))
return p
}