-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version_test.go
83 lines (73 loc) · 1.61 KB
/
version_test.go
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
74
75
76
77
78
79
80
81
82
83
// Copyright 2023 The FIT SDK for Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package proto_test
import (
"errors"
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/muktihari/fit/proto"
)
func TestCreateVersion(t *testing.T) {
tt := []struct {
major byte
minor byte
version proto.Version
ok bool
}{
{
major: 1,
minor: 1,
version: proto.Version((1 << 4) | 1),
ok: true,
},
{
major: 2,
minor: 1,
version: proto.Version((1 << 4) | 1),
ok: false,
},
}
for _, tc := range tt {
t.Run(fmt.Sprintf("%d, %d", tc.major, tc.minor), func(t *testing.T) {
version, ok := proto.CreateVersion(tc.major, tc.minor)
if ok != tc.ok {
t.Fatalf("expected: %t, got: %t", tc.ok, ok)
}
if !ok {
return
}
if diff := cmp.Diff(version, tc.version); diff != "" {
t.Fatal(diff)
}
})
}
}
func TestValidateVersion(t *testing.T) {
tt := []struct {
version proto.Version
err error
}{
{version: 32, err: nil},
{version: 64, err: proto.ErrProtocolVersionNotSupported},
}
for _, tc := range tt {
t.Run(fmt.Sprintf("%d", tc.version), func(t *testing.T) {
err := proto.Validate(tc.version)
if !errors.Is(err, tc.err) {
t.Fatalf("expected err: %v, got: %v", tc.err, err)
}
})
}
}
func TestVersionMajorMinor(t *testing.T) {
major := proto.VersionMajor(32)
if major != 2 {
t.Fatalf("expected major: 2, got: %d", major)
}
minor := proto.VersionMinor(7)
if minor != 7 {
t.Fatalf("expected minor: 7, got: %d", minor)
}
}