-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_test.go
More file actions
73 lines (68 loc) · 1.35 KB
/
util_test.go
File metadata and controls
73 lines (68 loc) · 1.35 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
package foscam
import (
"testing"
"github.com/mdmfernandes/go-foscam/testutil"
)
func Test_isJpeg(t *testing.T) {
tests := []struct {
name string
data []byte
wantErr error
}{
{
name: "JPEG image",
data: []byte("\xFF\xD8\xFF"),
wantErr: nil,
},
{
name: "Plain text",
data: []byte(`This is plain text`),
wantErr: &InvalidMIMETypeError{Want: jpegMime, Got: "text/plain; charset=utf-8"},
},
{
name: "Empty data",
data: []byte{},
wantErr: &InvalidMIMETypeError{Want: jpegMime, Got: "text/plain; charset=utf-8"},
},
{
name: "Unknown format",
data: []byte{1, 2},
wantErr: &InvalidMIMETypeError{Want: jpegMime, Got: "application/octet-stream"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := isJpeg(tt.data); !testutil.EqualError(t, err, tt.wantErr) {
t.Errorf("Error: got = %v; want = %v", err, tt.wantErr)
}
})
}
}
func Test_b2u(t *testing.T) {
type args struct {
b bool
}
tests := []struct {
name string
args args
want uint8
}{
{
name: "true",
args: args{true},
want: 1,
},
{
name: "false",
args: args{false},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := b2u(tt.args.b); got != tt.want {
t.Errorf("b2u() = %v, want %v", got, tt.want)
}
})
}
}