@@ -2,7 +2,10 @@ package process
2
2
3
3
import (
4
4
"context"
5
+ "crypto/md5"
6
+ "encoding/hex"
5
7
"errors"
8
+ "github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/dto/apiSpecDoc"
6
9
"testing"
7
10
8
11
"github.com/golang/mock/gomock"
@@ -13,7 +16,7 @@ import (
13
16
"github.com/stretchr/testify/assert"
14
17
)
15
18
16
- func Test_RecognizeFail_processReturnsError (t * testing.T ) {
19
+ func TestProcess_RecognizeFail_processReturnsError (t * testing.T ) {
17
20
ctrl := gomock .NewController (t )
18
21
19
22
contentLoader := load .NewMockContentLoader (ctrl )
@@ -37,7 +40,7 @@ func Test_RecognizeFail_processReturnsError(t *testing.T) {
37
40
assert .Equal (t , expectedErr , err , "Should return error from recognizer" )
38
41
}
39
42
40
- func Test_ContentLoaderFail_processReturnsError (t * testing.T ) {
43
+ func TestProcess_ContentLoaderFail_processReturnsError (t * testing.T ) {
41
44
ctrl := gomock .NewController (t )
42
45
43
46
contentLoader := load .NewMockContentLoader (ctrl )
@@ -60,7 +63,7 @@ func Test_ContentLoaderFail_processReturnsError(t *testing.T) {
60
63
assert .Equal (t , expectedErr , err , "Should return error from contentLoader" )
61
64
}
62
65
63
- func Test_ConverterFail_processReturnsError (t * testing.T ) {
66
+ func TestProcess_ConverterFail_processReturnsError (t * testing.T ) {
64
67
ctrl := gomock .NewController (t )
65
68
66
69
contentLoader := load .NewMockContentLoader (ctrl )
@@ -84,3 +87,35 @@ func Test_ConverterFail_processReturnsError(t *testing.T) {
84
87
assert .Nil (t , asd )
85
88
assert .Equal (t , expectedErr , err , "Should return error from converter" )
86
89
}
90
+
91
+ func TestProcess_completed_hashPopulated (t * testing.T ) {
92
+ ctrl := gomock .NewController (t )
93
+
94
+ contentLoader := load .NewMockContentLoader (ctrl )
95
+ recognizer := recognize .NewMockRecognizer (ctrl )
96
+ converter := parse .NewMockConverter (ctrl )
97
+
98
+ ctx := context .Background ()
99
+ url := "test_url_from_yaml_openapi_file"
100
+
101
+ fileContent := []byte ("Test content" )
102
+ fileResource := new (fileresource.FileResource )
103
+ fileResource .Content = fileContent
104
+
105
+ result := & apiSpecDoc.ApiSpecDoc {}
106
+ loadCall := contentLoader .EXPECT ().Load (ctx , url ).Times (1 ).Return (fileResource , nil )
107
+ recognizeCall := recognizer .EXPECT ().RecognizeFileType (fileResource ).After (loadCall ).Times (1 ).Return (fileresource .OpenApi , nil )
108
+ converter .EXPECT ().Convert (ctx , gomock .Any ()).Times (1 ).After (recognizeCall ).Return (result , nil )
109
+
110
+ processor , err := NewProcessor (recognizer , converter , contentLoader )
111
+ assert .Nil (t , err )
112
+ assert .NotNil (t , processor , "Processor must not be nil" )
113
+
114
+ asd , err := processor .Process (ctx , url )
115
+ assert .Nil (t , err )
116
+ assert .NotNil (t , asd )
117
+ assert .Equal (t , result , asd )
118
+ hashSum := md5 .Sum (fileContent )
119
+ expectedHash := hex .EncodeToString (hashSum [:])
120
+ assert .Equal (t , expectedHash , asd .Md5Sum )
121
+ }
0 commit comments