-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathdelete_templates_test.go
61 lines (53 loc) · 1.84 KB
/
delete_templates_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tasks
import (
"context"
"testing"
"github.com/content-services/content-sources-backend/pkg/api"
"github.com/content-services/content-sources-backend/pkg/candlepin_client"
"github.com/content-services/content-sources-backend/pkg/dao"
"github.com/content-services/content-sources-backend/pkg/models"
"github.com/content-services/content-sources-backend/pkg/tasks/queue"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type DeleteTemplatesSuite struct {
suite.Suite
mockDaoRegistry *dao.MockDaoRegistry
MockQueue queue.MockQueue
Queue queue.Queue
mockCpClient *candlepin_client.MockCandlepinClient
}
func TestDeleteTemplatesSuite(t *testing.T) {
suite.Run(t, new(DeleteTemplatesSuite))
}
func (s *DeleteTemplatesSuite) SetupTest() {
s.mockDaoRegistry = dao.GetMockDaoRegistry(s.T())
s.MockQueue = *queue.NewMockQueue(s.T())
s.Queue = &s.MockQueue
s.mockCpClient = candlepin_client.NewMockCandlepinClient(s.T())
}
func (s *DeleteTemplatesSuite) TestDeleteTemplates() {
ctx := context.Background()
template := api.TemplateResponse{OrgID: "OrgId", UUID: uuid.NewString()}
task := models.TaskInfo{
Id: uuid.UUID{},
OrgId: template.OrgID,
ObjectUUID: uuid.Nil,
}
s.mockDaoRegistry.Template.On("Fetch", ctx, template.UUID).Return([]models.Template{}, nil).Once()
s.mockDaoRegistry.Template.On("Delete", ctx, template.OrgID, template.UUID).Return(nil).Once()
s.mockCpClient.On("DeleteEnvironment", ctx, template.UUID).Return(nil).Once()
payload := DeleteTemplatesPayload{
TemplateUUID: template.UUID,
}
deleteTemplatesTask := DeleteTemplates{
daoReg: s.mockDaoRegistry.ToDaoRegistry(),
payload: &payload,
task: &task,
ctx: ctx,
cpClient: s.mockCpClient,
}
templateErr := deleteTemplatesTask.Run()
assert.NoError(s.T(), templateErr)
}