forked from areski/cdr-pusher
-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper_test.go
60 lines (53 loc) · 1.94 KB
/
helper_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
package main
import (
"testing"
)
func TestGetFieldSelect(t *testing.T) {
cdrFields := []ParseFields{
{OrigField: "uuid", DestField: "callid", TypeField: "string"},
{OrigField: "caller_id_name", DestField: "caller_id_name", TypeField: "string"},
}
IDField := "rowid"
strfields := getFieldSelect(IDField, cdrFields)
if strfields != "rowid, uuid, caller_id_name" {
t.Error("Expected 'rowid, uuid, caller_id_name', got ", strfields)
}
}
func TestGetFieldlistInsert(t *testing.T) {
cdrFields := []ParseFields{
{OrigField: "uuid", DestField: "callid", TypeField: "string"},
{OrigField: "caller_id_name", DestField: "caller_id_name", TypeField: "string"},
}
insertf, _ := getFieldlistInsert(cdrFields)
if insertf != "switch, cdr_source_type, callid, caller_id_name" {
t.Error("Expected 'switch, cdr_source_type, callid, caller_id_name', got ", insertf)
}
cdrFields = []ParseFields{
{OrigField: "uuid", DestField: "callid", TypeField: "string"},
{OrigField: "customfield", DestField: "extradata", TypeField: "jsonb"},
}
insertExtra, extradata := getFieldlistInsert(cdrFields)
if insertExtra != "switch, cdr_source_type, callid, extradata" {
t.Error("Expected 'switch, cdr_source_type, callid, extradata', got ", insertExtra)
}
expectedmap := map[int]string{1: "customfield"}
if extradata[1] != expectedmap[1] {
t.Error("Expected 'map[1:customfield]', got ", extradata)
}
}
func TestGetValuelistInsert(t *testing.T) {
cdrFields := []ParseFields{
{OrigField: "uuid", DestField: "callid", TypeField: "string"},
{OrigField: "caller_id_name", DestField: "caller_id_name", TypeField: "string"},
}
valuesf := getValuelistInsert(cdrFields)
if valuesf != ":switch, :cdr_source_type, :callid, :caller_id_name" {
t.Error("Expected ':switch, :cdr_source_type, :callid, :caller_id_name', got ", valuesf)
}
}
func TestExternalIP(t *testing.T) {
localip, _ := externalIP()
if localip == "" {
t.Error("Expected an IP Address, got ", localip)
}
}