-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package functional_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestTokenizationAndDetokenization(t *testing.T) { | ||
// Simulate request data | ||
requestData := []map[string]string{ | ||
{"name_first": "John", "name_last": "Dsilva"}, | ||
{"name_first": "Tera"}, | ||
{"name_first": "Maria"}, | ||
} | ||
|
||
// Send request to server for tokenization | ||
tokenizedData, err := sendRequest("http://127.0.0.1:28001/tokenize", requestData) | ||
if err != nil { | ||
t.Fatalf("Error sending tokenize request: %v", err) | ||
} | ||
|
||
// Send request to server for detokenization | ||
detokenizedData, err := sendRequest("http://127.0.0.1:28001/detokenize", tokenizedData) | ||
if err != nil { | ||
t.Fatalf("Error sending detokenize request: %v", err) | ||
} | ||
|
||
// Compare original data with detokenized data | ||
for i := range requestData { | ||
if !isEqual(requestData[i], detokenizedData[i]) { | ||
t.Errorf("Detokenized data doesn't match original data at index %d", i) | ||
} | ||
} | ||
} | ||
|
||
// Send request to server and decode the response | ||
func sendRequest(url string, requestData []map[string]string) ([]map[string]string, error) { | ||
requestBody, err := json.Marshal(requestData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
var responseData []map[string]string | ||
err = json.NewDecoder(resp.Body).Decode(&responseData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return responseData, nil | ||
} | ||
|
||
// Function to compare two maps | ||
func isEqual(a, b map[string]string) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
for k, v := range a { | ||
if b[k] != v { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/open-privacy/opv | ||
|
||
go 1.20 | ||
go 1.22 | ||
|
||
require ( | ||
entgo.io/ent v0.12.3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters