@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"crypto/sha256"
22
22
"encoding/hex"
23
+ "fmt"
23
24
"os"
24
25
"testing"
25
26
@@ -39,6 +40,29 @@ var bundleWithMultipleFiles = bundle.NewBatch(map[string]deepcode.BundleFile{
39
40
"file" : {},
40
41
"another" : {},
41
42
})
43
+ var bundleFromRawContent , batchErr = bundle .NewBatchFromRawContent (map [string ][]byte {"hello" : []byte ("world" )})
44
+
45
+ // Matcher for BundleFile that matches on key and content (ignores hash)
46
+ type bundleFilePartialMatcher struct {
47
+ expectedKey string
48
+ expectedContent string
49
+ }
50
+
51
+ func (m bundleFilePartialMatcher ) Matches (x interface {}) bool {
52
+ files , ok := x .(map [string ]deepcode.BundleFile )
53
+ if ! ok {
54
+ return false
55
+ }
56
+ file , exists := files [m .expectedKey ]
57
+ if ! exists {
58
+ return false
59
+ }
60
+ return file .Content == m .expectedContent
61
+ }
62
+
63
+ func (m bundleFilePartialMatcher ) String () string {
64
+ return fmt .Sprintf ("{ Key : '%s', Content : '%s' }" , m .expectedKey , m .expectedContent )
65
+ }
42
66
43
67
func Test_UploadBatch (t * testing.T ) {
44
68
testLogger := zerolog .Nop ()
@@ -89,6 +113,7 @@ func Test_UploadBatch(t *testing.T) {
89
113
mockSnykCodeClient .EXPECT ().ExtendBundle (gomock .Any (), "testBundleHash" , map [string ]deepcode.BundleFile {
90
114
"file" : {},
91
115
}, []string {}).Return ("testBundleHash" , []string {}, nil ).Times (1 )
116
+ mockSnykCodeClient .EXPECT ().ExtendBundle (gomock .Any (), "bundleWithMultipleFilesHash" , bundleFilePartialMatcher {expectedKey : "hello" , expectedContent : "world" }, []string {}).Return ("bundleWithAllFilesHash" , []string {}, nil ).Times (1 )
92
117
93
118
mockSpan := mocks .NewMockSpan (ctrl )
94
119
mockSpan .EXPECT ().Context ().AnyTimes ()
@@ -105,6 +130,11 @@ func Test_UploadBatch(t *testing.T) {
105
130
require .NoError (t , err )
106
131
newHash := b .GetBundleHash ()
107
132
assert .NotEqual (t , oldHash , newHash )
133
+ require .NoError (t , batchErr )
134
+ err = b .UploadBatch (context .Background (), "testRequestId" , bundleFromRawContent )
135
+ require .NoError (t , err )
136
+ newestHash := b .GetBundleHash ()
137
+ assert .NotEqual (t , newHash , newestHash )
108
138
})
109
139
}
110
140
0 commit comments