1 package resolver
2
3
6 import (
7 "context"
8 "testing"
9
10 "github.com/golang/mock/gomock"
11 "github.com/stretchr/testify/assert"
12
13 "edge-infra.dev/pkg/edge/api/graph/model"
14 "edge-infra.dev/pkg/edge/api/mocks"
15 )
16
17 var (
18 testClassificationBannerEdgeID = "9c478a9c-b536-4ea9-9f1f-144c87094f6b"
19
20 testID = "de4f477e-1f68-40f7-9f1f-f9c9dc08c250"
21 testDescription = "test-description-1"
22 testPod = "test-pod1"
23 testContainer = "test-container1"
24 testType = "test-type1"
25 testClass = model.LogClassSelectionAudit
26 testPattern = "test-pattern1"
27 )
28
29 func TestCreateClassification(t *testing.T) {
30 mock := gomock.NewController(t)
31 logClassificationService := mocks.NewMockLogClassificationService(mock)
32
33 createClassificationInput := model.CreateClassificationInput{
34 Description: testDescription,
35 Pod: testPod,
36 Container: testContainer,
37 Type: testType,
38 Class: testClass,
39 Pattern: testPattern,
40 }
41
42 logClassificationService.EXPECT().CreateLogClassification(context.Background(), testClassificationBannerEdgeID, "", createClassificationInput).
43 Return(&model.LogClassification{}, nil)
44
45 classifcation, err := logClassificationService.CreateLogClassification(context.Background(), testClassificationBannerEdgeID, "", createClassificationInput)
46
47 assert.NoError(t, err)
48 assert.Equal(t, &model.LogClassification{}, classifcation)
49 }
50 func TestUpdateClassification(t *testing.T) {
51 mock := gomock.NewController(t)
52 logClassificationService := mocks.NewMockLogClassificationService(mock)
53
54 updateClassificationInput := &model.UpdateClassificationInput{
55 Description: &testDescription,
56 Pod: &testPod,
57 Container: &testContainer,
58 Type: &testType,
59 Class: &testClass,
60 Pattern: &testPattern,
61 }
62
63 logClassificationService.EXPECT().UpdateLogClassification(context.Background(), testClassificationBannerEdgeID, testID, updateClassificationInput).
64 Return(&model.LogClassification{}, nil)
65
66 classifcation, err := logClassificationService.UpdateLogClassification(context.Background(), testClassificationBannerEdgeID, testID, updateClassificationInput)
67
68 assert.NoError(t, err)
69 assert.Equal(t, &model.LogClassification{}, classifcation)
70 }
71
72 func TestGetClassification(t *testing.T) {
73 mock := gomock.NewController(t)
74 logClassificationService := mocks.NewMockLogClassificationService(mock)
75
76 logClassificationService.EXPECT().GetLogClassification(context.Background(), testClassificationBannerEdgeID, testID).
77 Return(&model.LogClassification{}, nil)
78
79 classifcation, err := logClassificationService.GetLogClassification(context.Background(), testClassificationBannerEdgeID, testID)
80
81 assert.NoError(t, err)
82 assert.Equal(t, &model.LogClassification{}, classifcation)
83 }
84
85 func TestGetClassificationByBanner(t *testing.T) {
86 mock := gomock.NewController(t)
87 logClassificationService := mocks.NewMockLogClassificationService(mock)
88
89 logClassificationService.EXPECT().GetLogClassificationsByBanner(context.Background(), testClassificationBannerEdgeID).
90 Return([]*model.LogClassification{}, nil)
91
92 classifcation, err := logClassificationService.GetLogClassificationsByBanner(context.Background(), testClassificationBannerEdgeID)
93
94 assert.NoError(t, err)
95 assert.Equal(t, []*model.LogClassification{}, classifcation)
96 }
97 func TestDeleteClassification(t *testing.T) {
98 mock := gomock.NewController(t)
99 logClassificationService := mocks.NewMockLogClassificationService(mock)
100
101 logClassificationService.EXPECT().DeleteLogClassification(context.Background(), testClassificationBannerEdgeID, testID).
102 Return(true, nil)
103
104 classifcation, err := logClassificationService.DeleteLogClassification(context.Background(), testClassificationBannerEdgeID, testID)
105
106 assert.NoError(t, err)
107 assert.True(t, classifcation)
108 }
109
View as plain text