@@ -4,12 +4,13 @@ import (
4
4
"bytes"
5
5
"context"
6
6
"fmt"
7
- "golang.org/x/sync/errgroup"
8
7
"io/ioutil"
9
8
"os"
10
9
"regexp"
11
10
"sync"
12
11
"testing"
12
+
13
+ "golang.org/x/sync/errgroup"
13
14
)
14
15
15
16
func TestReconstruct (t * testing.T ) {
@@ -41,7 +42,7 @@ func TestReconstruct(t *testing.T) {
41
42
cfg configs
42
43
err string
43
44
}{
44
- {name : "solder" , cfg : configs {1 , 2 , 0 , 0 , solder , 1 , 1500 , "" , fmt . Sprintf ( "%s" , fakePcap .Name () ), fmt .Sprintf ("%s/solder" , tdir ), logic }},
45
+ {name : "solder" , cfg : configs {1 , 2 , 0 , 0 , solder , 1 , 1500 , "" , fakePcap .Name (), fmt .Sprintf ("%s/solder" , tdir ), logic }},
45
46
}
46
47
for _ , tc := range tests {
47
48
t .Run (tc .name , func (t * testing.T ) {
@@ -122,7 +123,7 @@ func TestCreatePacket(t *testing.T) {
122
123
{name : "24 BitsPerPixel" , recv : []byte {8 , 16 , 32 , 64 , 128 }, packet : []int {8 , 16 , 32 , 64 , 128 }, bpP : 24 },
123
124
{name : "12 BitPerPixel" , recv : []byte {1 , 2 , 5 , 13 , 18 , 57 , 153 }, packet : []int {0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 }, bpP : 12 },
124
125
{name : "3 BitPerPixel" , recv : []byte {5 , 49 , 14 }, packet : []int {0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , 233 , 144 , 89 , 55 , 34 , 21 , 13 , 8 , 5 , 3 , 2 , 1 , 1 , 0 }, bpP : 3 },
125
- {name : "2 BitsPerPixel" , recv : []byte {}, packet : []int {8 , 16 , 32 , 64 , 128 }, bpP : 2 , err : "This format is not supported so far" },
126
+ {name : "2 BitsPerPixel" , recv : []byte {}, packet : []int {8 , 16 , 32 , 64 , 128 }, bpP : 2 , err : "this format is not supported so far" },
126
127
{name : "1 BitPerPixel" , recv : []byte {1 , 8 }, packet : []int {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255 , 255 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 255 , 255 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 }, bpP : 1 },
127
128
}
128
129
@@ -134,10 +135,8 @@ func TestCreatePacket(t *testing.T) {
134
135
var recv []byte
135
136
go func () {
136
137
defer wg .Done ()
137
- select {
138
- case v , _ := <- ch :
139
- recv = append (recv , v ... )
140
- }
138
+ v := <- ch
139
+ recv = append (recv , v ... )
141
140
close (ch )
142
141
}()
143
142
err := createPacket (ch , tc .packet , tc .bpP )
@@ -153,7 +152,7 @@ func TestCreatePacket(t *testing.T) {
153
152
t .Fatalf ("Expected error, got none" )
154
153
}
155
154
wg .Wait ()
156
- if bytes .Compare (recv , tc .recv ) != 0 {
155
+ if ! bytes .Equal (recv , tc .recv ) {
157
156
t .Fatalf ("Expected: %v \t Got: %v" , tc .recv , recv )
158
157
}
159
158
})
@@ -234,12 +233,12 @@ func TestExtractInformation(t *testing.T) {
234
233
recv []byte
235
234
err string
236
235
}{
237
- {name : "No file" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , "noFile" , fmt .Sprintf ("%s/noFile" , dir ), logic }, err : "Could not open file" },
238
- {name : "Not a svg" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , fmt . Sprintf ( "%s" , notSvgFile .Name ()) , fmt .Sprintf ("%s/not_a_svg" , dir ), logic }, err : "No end of header found" },
239
- {name : "Without Comment" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , fmt . Sprintf ( "%s" , withoutCommentFile .Name ()) , fmt .Sprintf ("%s/without_comment" , dir ), logic }, err : "No end of header found" },
240
- {name : "Valid003 svg" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , fmt . Sprintf ( "%s" , validSvgFile003 .Name () ), fmt .Sprintf ("%s/valid_003_svg" , dir ), logic }, recv : []byte {0 , 0 }},
241
- {name : "Valid004 svg" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , fmt . Sprintf ( "%s" , validSvgFile004 .Name ()) , fmt .Sprintf ("%s/valid_004_svg" , dir ), logic }, err : "Can 't decode version" },
242
- {name : "Invalid version" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , fmt . Sprintf ( "%s" , invalidVersionFile .Name ()) , fmt .Sprintf ("%s/invalid_version" , dir ), logic }, err : "Unrecognized version" },
236
+ {name : "No file" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , "noFile" , fmt .Sprintf ("%s/noFile" , dir ), logic }, err : "could not open file" },
237
+ {name : "Not a svg" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , notSvgFile .Name (), fmt .Sprintf ("%s/not_a_svg" , dir ), logic }, err : "no end of header found" },
238
+ {name : "Without Comment" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , withoutCommentFile .Name (), fmt .Sprintf ("%s/without_comment" , dir ), logic }, err : "no end of header found" },
239
+ {name : "Valid003 svg" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , validSvgFile003 .Name (), fmt .Sprintf ("%s/valid_003_svg" , dir ), logic }, recv : []byte {0 , 0 }},
240
+ {name : "Valid004 svg" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , validSvgFile004 .Name (), fmt .Sprintf ("%s/valid_004_svg" , dir ), logic }, err : "can 't decode version" },
241
+ {name : "Invalid version" , cfg : configs {1 , 0 , 0 , 0 , 0 , 1 , 1500 , "" , invalidVersionFile .Name (), fmt .Sprintf ("%s/invalid_version" , dir ), logic }, err : "unrecognized version" },
243
242
}
244
243
245
244
for _ , tc := range tests {
@@ -267,7 +266,7 @@ func TestExtractInformation(t *testing.T) {
267
266
t .Fatalf ("Expected error, got none" )
268
267
}
269
268
wg .Wait ()
270
- if bytes .Compare (recv , tc .recv ) != 0 {
269
+ if ! bytes .Equal (recv , tc .recv ) {
271
270
t .Fatalf ("Expected: %v \t Got: %v" , tc .recv , recv )
272
271
}
273
272
})
0 commit comments