forked from denisenkom/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
always_encrypted_test.go
104 lines (86 loc) · 1.8 KB
/
always_encrypted_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package mssql
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"time"
)
type testAEStruct struct {
Id int
SSN string
Date time.Time
Float *float64
Money *float64
}
func TestAlwaysEncrypted(t *testing.T) {
conn := open(t)
defer conn.Close()
rows, err := conn.Query("SELECT id, ssn, secure_date, secure_float, secure_money FROM [dbo].[cid]")
defer rows.Close()
if err != nil {
t.Fatalf("unable to query db: %s", err)
}
var dest testAEStruct
expectedValues := []string{
"12345 ",
"00000 ",
"041-64-841",
"009-34-870",
"517-04-462",
"158-16-318",
"136-01-843",
}
secureFloat := []float64{
1.0,
453.32,
}
secureMoney := []float64{
40333.95,
8284323.0,
}
expectedSecureFloat := []*float64 {
&secureFloat[0],
&secureFloat[1],
nil,
nil,
nil,
nil,
nil,
}
expectedSecureMoney := []*float64 {
&secureMoney[0],
&secureMoney[1],
nil,
nil,
nil,
nil,
nil,
}
expectedDate := time.Date(2021, 02, 11, 0, 0, 0, 0, time.UTC)
expectedIdx := 0
for rows.Next() {
err = rows.Scan(&dest.Id, &dest.SSN, &dest.Date, &dest.Float, &dest.Money)
fmt.Printf("col: %+v", dest)
if dest.Float != nil {
fmt.Printf("\t%f", *dest.Float)
}
if dest.Money != nil {
fmt.Printf("\t%f", *dest.Money)
}
fmt.Printf("\n")
assert.Equal(t, expectedValues[expectedIdx], dest.SSN)
assert.Equal(t, expectedDate, dest.Date.UTC())
checkNilandValue(t, expectedSecureFloat, expectedIdx, dest.Float)
checkNilandValue(t, expectedSecureMoney, expectedIdx, dest.Money)
expectedIdx++
assert.Nil(t, err)
}
}
func checkNilandValue(t *testing.T, expectedArr []*float64, expectedIdx int, res *float64) {
if expectedArr[expectedIdx] == nil {
assert.Nil(t, res)
} else {
assert.NotNil(t, res)
assert.Equal(t, *expectedArr[expectedIdx], *res)
}
}