summaryrefslogtreecommitdiff
path: root/remote_test.go
diff options
context:
space:
mode:
authorlhchavez <[email protected]>2020-12-01 19:11:41 -0800
committerlhchavez <[email protected]>2021-09-05 18:52:01 -0700
commit5def02a589a2c1653f4bb515fdec290361a222be (patch)
treeb99d3a8204c27c902f711bc4f8f8b48baa8352bb /remote_test.go
parent70e5e419cf0cab31553b106267a0296f3cd672d9 (diff)
The big Callback type adjustment of 2020
This change makes all callbacks that can fail return an `error`. This makes things a lot more idiomatic.
Diffstat (limited to 'remote_test.go')
-rw-r--r--remote_test.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/remote_test.go b/remote_test.go
index 9660a3f..05395b3 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -38,13 +38,13 @@ func TestListRemotes(t *testing.T) {
compareStringList(t, expected, actual)
}
-func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) ErrorCode {
+func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) error {
if hostname != "github.com" {
- t.Fatal("Hostname does not match")
- return ErrorCodeUser
+ t.Fatal("hostname does not match")
+ return errors.New("hostname does not match")
}
- return ErrorCodeOK
+ return nil
}
func TestCertificateCheck(t *testing.T) {
@@ -58,7 +58,7 @@ func TestCertificateCheck(t *testing.T) {
options := FetchOptions{
RemoteCallbacks: RemoteCallbacks{
- CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
+ CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) error {
return assertHostname(cert, valid, hostname, t)
},
},
@@ -479,14 +479,13 @@ func TestRemoteSSH(t *testing.T) {
certificateCheckCallbackCalled := false
fetchOpts := FetchOptions{
RemoteCallbacks: RemoteCallbacks{
- CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
+ CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) error {
hostkeyFingerprint := fmt.Sprintf("%x", cert.Hostkey.HashMD5[:])
if hostkeyFingerprint != publicKeyFingerprint {
- t.Logf("server hostkey %q, want %q", hostkeyFingerprint, publicKeyFingerprint)
- return ErrorCodeAuth
+ return fmt.Errorf("server hostkey %q, want %q", hostkeyFingerprint, publicKeyFingerprint)
}
certificateCheckCallbackCalled = true
- return ErrorCodeOK
+ return nil
},
CredentialsCallback: func(url, username string, allowedTypes CredentialType) (*Credential, error) {
if allowedTypes&(CredentialTypeSSHKey|CredentialTypeSSHCustom|CredentialTypeSSHMemory) != 0 {