From 4acc4796edb2c1ff93e861b4732c1c758ac76371 Mon Sep 17 00:00:00 2001 From: Domenico Rizzo Date: Mon, 10 Jun 2024 17:11:47 +0200 Subject: [PATCH] Added GetPluginID method and tests (#27281) A new method, GetPluginID, has been added to the Manifest model. This function returns the ID of a plugin. Corresponding unit tests have also been implemented to ensure that this function works as expected. The test cases cover scenarios where IDs are the same and different. --- server/public/model/manifest.go | 4 ++++ server/public/model/manifest_test.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/server/public/model/manifest.go b/server/public/model/manifest.go index 98c4e9abf5..57a1efbc7e 100644 --- a/server/public/model/manifest.go +++ b/server/public/model/manifest.go @@ -322,6 +322,10 @@ func (m *Manifest) IsValid() error { return nil } +func (m *Manifest) GetPluginID() string { + return m.Id +} + func (s *PluginSettingsSchema) isValid() error { for _, setting := range s.Settings { err := setting.isValid() diff --git a/server/public/model/manifest_test.go b/server/public/model/manifest_test.go index 8f42ab5f4b..84d3cfb65d 100644 --- a/server/public/model/manifest_test.go +++ b/server/public/model/manifest_test.go @@ -81,6 +81,29 @@ func TestIsValid(t *testing.T) { } } +func TestGetPluginIdReturnsCorrectId(t *testing.T) { + testCases := []struct { + Title string + Id string + manifest *Manifest + ExpectEqual bool + }{ + {"Ids are Different", "not-same.com.company.test", &Manifest{Id: "com.company.test"}, false}, + {"Ids are the same", "com.company.test", &Manifest{Id: "com.company.test"}, true}, + } + + for _, tc := range testCases { + t.Run(tc.Title, func(t *testing.T) { + id := tc.manifest.GetPluginID() + if tc.ExpectEqual { + assert.Equal(t, tc.Id, id) + } else { + assert.NotEqual(t, tc.Id, id) + } + }) + } +} + func TestIsValidSettingsSchema(t *testing.T) { testCases := []struct { Title string