github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/internal/secret/secret_test.go (about) 1 package secret 2 3 import ( 4 "testing" 5 6 "github.com/apex/up" 7 "github.com/tj/assert" 8 ) 9 10 func TestFormat(t *testing.T) { 11 t.Run("relative", func(t *testing.T) { 12 assert.Equal(t, "/up/myapp/production/S3_KEY", Format("myapp", "production", "S3_KEY")) 13 }) 14 15 t.Run("absolute", func(t *testing.T) { 16 assert.Equal(t, "/up/myapp/all/S3_KEY", Format("myapp", "", "S3_KEY")) 17 }) 18 } 19 20 func TestParse(t *testing.T) { 21 s := Format("myapp", "production", "S3_KEY") 22 app, stage, name := Parse(s) 23 assert.Equal(t, "myapp", app) 24 assert.Equal(t, "production", stage) 25 assert.Equal(t, "S3_KEY", name) 26 } 27 28 func TestEnv(t *testing.T) { 29 s := []*up.Secret{ 30 { 31 Name: "foo", 32 Value: "bar", 33 }, 34 { 35 Name: "bar", 36 Value: "baz", 37 }, 38 } 39 40 env := Env(s) 41 assert.Equal(t, []string{"foo=bar", "bar=baz"}, env) 42 } 43 44 func TestString(t *testing.T) { 45 t.Run("String", func(t *testing.T) { 46 s := &up.Secret{ 47 Type: "String", 48 Value: "hello", 49 } 50 51 assert.Equal(t, `hello`, String(s)) 52 }) 53 54 t.Run("SecureString", func(t *testing.T) { 55 s := &up.Secret{ 56 Type: "SecureString", 57 Value: "hello", 58 } 59 60 assert.Equal(t, `*****`, String(s)) 61 }) 62 }