pkg/plugins: TestGet(): use sub-tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-19 02:01:32 +02:00
parent e1ad4aa002
commit 0f7bf67f83
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -64,27 +64,33 @@ func TestGet(t *testing.T) {
p.Manifest = &Manifest{Implements: []string{fruitImplements}}
storage.plugins[fruitPlugin] = p
plugin, err := Get(fruitPlugin, fruitImplements)
if err != nil {
t.Fatal(err)
}
if p.Name() != plugin.Name() {
t.Fatalf("No matching plugin with name %s found", plugin.Name())
}
if plugin.Client() != nil {
t.Fatal("expected nil Client but found one")
}
if !plugin.IsV1() {
t.Fatal("Expected true for V1 plugin")
}
t.Run("success", func(t *testing.T) {
plugin, err := Get(fruitPlugin, fruitImplements)
if err != nil {
t.Fatal(err)
}
if p.Name() != plugin.Name() {
t.Errorf("no matching plugin with name %s found", plugin.Name())
}
if plugin.Client() != nil {
t.Error("expected nil Client but found one")
}
if !plugin.IsV1() {
t.Error("Expected true for V1 plugin")
}
})
// check negative case where plugin fruit doesn't implement banana
_, err = Get("fruit", "banana")
assert.Assert(t, errors.Is(err, ErrNotImplements))
t.Run("not implemented", func(t *testing.T) {
_, err := Get("fruit", "banana")
assert.Assert(t, errors.Is(err, ErrNotImplements))
})
// check negative case where plugin vegetable doesn't exist
_, err = Get("vegetable", "potato")
assert.Assert(t, errors.Is(err, ErrNotFound))
t.Run("not exists", func(t *testing.T) {
_, err := Get("vegetable", "potato")
assert.Assert(t, errors.Is(err, ErrNotFound))
})
}
func TestPluginWithNoManifest(t *testing.T) {