From 3120ce9ac81fbe4dabcaf10ffe44ba3fe6fdd5d6 Mon Sep 17 00:00:00 2001 From: Michael Mraka Date: Wed, 4 Dec 2024 13:57:58 +0100 Subject: [PATCH] RHINENG-14351: add tests for system authenticated API for templates --- ...template_subscribed_systems_update_test.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 manager/controllers/template_subscribed_systems_update_test.go diff --git a/manager/controllers/template_subscribed_systems_update_test.go b/manager/controllers/template_subscribed_systems_update_test.go new file mode 100644 index 000000000..3166adcf3 --- /dev/null +++ b/manager/controllers/template_subscribed_systems_update_test.go @@ -0,0 +1,41 @@ +package controllers + +import ( + "app/base/core" + "app/base/database" + "app/base/utils" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" +) + +var subscriptionUUID = "cccccccc-0000-0000-0001-000000000004" +var templateSystemUUID = "00000000-0000-0000-0000-000000000004" + +func TestSubscribedSystemID(t *testing.T) { + core.SetupTest(t) + + c, _ := gin.CreateTestContext(httptest.NewRecorder()) + c.Set(utils.KeyAccount, templateAccount) + c.Set(utils.KeySystem, subscriptionUUID) + account, systemID, err := getSubscribedSystem(c, database.DB) + + assert.Nil(t, err) + assert.Equal(t, templateAccount, account) + assert.Equal(t, templateSystemUUID, systemID) +} + +func TestUnknownSubscribedSystemID(t *testing.T) { + core.SetupTest(t) + + c, _ := gin.CreateTestContext(httptest.NewRecorder()) + c.Set(utils.KeyAccount, templateAccount) + c.Set(utils.KeySystem, "unknown-uuid") + account, systemID, err := getSubscribedSystem(c, database.DB) + + assert.EqualError(t, err, "System unknown-uuid not found") + assert.Equal(t, 0, account) + assert.Equal(t, "", systemID) +}