mirror of https://github.com/tikv/client-go.git
config: replace pingcap/check with testify (#136)
Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
parent
bad44ec705
commit
090d6eb694
|
|
@ -33,31 +33,42 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
. "github.com/pingcap/check"
|
||||
"testing"
|
||||
|
||||
"github.com/pingcap/failpoint"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var _ = SerialSuites(&testConfigSuite{})
|
||||
|
||||
func (s *testConfigSuite) TestParsePath(c *C) {
|
||||
func TestParsePath(t *testing.T) {
|
||||
etcdAddrs, disableGC, err := ParsePath("tikv://node1:2379,node2:2379")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(etcdAddrs, DeepEquals, []string{"node1:2379", "node2:2379"})
|
||||
c.Assert(disableGC, IsFalse)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []string{"node1:2379", "node2:2379"}, etcdAddrs)
|
||||
assert.False(t, disableGC)
|
||||
|
||||
_, _, err = ParsePath("tikv://node1:2379")
|
||||
c.Assert(err, IsNil)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, disableGC, err = ParsePath("tikv://node1:2379?disableGC=true")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(disableGC, IsTrue)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, disableGC)
|
||||
}
|
||||
|
||||
func (s *testConfigSuite) TestTxnScopeValue(c *C) {
|
||||
c.Assert(failpoint.Enable("tikvclient/injectTxnScope", `return("bj")`), IsNil)
|
||||
c.Assert(GetTxnScopeFromConfig(), Equals, "bj")
|
||||
c.Assert(failpoint.Enable("tikvclient/injectTxnScope", `return("")`), IsNil)
|
||||
c.Assert(GetTxnScopeFromConfig(), Equals, "global")
|
||||
c.Assert(failpoint.Enable("tikvclient/injectTxnScope", `return("global")`), IsNil)
|
||||
c.Assert(GetTxnScopeFromConfig(), Equals, "global")
|
||||
c.Assert(failpoint.Disable("tikvclient/injectTxnScope"), IsNil)
|
||||
func TestTxnScopeValue(t *testing.T) {
|
||||
var err error
|
||||
|
||||
err = failpoint.Enable("tikvclient/injectTxnScope", `return("bj")`)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "bj", GetTxnScopeFromConfig())
|
||||
|
||||
err = failpoint.Enable("tikvclient/injectTxnScope", `return("")`)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "global", GetTxnScopeFromConfig())
|
||||
|
||||
err = failpoint.Enable("tikvclient/injectTxnScope", `return("global")`)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "global", GetTxnScopeFromConfig())
|
||||
|
||||
err = failpoint.Disable("tikvclient/injectTxnScope")
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,26 +38,37 @@ import (
|
|||
"runtime"
|
||||
"testing"
|
||||
|
||||
. "github.com/pingcap/check"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var _ = SerialSuites(&testConfigSuite{})
|
||||
func TestTLSConfig(t *testing.T) {
|
||||
_, localFile, _, _ := runtime.Caller(0)
|
||||
certFile := filepath.Join(filepath.Dir(localFile), "cert.pem")
|
||||
keyFile := filepath.Join(filepath.Dir(localFile), "key.pem")
|
||||
perm := os.FileMode(0666)
|
||||
|
||||
type testConfigSuite struct{}
|
||||
assert.Nil(t, os.WriteFile(certFile, []byte(cert), perm))
|
||||
assert.Nil(t, os.WriteFile(keyFile, []byte(key), perm))
|
||||
|
||||
func TestT(t *testing.T) {
|
||||
CustomVerboseFlag = true
|
||||
TestingT(t)
|
||||
security := Security{
|
||||
ClusterSSLCA: certFile,
|
||||
ClusterSSLCert: certFile,
|
||||
ClusterSSLKey: keyFile,
|
||||
}
|
||||
|
||||
tlsConfig, err := security.ToTLSConfig()
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, tlsConfig)
|
||||
|
||||
// Note that on windows, we can't Remove a file if the file is not closed.
|
||||
// The behavior is different on linux, we can always Remove a file even
|
||||
// if it's open. The OS maintains a reference count for open/close, the file
|
||||
// is recycled when the reference count drops to 0.
|
||||
assert.Nil(t, os.Remove(certFile))
|
||||
assert.Nil(t, os.Remove(keyFile))
|
||||
}
|
||||
|
||||
func (s *testConfigSuite) TestConfig(c *C) {
|
||||
// Test for TLS config.
|
||||
certFile := "cert.pem"
|
||||
_, localFile, _, _ := runtime.Caller(0)
|
||||
certFile = filepath.Join(filepath.Dir(localFile), certFile)
|
||||
f, err := os.Create(certFile)
|
||||
c.Assert(err, IsNil)
|
||||
_, err = f.WriteString(`-----BEGIN CERTIFICATE-----
|
||||
var cert = `-----BEGIN CERTIFICATE-----
|
||||
MIIC+jCCAeKgAwIBAgIRALsvlisKJzXtiwKcv7toreswDQYJKoZIhvcNAQELBQAw
|
||||
EjEQMA4GA1UEChMHQWNtZSBDbzAeFw0xOTAzMTMwNzExNDhaFw0yMDAzMTIwNzEx
|
||||
NDhaMBIxEDAOBgNVBAoTB0FjbWUgQ28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
|
|
@ -75,15 +86,9 @@ If0KbvbS6qDfimA+m0m6n5yDzc5tPl+kgKyeivSyqeG7T9m40gvCLAMgI7iTFhIZ
|
|||
BvUPi88z3wGa8rmhn9dOvkwauLFU5i5dqoz6m9HXmaEKzAAigGzgU8vPDt/Dxxgu
|
||||
c933WW1E0hCtvuGxWFIFtoJMQoyH0Pl4ACmY/6CokCCZKDInrPdhhf3MGRjkkw==
|
||||
-----END CERTIFICATE-----
|
||||
`)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(f.Close(), IsNil)
|
||||
`
|
||||
|
||||
keyFile := "key.pem"
|
||||
keyFile = filepath.Join(filepath.Dir(localFile), keyFile)
|
||||
f, err = os.Create(keyFile)
|
||||
c.Assert(err, IsNil)
|
||||
_, err = f.WriteString(`-----BEGIN RSA PRIVATE KEY-----
|
||||
var key = `-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAxAsmOXGeEnHEHZOFwoBDcDi7BPdrmb7rQXGB5PJ3SKcbsUJ5
|
||||
kv9mnycVpXbioGrri5cEWK88L5lELpswdCyCSMGTd+yjHnqU7/nH9SL9FNU8Nj8l
|
||||
2u4w9VcXHCO5R8ajm2K5y3WdQDhtkslqCaf4Oo2am3Rp2AGwcW2V2L/RcgOodBZL
|
||||
|
|
@ -110,23 +115,4 @@ hApKLQKBgHUG+SjrxQjiFipE52YNGFLzbMR6Uga4baACW05uGPpao/+MkCGRAidL
|
|||
d/8eU66iPNt/23iVAbqkF8mRpCxC0+O5HRqTEzgrlWKabXfmhYqIVjq+tkonJ0NU
|
||||
xkNuJ2BlEGkwWLiRbKy1lNBBFUXKuhh3L/EIY10WTnr3TQzeL6H1
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(f.Close(), IsNil)
|
||||
security := Security{
|
||||
ClusterSSLCA: certFile,
|
||||
ClusterSSLCert: certFile,
|
||||
ClusterSSLKey: keyFile,
|
||||
}
|
||||
|
||||
tlsConfig, err := security.ToTLSConfig()
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(tlsConfig, NotNil)
|
||||
|
||||
// Note that on windows, we can't Remove a file if the file is not closed.
|
||||
// The behavior is different on linux, we can always Remove a file even
|
||||
// if it's open. The OS maintains a reference count for open/close, the file
|
||||
// is recycled when the reference count drops to 0.
|
||||
c.Assert(os.Remove(certFile), IsNil)
|
||||
c.Assert(os.Remove(keyFile), IsNil)
|
||||
}
|
||||
`
|
||||
|
|
|
|||
Loading…
Reference in New Issue