Browse code

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

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/07/19 09:01:32
Showing 1 changed files
... ...
@@ -64,27 +64,33 @@ func TestGet(t *testing.T) {
64 64
 	p.Manifest = &Manifest{Implements: []string{fruitImplements}}
65 65
 	storage.plugins[fruitPlugin] = p
66 66
 
67
-	plugin, err := Get(fruitPlugin, fruitImplements)
68
-	if err != nil {
69
-		t.Fatal(err)
70
-	}
71
-	if p.Name() != plugin.Name() {
72
-		t.Fatalf("No matching plugin with name %s found", plugin.Name())
73
-	}
74
-	if plugin.Client() != nil {
75
-		t.Fatal("expected nil Client but found one")
76
-	}
77
-	if !plugin.IsV1() {
78
-		t.Fatal("Expected true for V1 plugin")
79
-	}
67
+	t.Run("success", func(t *testing.T) {
68
+		plugin, err := Get(fruitPlugin, fruitImplements)
69
+		if err != nil {
70
+			t.Fatal(err)
71
+		}
72
+		if p.Name() != plugin.Name() {
73
+			t.Errorf("no matching plugin with name %s found", plugin.Name())
74
+		}
75
+		if plugin.Client() != nil {
76
+			t.Error("expected nil Client but found one")
77
+		}
78
+		if !plugin.IsV1() {
79
+			t.Error("Expected true for V1 plugin")
80
+		}
81
+	})
80 82
 
81 83
 	// check negative case where plugin fruit doesn't implement banana
82
-	_, err = Get("fruit", "banana")
83
-	assert.Assert(t, errors.Is(err, ErrNotImplements))
84
+	t.Run("not implemented", func(t *testing.T) {
85
+		_, err := Get("fruit", "banana")
86
+		assert.Assert(t, errors.Is(err, ErrNotImplements))
87
+	})
84 88
 
85 89
 	// check negative case where plugin vegetable doesn't exist
86
-	_, err = Get("vegetable", "potato")
87
-	assert.Assert(t, errors.Is(err, ErrNotFound))
90
+	t.Run("not exists", func(t *testing.T) {
91
+		_, err := Get("vegetable", "potato")
92
+		assert.Assert(t, errors.Is(err, ErrNotFound))
93
+	})
88 94
 }
89 95
 
90 96
 func TestPluginWithNoManifest(t *testing.T) {