proton-bridge/internal/transfer/transfer_test.go

72 lines
1.9 KiB
Go
Raw Normal View History

2021-01-04 10:55:15 +00:00
// Copyright (c) 2021 Proton Technologies AG
2020-05-14 13:22:29 +00:00
//
// This file is part of ProtonMail Bridge.
//
// ProtonMail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ProtonMail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
package transfer
import (
"io/ioutil"
"testing"
2020-06-17 13:29:41 +00:00
"github.com/ProtonMail/gopenpgp/v2/crypto"
2020-05-14 13:22:29 +00:00
transfermocks "github.com/ProtonMail/proton-bridge/internal/transfer/mocks"
pmapimocks "github.com/ProtonMail/proton-bridge/pkg/pmapi/mocks"
gomock "github.com/golang/mock/gomock"
)
type mocks struct {
t *testing.T
2020-11-06 13:23:38 +00:00
ctrl *gomock.Controller
panicHandler *transfermocks.MockPanicHandler
imapClientProvider *transfermocks.MockIMAPClientProvider
pmapiClient *pmapimocks.MockClient
2020-05-14 13:22:29 +00:00
keyring *crypto.KeyRing
}
func initMocks(t *testing.T) mocks {
mockCtrl := gomock.NewController(t)
m := mocks{
t: t,
2020-11-06 13:23:38 +00:00
ctrl: mockCtrl,
panicHandler: transfermocks.NewMockPanicHandler(mockCtrl),
imapClientProvider: transfermocks.NewMockIMAPClientProvider(mockCtrl),
pmapiClient: pmapimocks.NewMockClient(mockCtrl),
keyring: newTestKeyring(),
2020-05-14 13:22:29 +00:00
}
return m
}
func newTestKeyring() *crypto.KeyRing {
data, err := ioutil.ReadFile("testdata/keyring_userKey")
if err != nil {
panic(err)
}
2020-06-17 13:29:41 +00:00
key, err := crypto.NewKeyFromArmored(string(data))
2020-05-14 13:22:29 +00:00
if err != nil {
panic(err)
}
2020-06-17 13:29:41 +00:00
userKey, err := crypto.NewKeyRing(key)
if err != nil {
2020-05-14 13:22:29 +00:00
panic(err)
}
return userKey
}