This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
87 lines (65 loc) · 1.97 KB
/
api_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
84
85
86
87
package routific_test
import (
"encoding/json"
"os"
"testing"
r "github.com/slamethendry/routific"
"github.com/stretchr/testify/assert"
)
// api_test calls Routific server API and compare the result
// between input from JSON and input from Routific object.
// Prerequisite: Auth Bearer Token, which, for testing purpose
// only, is assumed to be available as environment variable
// "Routific_Token".
// Test data is defined in setup_test.
var token = os.Getenv("Routific_Token")
func TestVRP(t *testing.T) {
assert.NotEmpty(t, token)
// Compare the JSON conversion vs internally created object
var v r.VRPlan
err := json.Unmarshal([]byte(vrpInputJSON), &v)
assert.Nil(t, err)
assert.Equal(t, v, vrpInput)
// VRP call using JSON
output1, err := r.VRP(v, token)
assert.Nil(t, err)
assert.NotEmpty(t, output1)
assert.Equal(t, output1.Status, "success")
// VRP call using internally created object
output2, err := r.VRP(vrpInput, token)
assert.Nil(t, err)
assert.NotEmpty(t, output2)
assert.Equal(t, output1, output2)
}
func TestPDP(t *testing.T) {
assert.NotEmpty(t, token)
// Compare the JSON conversion vs internally created object
var p r.PDPlan
err := json.Unmarshal([]byte(pdpInputJSON), &p)
assert.Nil(t, err)
assert.Equal(t, p, pdpInput)
// PDP call using JSON
output1, err := r.PDP(p, token)
assert.Nil(t, err)
assert.NotEmpty(t, output1)
assert.Equal(t, output1.Status, "success")
// PDP call using internally created object
output2, err := r.PDP(pdpInput, token)
assert.Nil(t, err)
assert.NotEmpty(t, output2)
assert.Equal(t, output1, output2)
}
func TestLongVRP(t *testing.T) {
assert.NotEmpty(t, token)
vrp, err := r.LongVRP(vrpInput, token, 3, 5)
assert.Nil(t, err)
assert.Equal(t, "success", vrp.Status)
assert.NotEmpty(t, vrp.Solution)
}
func TestLongPDP(t *testing.T) {
assert.NotEmpty(t, token)
pdp, err := r.LongPDP(pdpInput, token, 3, 2)
assert.Nil(t, err)
assert.Equal(t, "success", pdp.Status)
assert.NotEmpty(t, pdp.Solution)
}