42 lines
1 KiB
Go
42 lines
1 KiB
Go
package secretstore
|
|
|
|
import "testing"
|
|
|
|
func TestMarshalCredentialRoundTrip(t *testing.T) {
|
|
input := Credential{
|
|
Host: "imap.example.com",
|
|
Username: "alice",
|
|
Password: "secret",
|
|
}
|
|
|
|
data, err := MarshalCredential(input)
|
|
if err != nil {
|
|
t.Fatalf("MarshalCredential returned error: %v", err)
|
|
}
|
|
|
|
output, err := UnmarshalCredential(data)
|
|
if err != nil {
|
|
t.Fatalf("UnmarshalCredential returned error: %v", err)
|
|
}
|
|
|
|
if output != input {
|
|
t.Fatalf("round-trip mismatch: got %#v want %#v", output, input)
|
|
}
|
|
}
|
|
|
|
func TestMarshalCredentialRejectsInvalidCredential(t *testing.T) {
|
|
_, err := MarshalCredential(Credential{
|
|
Host: "imap.example.com",
|
|
Username: "alice",
|
|
})
|
|
if err == nil {
|
|
t.Fatal("expected MarshalCredential to reject incomplete credential")
|
|
}
|
|
}
|
|
|
|
func TestUnmarshalCredentialRejectsInvalidCredential(t *testing.T) {
|
|
_, err := UnmarshalCredential([]byte(`{"host":"imap.example.com","username":"alice"}`))
|
|
if err == nil {
|
|
t.Fatal("expected UnmarshalCredential to reject incomplete credential")
|
|
}
|
|
}
|