@@ -4,11 +4,12 @@ Copyright (c) 2022 Skyflow, Inc.
4
4
package client
5
5
6
6
import (
7
+ "context"
7
8
"errors"
8
9
"fmt"
9
10
"os"
10
11
"testing"
11
- "context"
12
+
12
13
"github.com/joho/godotenv"
13
14
errors1 "github.com/skyflowapi/skyflow-go/commonutils/errors"
14
15
"github.com/skyflowapi/skyflow-go/commonutils/messages"
@@ -83,13 +84,89 @@ func TestInsertValidToken(t *testing.T) {
83
84
skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .EMPTY_VAULT_ID , clientTag ))
84
85
check (err .GetMessage (), skyflowError .GetMessage (), t )
85
86
}
86
-
87
+ func TestInsertInValidByot (t * testing.T ) {
88
+ configuration := common.Configuration {VaultID : "id" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
89
+ var client = Init (configuration )
90
+ var records = make (map [string ]interface {})
91
+ var record = make (map [string ]interface {})
92
+ record ["table" ] = "credit_cards"
93
+ var fields = make (map [string ]interface {})
94
+ fields ["cardholder_name" ] = "name"
95
+ fields ["card_number" ] = "4111111111111112"
96
+ record ["fields" ] = fields
97
+ var tokens = make (map [string ]interface {})
98
+ tokens ["cardholder_name" ] = "token1"
99
+ record ["tokens" ] = tokens
100
+ var recordsArray []interface {}
101
+ recordsArray = append (recordsArray , record )
102
+ records ["records" ] = recordsArray
103
+ _ , err := client .Insert (records , common.InsertOptions {Tokens : true , Byot : "demo" })
104
+ skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .INVALID_BYOT_TYPE , "Insert" ))
105
+ check (err .GetMessage (), skyflowError .GetMessage (), t )
106
+ }
107
+ func TestInsertByotTokensNotPassed (t * testing.T ) {
108
+ configuration := common.Configuration {VaultID : "id" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
109
+ var client = Init (configuration )
110
+ var records = make (map [string ]interface {})
111
+ var record = make (map [string ]interface {})
112
+ record ["table" ] = "credit_cards"
113
+ var fields = make (map [string ]interface {})
114
+ fields ["cardholder_name" ] = "name"
115
+ fields ["card_number" ] = "4111111111111112"
116
+ record ["fields" ] = fields
117
+ var recordsArray []interface {}
118
+ recordsArray = append (recordsArray , record )
119
+ records ["records" ] = recordsArray
120
+ _ , err := client .Insert (records , common.InsertOptions {Tokens : true , Byot : common .ENABLE })
121
+ skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .NO_TOKENS_IN_INSERT , "Insert" , "ENABLE" ))
122
+ check (err .GetMessage (), skyflowError .GetMessage (), t )
123
+ }
124
+ func TestInsertByotTokensNotAllPassed (t * testing.T ) {
125
+ configuration := common.Configuration {VaultID : "id" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
126
+ var client = Init (configuration )
127
+ var records = make (map [string ]interface {})
128
+ var record = make (map [string ]interface {})
129
+ record ["table" ] = "credit_cards"
130
+ var fields = make (map [string ]interface {})
131
+ fields ["cardholder_name" ] = "name"
132
+ fields ["card_number" ] = "4111111111111112"
133
+ record ["fields" ] = fields
134
+ var tokens = make (map [string ]interface {})
135
+ tokens ["cardholder_name" ] = "token1"
136
+ record ["tokens" ] = tokens
137
+ var recordsArray []interface {}
138
+ recordsArray = append (recordsArray , record )
139
+ records ["records" ] = recordsArray
140
+ _ , err := client .Insert (records , common.InsertOptions {Tokens : true , Byot : common .ENABLE_STRICT })
141
+ skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .INSUFFICIENT_TOKENS_PASSED_FOR_BYOT_ENABLE_STRICT , "Insert" ))
142
+ check (err .GetMessage (), skyflowError .GetMessage (), t )
143
+ }
144
+ func TestInsertByotNotPassedforTokens (t * testing.T ) {
145
+ configuration := common.Configuration {VaultID : "id" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
146
+ var client = Init (configuration )
147
+ var records = make (map [string ]interface {})
148
+ var record = make (map [string ]interface {})
149
+ record ["table" ] = "credit_cards"
150
+ var fields = make (map [string ]interface {})
151
+ fields ["cardholder_name" ] = "name"
152
+ fields ["card_number" ] = "4111111111111112"
153
+ record ["fields" ] = fields
154
+ var tokens = make (map [string ]interface {})
155
+ tokens ["cardholder_name" ] = "token1"
156
+ record ["tokens" ] = tokens
157
+ var recordsArray []interface {}
158
+ recordsArray = append (recordsArray , record )
159
+ records ["records" ] = recordsArray
160
+ _ , err := client .Insert (records , common.InsertOptions {Tokens : true })
161
+ skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .TOKENS_PASSED_FOR_BYOT_DISABLE , "Insert" ))
162
+ check (err .GetMessage (), skyflowError .GetMessage (), t )
163
+ }
87
164
func TestInsertValidTokenWithContext (t * testing.T ) {
88
165
configuration := common.Configuration {VaultID : "" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
89
166
var client = Init (configuration )
90
167
var record = make (map [string ]interface {})
91
- ctx := context .TODO ()
92
- _ , err := client .Insert (record , common.InsertOptions {Tokens : true ,Context : ctx })
168
+ ctx := context .TODO ()
169
+ _ , err := client .Insert (record , common.InsertOptions {Tokens : true , Context : ctx })
93
170
skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .EMPTY_VAULT_ID , clientTag ))
94
171
check (err .GetMessage (), skyflowError .GetMessage (), t )
95
172
}
@@ -107,8 +184,8 @@ func TestDetokenizeValidTokenWithContext(t *testing.T) {
107
184
configuration := common.Configuration {VaultID : "" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
108
185
var client = Init (configuration )
109
186
var record = make (map [string ]interface {})
110
- ctx := context .TODO ()
111
- _ , err := client .Detokenize (record ,common.DetokenizeOptions {Context : ctx })
187
+ ctx := context .TODO ()
188
+ _ , err := client .Detokenize (record , common.DetokenizeOptions {Context : ctx })
112
189
skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .EMPTY_VAULT_ID , clientTag ))
113
190
check (err .GetMessage (), skyflowError .GetMessage (), t )
114
191
}
@@ -117,8 +194,8 @@ func TestDetokenizeBulkValidTokenWithContext(t *testing.T) {
117
194
configuration := common.Configuration {VaultID : "" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
118
195
var client = Init (configuration )
119
196
var record = make (map [string ]interface {})
120
- ctx := context .TODO ()
121
- _ , err := client .Detokenize (record ,common.DetokenizeOptions {Context : ctx ,ContinueOnError : false })
197
+ ctx := context .TODO ()
198
+ _ , err := client .Detokenize (record , common.DetokenizeOptions {Context : ctx , ContinueOnError : false })
122
199
skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .EMPTY_VAULT_ID , clientTag ))
123
200
check (err .GetMessage (), skyflowError .GetMessage (), t )
124
201
}
@@ -127,7 +204,7 @@ func TestDetokenizeBulkValidTokenWithoutContext(t *testing.T) {
127
204
configuration := common.Configuration {VaultID : "" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
128
205
var client = Init (configuration )
129
206
var record = make (map [string ]interface {})
130
- _ , err := client .Detokenize (record ,common.DetokenizeOptions {ContinueOnError : false })
207
+ _ , err := client .Detokenize (record , common.DetokenizeOptions {ContinueOnError : false })
131
208
skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .EMPTY_VAULT_ID , clientTag ))
132
209
check (err .GetMessage (), skyflowError .GetMessage (), t )
133
210
}
@@ -145,8 +222,8 @@ func TestGetByIdValidTokenWithContext(t *testing.T) {
145
222
configuration := common.Configuration {VaultID : "" , VaultURL : "https://www.url.com" , TokenProvider : validToken }
146
223
var client = Init (configuration )
147
224
var record = make (map [string ]interface {})
148
- ctx := context .TODO ()
149
- _ , err := client .GetById (record ,common.GetByIdOptions {Context : ctx })
225
+ ctx := context .TODO ()
226
+ _ , err := client .GetById (record , common.GetByIdOptions {Context : ctx })
150
227
skyflowError := errors1 .NewSkyflowError (errors1 .ErrorCodesEnum (errors1 .SdkErrorCode ), fmt .Sprintf (messages .EMPTY_VAULT_ID , clientTag ))
151
228
check (err .GetMessage (), skyflowError .GetMessage (), t )
152
229
}
0 commit comments