forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quantity_test.go
55 lines (46 loc) · 1.36 KB
/
quantity_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
package openrtb_test
import (
"reflect"
"testing"
. "github.com/bsm/openrtb/v3"
)
func TestQuantity(t *testing.T) {
var subject *Quantity
if err := fixture("quantity", &subject); err != nil {
t.Fatalf("expected no error, got %+v", err)
}
exp := &Quantity{
Multiplier: 3.14,
SourceType: MeasurementSourceTypePublisher,
}
if !reflect.DeepEqual(exp, subject) {
t.Fatalf("expected %+v, got %+v", exp, subject)
}
}
func TestQuantity_Validate(t *testing.T) {
subject := Quantity{}
if got := subject.Validate(); got != ErrMissingMultiplier {
t.Fatalf("expected %+v, got %+v", ErrMissingMultiplier, got)
}
// If MeasurementSourceType is MeasurementSourceTypeMeasurementVendor, the
// Vendor field should not be empty.
subject = Quantity{
Multiplier: 1.0,
SourceType: MeasurementSourceTypeMeasurementVendor,
}
if got := subject.Validate(); got != ErrMissingMeasurementVendor {
t.Fatalf("expected %+v, got %+v", ErrMissingMeasurementVendor, got)
}
subject.Vendor = "TestVendor" // Should fix the invalid Quantity
if got := subject.Validate(); got != nil {
t.Fatalf("expected no error, got %+v", got)
}
// All other value from MeasurementSourceType can be used without Vendor
subject = Quantity{
Multiplier: 2.0,
SourceType: MeasurementSourceTypeUnknown,
}
if got := subject.Validate(); got != nil {
t.Fatalf("expected nil, got %+v", got)
}
}