-
Notifications
You must be signed in to change notification settings - Fork 5
/
route_data_test.go
64 lines (57 loc) · 1.68 KB
/
route_data_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
package fir
import (
"reflect"
"testing"
)
type TestData struct {
Name string
Age int
}
func TestBuildData(t *testing.T) {
// Test case 1: No dataset provided
err := buildData(false)
if err != nil {
t.Errorf("Expected nil error, got: %v", err)
}
// Test case 2: Only routeData provided
data := map[string]any{"key": "value"}
err = buildData(false, data)
if err == nil {
t.Errorf("Expected error, got: %v", err)
}
r, ok := err.(*routeData)
if !ok {
t.Errorf("Expected error type *routeData, got: %v", reflect.TypeOf(err))
}
if !reflect.DeepEqual(*r, routeData{"key": "value"}) {
t.Errorf("Expected error value %v, got: %v", data, *r)
}
// Test case 2: Only stateData provided
err = buildData(true, data)
if err == nil {
t.Errorf("Expected error, got: %v", err)
}
s, ok := err.(*stateData)
if !ok {
t.Errorf("Expected error type *stateData, got: %v", reflect.TypeOf(err))
}
if !reflect.DeepEqual(*s, stateData{"key": "value"}) {
t.Errorf("Expected error value %v, got: %v", data, *s)
}
// Test case 3: Both routeData and stateData provided
err = buildData(false, data, buildData(true, map[string]any{"key1": "value1"}))
if err == nil {
t.Errorf("Expected error, got: %v", err)
}
rs, ok := err.(*routeDataWithState)
if !ok {
t.Errorf("Expected error type *routeDataWithState, got: %v", reflect.TypeOf(err))
}
expectedRouteData := routeData{"key": "value", "key1": "value1"}
if !reflect.DeepEqual(*rs.routeData, expectedRouteData) {
t.Errorf("Expected error value %v, got: %v", expectedRouteData, *rs.routeData)
}
if !reflect.DeepEqual(*rs.stateData, stateData{"key1": "value1"}) {
t.Errorf("Expected error value %v, got: %v", data, *rs.stateData)
}
}