MiniappGoService/pkg/hashText/tests/test.go

47 lines
1.2 KiB
Go

package hashText_test
import (
"log"
"testing"
"gitea.cybertalant.ru/VisionCareerMiniapp/MiniappGoService/pkg/hashText"
)
func TestMain(m *testing.M) {
log.Println("Start TestMain", "package: hashText_test")
m.Run()
log.Println("End TestMain", "package: hashText_test")
}
func TestDecode(t *testing.T) {
t.Parallel()
pass1, salt1 := "123qwerrt", "Hkjsldhgf8w7egfn87n"
pass2, salt2 := "alskjdfh", "JKHABJHSDGAJSdgb*&897taSBDJ"
pass3, salt3 := "3416924hf", "OIASd98yq892nmIUAWNM98"
t.Run("TestDecode - success - 1", func(t *testing.T) {
p := hashText.Encode(pass1, salt1)
result, err := hashText.Decode(p, salt1)
if result != pass1 || err != nil {
t.Errorf("The passwords don't match. Password: %s Result: %s", pass1, result)
}
})
t.Run("TestDecode - error - 2", func(t *testing.T) {
result, err := hashText.Decode(pass2, salt2)
if result == pass2 || err == nil {
t.Errorf("The passwords match. Password: %s Result: %s", pass2, result)
}
})
t.Run("TestDecode - success - 3", func(t *testing.T) {
p := hashText.Encode(pass3, salt3)
result, err := hashText.Decode(p, salt3)
if result != pass3 || err != nil {
t.Errorf("The passwords match. Password: %s Result: %s", pass3, result)
}
})
}