-
Notifications
You must be signed in to change notification settings - Fork 11
/
secrets_test.go
46 lines (37 loc) · 1.24 KB
/
secrets_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
package provider
import (
"encoding/json"
"testing"
)
func TestUnmarshalJson(t *testing.T) {
// Define the JSON input
jsonData := `{"kind": "String", "value": "mySecretValue"}`
// Create a new SecretValue instance
secret := &SecretValue{}
// Unmarshal the JSON data into the SecretValue instance
err := json.Unmarshal([]byte(jsonData), secret)
if err != nil {
t.Errorf("Failed to unmarshal JSON: %v", err)
}
// Verify the unmarshaled value
expectedValue := "mySecretValue"
if secret.String.Reveal() != expectedValue {
t.Errorf("Unexpected value. Got: %s, Expected: %s", secret.String.Reveal(), expectedValue)
}
}
func TestUnmarshalJsonMap(t *testing.T) {
// Define the JSON input
jsonData := `{"foobar": {"kind": "String", "value": "mySecretValue"}}`
// Create a new SecretValue instance
secret := make(map[string]SecretValue)
// Unmarshal the JSON data into the SecretValue instance
err := json.Unmarshal([]byte(jsonData), &secret)
if err != nil {
t.Errorf("Failed to unmarshal JSON: %v", err)
}
// Verify the unmarshaled value
expectedValue := "mySecretValue"
if secret["foobar"].String.Reveal() != expectedValue {
t.Errorf("Unexpected value. Got: %s, Expected: %s", secret["foobar"].String.Reveal(), expectedValue)
}
}