test: check and handle error for testing
SonarQube Scan / SonarQube Trigger (push) Successful in 3m35s
SonarQube Scan / SonarQube Trigger (push) Successful in 3m35s
This commit is contained in:
@@ -38,7 +38,8 @@ func TestHTTPServer_Listen(t *testing.T) {
|
||||
listener, err := srv.Listen()
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, listener)
|
||||
listener.Close()
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestHTTPServer_Serve(t *testing.T) {
|
||||
@@ -54,7 +55,8 @@ func TestHTTPServer_Serve(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
listener.Close()
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
err = srv.Serve(listener)
|
||||
@@ -102,8 +104,12 @@ func TestHTTPServer_Serve_Success(t *testing.T) {
|
||||
_, _ = conn.Write([]byte("GET / HTTP/1.1\r\nHost: ping.example.com\r\n\r\n"))
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
conn.Close()
|
||||
listener.Close()
|
||||
err = conn.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
}
|
||||
|
||||
type mockListener struct {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
"tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/registry"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
@@ -97,53 +96,6 @@ func (m *MockSession) Detail() *types.Detail {
|
||||
return args.Get(0).(*types.Detail)
|
||||
}
|
||||
|
||||
type MockLifecycle struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) Channel() ssh.Channel {
|
||||
args := m.Called()
|
||||
return args.Get(0).(ssh.Channel)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) Connection() ssh.Conn {
|
||||
args := m.Called()
|
||||
return args.Get(0).(ssh.Conn)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) PortRegistry() port.Port {
|
||||
args := m.Called()
|
||||
return args.Get(0).(port.Port)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) User() string {
|
||||
args := m.Called()
|
||||
return args.String(0)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) SetChannel(channel ssh.Channel) {
|
||||
m.Called(channel)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) SetStatus(status types.SessionStatus) {
|
||||
m.Called(status)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) IsActive() bool {
|
||||
args := m.Called()
|
||||
return args.Bool(0)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) StartedAt() time.Time {
|
||||
args := m.Called()
|
||||
return args.Get(0).(time.Time)
|
||||
}
|
||||
|
||||
func (m *MockLifecycle) Close() error {
|
||||
args := m.Called()
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
type MockSSHChannel struct {
|
||||
ssh.Channel
|
||||
mock.Mock
|
||||
@@ -678,7 +630,10 @@ func TestHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
if clientConn != nil {
|
||||
defer clientConn.Close()
|
||||
defer func(clientConn net.Conn) {
|
||||
err := clientConn.Close()
|
||||
assert.NoError(t, err)
|
||||
}(clientConn)
|
||||
}
|
||||
|
||||
remoteAddr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:12345")
|
||||
|
||||
@@ -46,7 +46,8 @@ func TestHTTPSServer_Listen(t *testing.T) {
|
||||
return
|
||||
}
|
||||
assert.NotNil(t, listener)
|
||||
listener.Close()
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestHTTPSServer_Serve(t *testing.T) {
|
||||
@@ -62,7 +63,8 @@ func TestHTTPSServer_Serve(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
listener.Close()
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
err = srv.Serve(listener)
|
||||
@@ -111,6 +113,8 @@ func TestHTTPSServer_Serve_Success(t *testing.T) {
|
||||
_, _ = conn.Write([]byte("GET / HTTP/1.1\r\nHost: ping.example.com\r\n\r\n"))
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
conn.Close()
|
||||
listener.Close()
|
||||
err = conn.Close()
|
||||
assert.NoError(t, err)
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ func TestTCPServer_Listen(t *testing.T) {
|
||||
listener, err := srv.Listen()
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, listener)
|
||||
listener.Close()
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestTCPServer_Serve(t *testing.T) {
|
||||
@@ -44,7 +45,8 @@ func TestTCPServer_Serve(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
listener.Close()
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
err = srv.Serve(listener)
|
||||
@@ -84,9 +86,10 @@ func TestTCPServer_Serve_Success(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
conn.Close()
|
||||
listener.Close()
|
||||
|
||||
err = conn.Close()
|
||||
assert.NoError(t, err)
|
||||
err = listener.Close()
|
||||
assert.NoError(t, err)
|
||||
mf.AssertExpectations(t)
|
||||
}
|
||||
|
||||
@@ -95,7 +98,10 @@ func TestTCPServer_handleTcp_Success(t *testing.T) {
|
||||
srv := NewTCPServer(0, mf).(*tcp)
|
||||
|
||||
serverConn, clientConn := net.Pipe()
|
||||
defer clientConn.Close()
|
||||
defer func(clientConn net.Conn) {
|
||||
err := clientConn.Close()
|
||||
assert.NoError(t, err)
|
||||
}(clientConn)
|
||||
|
||||
reqs := make(chan *ssh.Request)
|
||||
mockChannel := new(MockSSHChannel)
|
||||
@@ -127,7 +133,10 @@ func TestTCPServer_handleTcp_OpenChannelError(t *testing.T) {
|
||||
srv := NewTCPServer(0, mf).(*tcp)
|
||||
|
||||
serverConn, clientConn := net.Pipe()
|
||||
defer clientConn.Close()
|
||||
defer func(clientConn net.Conn) {
|
||||
err := clientConn.Close()
|
||||
assert.NoError(t, err)
|
||||
}(clientConn)
|
||||
|
||||
mf.On("OpenForwardedChannel", mock.Anything, mock.Anything).Return(nil, (<-chan *ssh.Request)(nil), errors.New("open error"))
|
||||
|
||||
|
||||
+124
-61
@@ -80,13 +80,15 @@ func createTestCert(t *testing.T, domain string, wildcard bool, expired bool, so
|
||||
assert.NoError(t, err)
|
||||
err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
|
||||
assert.NoError(t, err)
|
||||
certOut.Close()
|
||||
err = certOut.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
keyOut, err := os.CreateTemp("", "key*.pem")
|
||||
assert.NoError(t, err)
|
||||
err = pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
|
||||
assert.NoError(t, err)
|
||||
keyOut.Close()
|
||||
err = keyOut.Close()
|
||||
assert.NoError(t, err)
|
||||
|
||||
return certOut.Name(), keyOut.Name()
|
||||
}
|
||||
@@ -98,7 +100,8 @@ func setupTestDir(t *testing.T) string {
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
os.RemoveAll(tmpDir)
|
||||
err = os.RemoveAll(tmpDir)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
return tmpDir
|
||||
@@ -126,8 +129,11 @@ func TestValidateCertDomains(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
_, err = tmpFile.WriteString("not a pem")
|
||||
assert.NoError(t, err)
|
||||
tmpFile.Close()
|
||||
return tmpFile.Name(), func() { os.Remove(tmpFile.Name()) }
|
||||
err = tmpFile.Close()
|
||||
assert.NoError(t, err)
|
||||
return tmpFile.Name(), func() {
|
||||
_ = os.Remove(tmpFile.Name())
|
||||
}
|
||||
},
|
||||
domain: "example.com",
|
||||
expected: false,
|
||||
@@ -137,8 +143,8 @@ func TestValidateCertDomains(t *testing.T) {
|
||||
setup: func(t *testing.T) (string, func()) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
return certPath, func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
}
|
||||
},
|
||||
domain: "example.com",
|
||||
@@ -149,8 +155,8 @@ func TestValidateCertDomains(t *testing.T) {
|
||||
setup: func(t *testing.T) (string, func()) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, true, false)
|
||||
return certPath, func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
}
|
||||
},
|
||||
domain: "example.com",
|
||||
@@ -161,8 +167,8 @@ func TestValidateCertDomains(t *testing.T) {
|
||||
setup: func(t *testing.T) (string, func()) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, true)
|
||||
return certPath, func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
}
|
||||
},
|
||||
domain: "example.com",
|
||||
@@ -173,8 +179,8 @@ func TestValidateCertDomains(t *testing.T) {
|
||||
setup: func(t *testing.T) (string, func()) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", false, false, false)
|
||||
return certPath, func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
}
|
||||
},
|
||||
domain: "example.com",
|
||||
@@ -205,8 +211,8 @@ func TestLoadAndParseCertificate(t *testing.T) {
|
||||
setup: func(t *testing.T) (string, func()) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
return certPath, func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
}
|
||||
},
|
||||
wantError: false,
|
||||
@@ -275,8 +281,14 @@ func TestIsCertificateValid(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, tt.expired, tt.soon)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
cert, err := loadAndParseCertificate(certPath)
|
||||
assert.NoError(t, err)
|
||||
@@ -289,8 +301,14 @@ func TestIsCertificateValid(t *testing.T) {
|
||||
|
||||
func TestExtractCertDomains(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
cert, err := loadAndParseCertificate(certPath)
|
||||
assert.NoError(t, err)
|
||||
@@ -381,8 +399,8 @@ func TestTLSManager_getCertificate(t *testing.T) {
|
||||
setup: func(t *testing.T) *tlsManager {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
cert, err := tls.LoadX509KeyPair(certPath, keyPath)
|
||||
@@ -447,8 +465,9 @@ func TestTLSManager_userCertsExistAndValid(t *testing.T) {
|
||||
mockCfg.On("Domain").Return("example.com")
|
||||
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() { os.Remove(certPath) })
|
||||
os.Remove(keyPath)
|
||||
t.Cleanup(func() { _ = os.Remove(certPath) })
|
||||
err := os.Remove(keyPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
return &tlsManager{
|
||||
config: mockCfg,
|
||||
@@ -471,8 +490,14 @@ func TestTLSManager_userCertsExistAndValid(t *testing.T) {
|
||||
|
||||
func TestTLSManager_certFilesExist(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
tm := &tlsManager{
|
||||
certPath: certPath,
|
||||
@@ -494,8 +519,8 @@ func TestTLSManager_loadUserCerts(t *testing.T) {
|
||||
setup: func(t *testing.T) *tlsManager {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
return &tlsManager{
|
||||
@@ -550,8 +575,14 @@ func TestCreateTLSManager(t *testing.T) {
|
||||
|
||||
func TestNewCertWatcher(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
|
||||
@@ -571,8 +602,14 @@ func TestNewCertWatcher(t *testing.T) {
|
||||
|
||||
func TestCertWatcher_filesModified(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
|
||||
@@ -600,8 +637,14 @@ func TestCertWatcher_filesModified(t *testing.T) {
|
||||
|
||||
func TestCertWatcher_updateModTimes(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
|
||||
@@ -637,8 +680,8 @@ func TestCertWatcher_getFileInfo(t *testing.T) {
|
||||
setup: func(t *testing.T) *tlsManager {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
return &tlsManager{
|
||||
@@ -657,8 +700,9 @@ func TestCertWatcher_getFileInfo(t *testing.T) {
|
||||
name: "missing cert file",
|
||||
setup: func(t *testing.T) *tlsManager {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
os.Remove(certPath)
|
||||
t.Cleanup(func() { os.Remove(keyPath) })
|
||||
err := os.Remove(certPath)
|
||||
assert.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.Remove(keyPath) })
|
||||
|
||||
return &tlsManager{
|
||||
config: &MockConfig{},
|
||||
@@ -672,8 +716,9 @@ func TestCertWatcher_getFileInfo(t *testing.T) {
|
||||
name: "missing key file",
|
||||
setup: func(t *testing.T) *tlsManager {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
os.Remove(keyPath)
|
||||
t.Cleanup(func() { os.Remove(certPath) })
|
||||
err := os.Remove(keyPath)
|
||||
assert.NoError(t, err)
|
||||
t.Cleanup(func() { _ = os.Remove(certPath) })
|
||||
|
||||
return &tlsManager{
|
||||
config: &MockConfig{},
|
||||
@@ -729,8 +774,8 @@ func TestCertWatcher_checkAndReloadCerts(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
tm := &tlsManager{
|
||||
@@ -747,8 +792,8 @@ func TestCertWatcher_checkAndReloadCerts(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
@@ -792,8 +837,8 @@ func TestCertWatcher_handleCertificateChange(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher, os.FileInfo, os.FileInfo) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
@@ -819,8 +864,8 @@ func TestCertWatcher_handleCertificateChange(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher, os.FileInfo, os.FileInfo) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", false, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
tmpDir := setupTestDir(t)
|
||||
@@ -850,8 +895,8 @@ func TestCertWatcher_handleCertificateChange(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher, os.FileInfo, os.FileInfo) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
@@ -946,8 +991,8 @@ func TestCertWatcher_watch(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", false, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
tmpDir := setupTestDir(t)
|
||||
@@ -976,8 +1021,8 @@ func TestCertWatcher_watch(t *testing.T) {
|
||||
setup: func(t *testing.T) (*tlsManager, *certWatcher) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
@@ -1006,8 +1051,14 @@ func TestCertWatcher_watch(t *testing.T) {
|
||||
|
||||
func TestCertWatcher_watch_Integration(t *testing.T) {
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
mockCfg := &MockConfig{}
|
||||
mockCfg.On("Domain").Return("example.com")
|
||||
@@ -1029,8 +1080,14 @@ func TestCertWatcher_watch_Integration(t *testing.T) {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
newCertPath, newKeyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(newCertPath)
|
||||
defer os.Remove(newKeyPath)
|
||||
defer func(name string) {
|
||||
err = os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(newCertPath)
|
||||
defer func(name string) {
|
||||
err = os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(newKeyPath)
|
||||
|
||||
newCertData, err := os.ReadFile(newCertPath)
|
||||
assert.NoError(t, err)
|
||||
@@ -1066,8 +1123,8 @@ func TestNewTLSConfig(t *testing.T) {
|
||||
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
t.Cleanup(func() {
|
||||
os.Remove(certPath)
|
||||
os.Remove(keyPath)
|
||||
_ = os.Remove(certPath)
|
||||
_ = os.Remove(keyPath)
|
||||
})
|
||||
|
||||
certData, err := os.ReadFile(certPath)
|
||||
@@ -1140,8 +1197,14 @@ func TestNewTLSConfig_Singleton(t *testing.T) {
|
||||
tmpDir := setupTestDir(t)
|
||||
|
||||
certPath, keyPath := createTestCert(t, "example.com", true, false, false)
|
||||
defer os.Remove(certPath)
|
||||
defer os.Remove(keyPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(certPath)
|
||||
defer func(name string) {
|
||||
err := os.Remove(name)
|
||||
assert.NoError(t, err)
|
||||
}(keyPath)
|
||||
|
||||
certData, err := os.ReadFile(certPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user