tlsopts: fix helper (#1515)
This commit is contained in:
parent
ea8a0fd9ba
commit
46ab2f0d8f
@ -174,11 +174,11 @@ func (vf *VerificationFuncs) ServerAdd(verificationFuncs ...peertls.PeerCertVeri
|
||||
}
|
||||
|
||||
func removeNils(verificationFuncs []peertls.PeerCertVerificationFunc) []peertls.PeerCertVerificationFunc {
|
||||
for i, f := range verificationFuncs {
|
||||
if f == nil {
|
||||
copy(verificationFuncs[i:], verificationFuncs[i+1:])
|
||||
verificationFuncs = verificationFuncs[:len(verificationFuncs)-1]
|
||||
result := verificationFuncs[:0]
|
||||
for _, f := range verificationFuncs {
|
||||
if f != nil {
|
||||
result = append(result, f)
|
||||
}
|
||||
}
|
||||
return verificationFuncs
|
||||
return result
|
||||
}
|
||||
|
26
pkg/peertls/tlsopts/options_internal_test.go
Normal file
26
pkg/peertls/tlsopts/options_internal_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package tlsopts
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"storj.io/storj/pkg/peertls"
|
||||
)
|
||||
|
||||
func TestRemoveNils(t *testing.T) {
|
||||
e1 := fmt.Errorf("error 1")
|
||||
f1 := peertls.PeerCertVerificationFunc(func([][]byte, [][]*x509.Certificate) error { return e1 })
|
||||
e2 := fmt.Errorf("error 2")
|
||||
f2 := peertls.PeerCertVerificationFunc(func([][]byte, [][]*x509.Certificate) error { return e2 })
|
||||
|
||||
l := removeNils([]peertls.PeerCertVerificationFunc{f1, nil, nil, f2})
|
||||
require.Equal(t, len(l), 2)
|
||||
require.Equal(t, l[0](nil, nil), e1)
|
||||
require.Equal(t, l[1](nil, nil), e2)
|
||||
}
|
Loading…
Reference in New Issue
Block a user