61 lines
1008 B
Go
61 lines
1008 B
Go
package secret
|
|
|
|
import (
|
|
"bytes"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestEnvironment(t *testing.T) {
|
|
testProvider(t, Environment(),
|
|
testProviderCase{
|
|
Key: "USER",
|
|
Test: testNotEmpty,
|
|
})
|
|
}
|
|
|
|
func TestEnvironmentPrefix(t *testing.T) {
|
|
testProvider(t, EnvironmentPrefix("US"),
|
|
testProviderCase{
|
|
Key: "ER",
|
|
Test: testNotEmpty,
|
|
})
|
|
}
|
|
|
|
var testEnvironmentFileCases = []testProviderCase{
|
|
{
|
|
Key: "test",
|
|
Test: testEqualString("case"),
|
|
},
|
|
{
|
|
Key: "spaces",
|
|
Test: testEqualString("yeah"),
|
|
},
|
|
{
|
|
Key: "ignored",
|
|
Err: NotFound{"ignored"},
|
|
},
|
|
}
|
|
|
|
func TestEnvironmentFile(t *testing.T) {
|
|
p, err := EnvironmentFile(filepath.Join("testdata", "env"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
testProvider(t, p, testEnvironmentFileCases...)
|
|
}
|
|
|
|
func TestEnvironmentReader(t *testing.T) {
|
|
p, err := EnvironmentReader(bytes.NewBufferString(`
|
|
#ignored=true
|
|
test=case
|
|
spaces = yeah
|
|
`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
testProvider(t, p, testEnvironmentFileCases...)
|
|
}
|