package subsonic import "testing" // A Subsonic app sends its password as plain text or hex-encoded behind // "enc:"; malformed hex is an error rather than a wrong password. func TestDecodePassword(t *testing.T) { for _, tc := range []struct { in, want string err bool }{ {"enc:68656c6c6f", "hello", false}, {"hunter2", "hunter2", false}, {"enc:zzzz", "", true}, } { out, err := decodePassword(tc.in) if (err != nil) != tc.err || (!tc.err && out != tc.want) { t.Errorf("decodePassword(%q) = %q, %v; want %q (error %v)", tc.in, out, err, tc.want, tc.err) } } }