Files
filestash/server/common/crypto_test.go
2018-10-15 22:48:27 +11:00

43 lines
810 B
Go

package common
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEncryptString(t *testing.T) {
key := "test|test|test|test|test"
text := "I'm some text"
a, err := EncryptString(key, text)
assert.NoError(t, err)
assert.NotNil(t, a)
assert.NotEqual(t, a, text)
b, err := DecryptString(key, a)
assert.NoError(t, err)
assert.Equal(t, b, text)
}
func TestIDGeneration(t *testing.T) {
d := make(map[string]string)
d["foo"] = "bar"
id1 := GenerateID(d)
d["user"] = "polo"
id2 := GenerateID(d)
d["doesn_t_matter"] = "N/A"
id3 := GenerateID(d)
assert.NotEqual(t, id1, id2)
assert.Equal(t, id2, id3)
}
func TestStringGeneration(t *testing.T) {
str := QuickString(10)
str1 := QuickString(10)
str2 := QuickString(10)
assert.Equal(t, len(str), 10)
t.Log(str, str1, str2)
}