File: secret_test.go

package info (click to toggle)
golang-github-viant-toolbox 0.33.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,280 kB
  • sloc: makefile: 16
file content (62 lines) | stat: -rw-r--r-- 1,187 bytes parent folder | download | duplicates (2)
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
package secret_test

import (
	"github.com/stretchr/testify/assert"
	"github.com/viant/toolbox/cred"
	"github.com/viant/toolbox/secret"
	"testing"
)

func TestSecret_IsLocation(t *testing.T) {

	{
		sec := secret.Secret("htttp://abc.com/secret.json")
		assert.True(t, sec.IsLocation())
	}
	{
		sec := secret.Secret("{}")
		assert.False(t, sec.IsLocation())
	}

}

func TestSecretKey_IsDynamic(t *testing.T) {

	{
		key := secret.SecretKey("**key1**")
		assert.False(t, key.IsDynamic())
	}
	{
		key := secret.SecretKey("##key1##")
		assert.False(t, key.IsDynamic())
	}
	{
		key := secret.SecretKey("key1")
		assert.True(t, key.IsDynamic())
	}

}

func TestSecretKey_Secret(t *testing.T) {

	{ //test user and password secret
		credConfig := &cred.Config{Username: "abc", Password: "pass"}
		{
			key := secret.SecretKey("**key1**")
			assert.EqualValues(t, "pass", key.Secret(credConfig))
		}
		{
			key := secret.SecretKey("##key1##")
			assert.EqualValues(t, "abc", key.Secret(credConfig))
		}
	}

	{ //test json secret
		credConfig := &cred.Config{Username: "abc", Data: "{}"}
		{
			key := secret.SecretKey("**key1**")
			assert.EqualValues(t, "{}", key.Secret(credConfig))
		}
	}

}