Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/go/json_test.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package db_test
6
7
import (
8
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
9
"github.com/gitpod-io/gitpod/components/gitpod-db/go/dbtest"
10
"github.com/stretchr/testify/require"
11
"testing"
12
)
13
14
func TestEncryptJSON_DecryptJSON(t *testing.T) {
15
cipher, _ := dbtest.GetTestCipher(t)
16
17
type Data struct {
18
First string
19
Second int
20
}
21
22
data := Data{
23
First: "first",
24
Second: 2,
25
}
26
27
encrypted, err := db.EncryptJSON(cipher, data)
28
require.NoError(t, err)
29
30
decrypted, err := encrypted.Decrypt(cipher)
31
require.NoError(t, err)
32
33
require.Equal(t, data, decrypted)
34
}
35
36