mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-15 01:48:45 -07:00
lib: Use counterfeiter to mock interfaces in tests (#7375)
This commit is contained in:
parent
7945430e64
commit
3d91f7c975
21
build.go
21
build.go
@ -316,6 +316,9 @@ func runCommand(cmd string, target target) {
|
||||
case "proto":
|
||||
proto()
|
||||
|
||||
case "testmocks":
|
||||
testmocks()
|
||||
|
||||
case "translate":
|
||||
translate()
|
||||
|
||||
@ -862,10 +865,26 @@ func proto() {
|
||||
}
|
||||
runPrintInDir(path, "git", "checkout", dep.commit)
|
||||
}
|
||||
runPrint(goCmd, "generate", "github.com/syncthing/syncthing/lib/...", "github.com/syncthing/syncthing/cmd/stdiscosrv")
|
||||
runPrint(goCmd, "generate", "github.com/syncthing/syncthing/cmd/stdiscosrv")
|
||||
runPrint(goCmd, "generate", "proto/generate.go")
|
||||
}
|
||||
|
||||
func testmocks() {
|
||||
runPrint(goCmd, "get", "golang.org/x/tools/cmd/goimports")
|
||||
runPrint(goCmd, "get", "github.com/maxbrunsfeld/counterfeiter/v6")
|
||||
args := []string{
|
||||
"generate",
|
||||
"github.com/syncthing/syncthing/lib/config",
|
||||
"github.com/syncthing/syncthing/lib/connections",
|
||||
"github.com/syncthing/syncthing/lib/discover",
|
||||
"github.com/syncthing/syncthing/lib/events",
|
||||
"github.com/syncthing/syncthing/lib/logger",
|
||||
"github.com/syncthing/syncthing/lib/model",
|
||||
"github.com/syncthing/syncthing/lib/protocol",
|
||||
}
|
||||
runPrint(goCmd, args...)
|
||||
}
|
||||
|
||||
func translate() {
|
||||
os.Chdir("gui/default/assets/lang")
|
||||
runPipe("lang-en-new.json", goCmd, "run", "../../../../script/translate.go", "lang-en.json", "../../../")
|
||||
|
5
go.mod
5
go.mod
@ -30,6 +30,8 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.12
|
||||
github.com/minio/sha256-simd v0.1.1
|
||||
github.com/miscreant/miscreant.go v0.0.0-20200214223636-26d376326b75
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/onsi/gomega v1.10.3 // indirect
|
||||
github.com/oschwald/geoip2-golang v1.4.0
|
||||
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
@ -44,9 +46,10 @@ require (
|
||||
github.com/vitrun/qart v0.0.0-20160531060029-bf64b92db6b0
|
||||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
|
||||
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102
|
||||
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
|
||||
golang.org/x/text v0.3.4
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
|
||||
)
|
||||
|
||||
go 1.14
|
||||
|
14
go.sum
14
go.sum
@ -231,7 +231,6 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
@ -291,6 +290,8 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
|
||||
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
@ -303,8 +304,9 @@ github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
|
||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.10.3 h1:gph6h/qe9GSUw1NhH1gp+qb+h8rXD8Cy60Z32Qw3ELA=
|
||||
github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||
@ -504,6 +506,7 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
|
||||
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
@ -550,8 +553,8 @@ golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201024232916-9f70ab9862d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1 h1:a/mKvvZr9Jcc8oKfcmgzyp7OwF73JPWsQLvH1z2Kxck=
|
||||
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -623,8 +626,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
|
@ -28,9 +28,15 @@ import (
|
||||
"github.com/d4l3k/messagediff"
|
||||
"github.com/syncthing/syncthing/lib/assets"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
connmocks "github.com/syncthing/syncthing/lib/connections/mocks"
|
||||
discovermocks "github.com/syncthing/syncthing/lib/discover/mocks"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
eventmocks "github.com/syncthing/syncthing/lib/events/mocks"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/locations"
|
||||
"github.com/syncthing/syncthing/lib/logger"
|
||||
loggermocks "github.com/syncthing/syncthing/lib/logger/mocks"
|
||||
modelmocks "github.com/syncthing/syncthing/lib/model/mocks"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
"github.com/syncthing/syncthing/lib/svcutil"
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
@ -40,13 +46,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
confDir = filepath.Join("testdata", "config")
|
||||
token = filepath.Join(confDir, "csrftokens.txt")
|
||||
dev1 protocol.DeviceID
|
||||
confDir = filepath.Join("testdata", "config")
|
||||
token = filepath.Join(confDir, "csrftokens.txt")
|
||||
dev1 protocol.DeviceID
|
||||
apiCfg = newMockedConfig()
|
||||
testAPIKey = "foobarbaz"
|
||||
)
|
||||
|
||||
func init() {
|
||||
dev1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
|
||||
apiCfg.GUIReturns(config.GUIConfiguration{APIKey: testAPIKey})
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -246,10 +255,7 @@ type httpTestCase struct {
|
||||
func TestAPIServiceRequests(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const testAPIKey = "foobarbaz"
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.APIKey = testAPIKey
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
baseURL, cancel, err := startHTTP(apiCfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -515,9 +521,11 @@ func testHTTPRequest(t *testing.T, baseURL string, tc httpTestCase, apikey strin
|
||||
func TestHTTPLogin(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.User = "üser"
|
||||
cfg.gui.Password = "$2a$10$IdIZTxTg/dCNuNEGlmLynOjqg4B1FvDKuIV5e0BB3pnWVHNb8.GSq" // bcrypt of "räksmörgås" in UTF-8
|
||||
cfg := newMockedConfig()
|
||||
cfg.GUIReturns(config.GUIConfiguration{
|
||||
User: "üser",
|
||||
Password: "$2a$10$IdIZTxTg/dCNuNEGlmLynOjqg4B1FvDKuIV5e0BB3pnWVHNb8.GSq", // bcrypt of "räksmörgås" in UTF-8
|
||||
})
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -581,19 +589,29 @@ func TestHTTPLogin(t *testing.T) {
|
||||
}
|
||||
|
||||
func startHTTP(cfg config.Wrapper) (string, context.CancelFunc, error) {
|
||||
m := new(mockedModel)
|
||||
m := new(modelmocks.Model)
|
||||
assetDir := "../../gui"
|
||||
eventSub := new(mockedEventSub)
|
||||
diskEventSub := new(mockedEventSub)
|
||||
discoverer := new(mockedCachingMux)
|
||||
connections := new(mockedConnections)
|
||||
errorLog := new(mockedLoggerRecorder)
|
||||
systemLog := new(mockedLoggerRecorder)
|
||||
eventSub := new(eventmocks.BufferedSubscription)
|
||||
diskEventSub := new(eventmocks.BufferedSubscription)
|
||||
discoverer := new(discovermocks.Manager)
|
||||
connections := new(connmocks.Service)
|
||||
errorLog := new(loggermocks.Recorder)
|
||||
systemLog := new(loggermocks.Recorder)
|
||||
for _, l := range []*loggermocks.Recorder{errorLog, systemLog} {
|
||||
l.SinceReturns([]logger.Line{
|
||||
{
|
||||
When: time.Now(),
|
||||
Message: "Test message",
|
||||
},
|
||||
})
|
||||
}
|
||||
addrChan := make(chan string)
|
||||
mockedSummary := &modelmocks.FolderSummaryService{}
|
||||
mockedSummary.SummaryReturns(map[string]interface{}{"mocked": true}, nil)
|
||||
|
||||
// Instantiate the API service
|
||||
urService := ur.New(cfg, m, connections, false)
|
||||
svc := New(protocol.LocalDeviceID, cfg, assetDir, "syncthing", m, eventSub, diskEventSub, events.NoopLogger, discoverer, connections, urService, &mockedFolderSummaryService{}, errorLog, systemLog, false).(*service)
|
||||
svc := New(protocol.LocalDeviceID, cfg, assetDir, "syncthing", m, eventSub, diskEventSub, events.NoopLogger, discoverer, connections, urService, mockedSummary, errorLog, systemLog, false).(*service)
|
||||
defer os.Remove(token)
|
||||
svc.started = addrChan
|
||||
|
||||
@ -625,10 +643,7 @@ func startHTTP(cfg config.Wrapper) (string, context.CancelFunc, error) {
|
||||
func TestCSRFRequired(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const testAPIKey = "foobarbaz"
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.APIKey = testAPIKey
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
baseURL, cancel, err := startHTTP(apiCfg)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error from getting base URL:", err)
|
||||
}
|
||||
@ -701,10 +716,7 @@ func TestCSRFRequired(t *testing.T) {
|
||||
func TestRandomString(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const testAPIKey = "foobarbaz"
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.APIKey = testAPIKey
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
baseURL, cancel, err := startHTTP(apiCfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -794,10 +806,7 @@ func TestConfigPostDupFolder(t *testing.T) {
|
||||
}
|
||||
|
||||
func testConfigPost(data io.Reader) (*http.Response, error) {
|
||||
const testAPIKey = "foobarbaz"
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.APIKey = testAPIKey
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
baseURL, cancel, err := startHTTP(apiCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -816,8 +825,8 @@ func TestHostCheck(t *testing.T) {
|
||||
|
||||
// An API service bound to localhost should reject non-localhost host Headers
|
||||
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.RawAddress = "127.0.0.1:0"
|
||||
cfg := newMockedConfig()
|
||||
cfg.GUIReturns(config.GUIConfiguration{RawAddress: "127.0.0.1:0"})
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -876,9 +885,11 @@ func TestHostCheck(t *testing.T) {
|
||||
|
||||
// A server with InsecureSkipHostCheck set behaves differently
|
||||
|
||||
cfg = new(mockedConfig)
|
||||
cfg.gui.RawAddress = "127.0.0.1:0"
|
||||
cfg.gui.InsecureSkipHostCheck = true
|
||||
cfg = newMockedConfig()
|
||||
cfg.GUIReturns(config.GUIConfiguration{
|
||||
RawAddress: "127.0.0.1:0",
|
||||
InsecureSkipHostCheck: true,
|
||||
})
|
||||
baseURL, cancel, err = startHTTP(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -900,9 +911,11 @@ func TestHostCheck(t *testing.T) {
|
||||
|
||||
// A server bound to a wildcard address also doesn't do the check
|
||||
|
||||
cfg = new(mockedConfig)
|
||||
cfg.gui.RawAddress = "0.0.0.0:0"
|
||||
cfg.gui.InsecureSkipHostCheck = true
|
||||
cfg = newMockedConfig()
|
||||
cfg.GUIReturns(config.GUIConfiguration{
|
||||
RawAddress: "0.0.0.0:0",
|
||||
InsecureSkipHostCheck: true,
|
||||
})
|
||||
baseURL, cancel, err = startHTTP(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -929,8 +942,10 @@ func TestHostCheck(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
cfg = new(mockedConfig)
|
||||
cfg.gui.RawAddress = "[::1]:0"
|
||||
cfg = newMockedConfig()
|
||||
cfg.GUIReturns(config.GUIConfiguration{
|
||||
RawAddress: "[::1]:0",
|
||||
})
|
||||
baseURL, cancel, err = startHTTP(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -1023,10 +1038,7 @@ func TestAddressIsLocalhost(t *testing.T) {
|
||||
func TestAccessControlAllowOriginHeader(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const testAPIKey = "foobarbaz"
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.APIKey = testAPIKey
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
baseURL, cancel, err := startHTTP(apiCfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1054,10 +1066,7 @@ func TestAccessControlAllowOriginHeader(t *testing.T) {
|
||||
func TestOptionsRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const testAPIKey = "foobarbaz"
|
||||
cfg := new(mockedConfig)
|
||||
cfg.gui.APIKey = testAPIKey
|
||||
baseURL, cancel, err := startHTTP(cfg)
|
||||
baseURL, cancel, err := startHTTP(apiCfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -1090,9 +1099,9 @@ func TestOptionsRequest(t *testing.T) {
|
||||
func TestEventMasks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cfg := new(mockedConfig)
|
||||
defSub := new(mockedEventSub)
|
||||
diskSub := new(mockedEventSub)
|
||||
cfg := newMockedConfig()
|
||||
defSub := new(eventmocks.BufferedSubscription)
|
||||
diskSub := new(eventmocks.BufferedSubscription)
|
||||
svc := New(protocol.LocalDeviceID, cfg, "", "syncthing", nil, defSub, diskSub, events.NoopLogger, nil, nil, nil, nil, nil, nil, false).(*service)
|
||||
defer os.Remove(token)
|
||||
|
||||
|
@ -7,136 +7,15 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
"github.com/syncthing/syncthing/lib/config/mocks"
|
||||
)
|
||||
|
||||
type mockedConfig struct {
|
||||
gui config.GUIConfiguration
|
||||
}
|
||||
|
||||
func (c *mockedConfig) GUI() config.GUIConfiguration {
|
||||
return c.gui
|
||||
}
|
||||
|
||||
func (c *mockedConfig) ListenAddresses() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) LDAP() config.LDAPConfiguration {
|
||||
return config.LDAPConfiguration{}
|
||||
}
|
||||
|
||||
func (c *mockedConfig) RawCopy() config.Configuration {
|
||||
cfg := config.Configuration{}
|
||||
util.SetDefaults(&cfg.Options)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Options() config.OptionsConfiguration {
|
||||
return config.OptionsConfiguration{}
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Modify(config.ModifyFunction) (config.Waiter, error) {
|
||||
return noopWaiter{}, nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Subscribe(cm config.Committer) config.Configuration {
|
||||
return config.Configuration{}
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Unsubscribe(cm config.Committer) {}
|
||||
|
||||
func (c *mockedConfig) Folders() map[string]config.FolderConfiguration {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Devices() map[protocol.DeviceID]config.DeviceConfiguration {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) DeviceList() []config.DeviceConfiguration {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Save() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) RequiresRestart() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *mockedConfig) AddOrUpdatePendingDevice(device protocol.DeviceID, name, address string) {}
|
||||
|
||||
func (c *mockedConfig) AddOrUpdatePendingFolder(id, label string, device protocol.DeviceID) {}
|
||||
|
||||
func (c *mockedConfig) ConfigPath() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *mockedConfig) Folder(id string) (config.FolderConfiguration, bool) {
|
||||
return config.FolderConfiguration{}, false
|
||||
}
|
||||
|
||||
func (c *mockedConfig) FolderList() []config.FolderConfiguration {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) RemoveFolder(id string) (config.Waiter, error) {
|
||||
return noopWaiter{}, nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) FolderPasswords(device protocol.DeviceID) map[string]string {
|
||||
return nil
|
||||
}
|
||||
func (c *mockedConfig) Device(id protocol.DeviceID) (config.DeviceConfiguration, bool) {
|
||||
return config.DeviceConfiguration{}, false
|
||||
}
|
||||
|
||||
func (c *mockedConfig) RemoveDevice(id protocol.DeviceID) (config.Waiter, error) {
|
||||
return noopWaiter{}, nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) IgnoredDevice(id protocol.DeviceID) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *mockedConfig) IgnoredDevices() []config.ObservedDevice {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) IgnoredFolder(device protocol.DeviceID, folder string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *mockedConfig) DefaultFolder() config.FolderConfiguration {
|
||||
return config.FolderConfiguration{}
|
||||
}
|
||||
|
||||
func (c *mockedConfig) SetDefaultFolder(config.FolderConfiguration) (config.Waiter, error) {
|
||||
return noopWaiter{}, nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) DefaultDevice() config.DeviceConfiguration {
|
||||
return config.DeviceConfiguration{}
|
||||
}
|
||||
|
||||
func (c *mockedConfig) SetDefaultDevice(config.DeviceConfiguration) (config.Waiter, error) {
|
||||
return noopWaiter{}, nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) GlobalDiscoveryServers() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) StunServers() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *mockedConfig) MyID() protocol.DeviceID {
|
||||
return protocol.DeviceID{}
|
||||
func newMockedConfig() *mocks.Wrapper {
|
||||
m := &mocks.Wrapper{}
|
||||
m.ModifyReturns(noopWaiter{}, nil)
|
||||
m.RemoveFolderReturns(noopWaiter{}, nil)
|
||||
m.RemoveDeviceReturns(noopWaiter{}, nil)
|
||||
return m
|
||||
}
|
||||
|
||||
type noopWaiter struct{}
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2016 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/connections"
|
||||
)
|
||||
|
||||
type mockedConnections struct{}
|
||||
|
||||
func (m *mockedConnections) ListenerStatus() map[string]connections.ListenerStatusEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedConnections) ConnectionStatus() map[string]connections.ConnectionStatusEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedConnections) NATType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *mockedConnections) Serve(ctx context.Context) error { return nil }
|
||||
|
||||
func (m *mockedConnections) ExternalAddresses() []string { return nil }
|
||||
|
||||
func (m *mockedConnections) AllAddresses() []string { return nil }
|
@ -1,46 +0,0 @@
|
||||
// Copyright (C) 2016 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/discover"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
)
|
||||
|
||||
type mockedCachingMux struct{}
|
||||
|
||||
// from suture.Service
|
||||
|
||||
func (m *mockedCachingMux) Serve(ctx context.Context) error {
|
||||
select {}
|
||||
}
|
||||
|
||||
// from events.Finder
|
||||
|
||||
func (m *mockedCachingMux) Lookup(ctx context.Context, deviceID protocol.DeviceID) (direct []string, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedCachingMux) Error() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedCachingMux) String() string {
|
||||
return "mockedCachingMux"
|
||||
}
|
||||
|
||||
func (m *mockedCachingMux) Cache() map[protocol.DeviceID]discover.CacheEntry {
|
||||
return nil
|
||||
}
|
||||
|
||||
// from events.Manager
|
||||
|
||||
func (m *mockedCachingMux) ChildErrors() map[string]error {
|
||||
return nil
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2016 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
)
|
||||
|
||||
type mockedEventSub struct{}
|
||||
|
||||
func (s *mockedEventSub) Since(id int, into []events.Event, timeout time.Duration) []events.Event {
|
||||
select {}
|
||||
}
|
||||
|
||||
func (s *mockedEventSub) Mask() events.EventType { return 0 }
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2016 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/logger"
|
||||
)
|
||||
|
||||
type mockedLoggerRecorder struct{}
|
||||
|
||||
func (r *mockedLoggerRecorder) Since(t time.Time) []logger.Line {
|
||||
return []logger.Line{
|
||||
{
|
||||
When: time.Now(),
|
||||
Message: "Test message",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *mockedLoggerRecorder) Clear() {}
|
@ -1,199 +0,0 @@
|
||||
// Copyright (C) 2016 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/db"
|
||||
"github.com/syncthing/syncthing/lib/model"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
"github.com/syncthing/syncthing/lib/stats"
|
||||
"github.com/syncthing/syncthing/lib/ur/contract"
|
||||
"github.com/syncthing/syncthing/lib/versioner"
|
||||
)
|
||||
|
||||
type mockedModel struct{}
|
||||
|
||||
func (m *mockedModel) GlobalDirectoryTree(folder, prefix string, levels int, dirsOnly bool) ([]*model.TreeEntry, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) Completion(device protocol.DeviceID, folder string) model.FolderCompletion {
|
||||
return model.FolderCompletion{}
|
||||
}
|
||||
|
||||
func (m *mockedModel) Override(folder string) {}
|
||||
|
||||
func (m *mockedModel) Revert(folder string) {}
|
||||
|
||||
func (m *mockedModel) NeedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, []db.FileInfoTruncated, []db.FileInfoTruncated, error) {
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
|
||||
func (*mockedModel) RemoteNeedFolderFiles(folder string, device protocol.DeviceID, page, perpage int) ([]db.FileInfoTruncated, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (*mockedModel) LocalChangedFolderFiles(folder string, page, perpage int) ([]db.FileInfoTruncated, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) FolderProgressBytesCompleted(_ string) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *mockedModel) NumConnections() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *mockedModel) ConnectionStats() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) DeviceStatistics() (map[protocol.DeviceID]stats.DeviceStatistics, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) FolderStatistics() (map[string]stats.FolderStatistics, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) CurrentFolderFile(folder string, file string) (protocol.FileInfo, bool) {
|
||||
return protocol.FileInfo{}, false
|
||||
}
|
||||
|
||||
func (m *mockedModel) CurrentGlobalFile(folder string, file string) (protocol.FileInfo, bool) {
|
||||
return protocol.FileInfo{}, false
|
||||
}
|
||||
|
||||
func (m *mockedModel) ResetFolder(folder string) {
|
||||
}
|
||||
|
||||
func (m *mockedModel) Availability(folder string, file protocol.FileInfo, block protocol.BlockInfo) []model.Availability {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) LoadIgnores(folder string) ([]string, []string, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) CurrentIgnores(folder string) ([]string, []string, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) SetIgnores(folder string, content []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) GetFolderVersions(folder string) (map[string][]versioner.FileVersion, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) RestoreFolderVersions(folder string, versions map[string]time.Time) (map[string]error, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) PauseDevice(device protocol.DeviceID) {
|
||||
}
|
||||
|
||||
func (m *mockedModel) ResumeDevice(device protocol.DeviceID) {}
|
||||
|
||||
func (m *mockedModel) DelayScan(folder string, next time.Duration) {}
|
||||
|
||||
func (m *mockedModel) ScanFolder(folder string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) ScanFolders() map[string]error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) ScanFolderSubdirs(folder string, subs []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) BringToFront(folder, file string) {}
|
||||
|
||||
func (m *mockedModel) Connection(deviceID protocol.DeviceID) (protocol.Connection, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (m *mockedModel) State(folder string) (string, time.Time, error) {
|
||||
return "", time.Time{}, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) UsageReportingStats(r *contract.Report, version int, preview bool) {
|
||||
}
|
||||
|
||||
func (m *mockedModel) PendingDevices() (map[protocol.DeviceID]db.ObservedDevice, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) PendingFolders(device protocol.DeviceID) (map[string]db.PendingFolder, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) FolderErrors(folder string) ([]model.FileError, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) WatchError(folder string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) Serve(ctx context.Context) error { return nil }
|
||||
|
||||
func (m *mockedModel) Index(deviceID protocol.DeviceID, folder string, files []protocol.FileInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) IndexUpdate(deviceID protocol.DeviceID, folder string, files []protocol.FileInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) Request(deviceID protocol.DeviceID, folder, name string, blockNo, size int32, offset int64, hash []byte, weakHash uint32, fromTemporary bool) (protocol.RequestResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) ClusterConfig(deviceID protocol.DeviceID, config protocol.ClusterConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) Closed(conn protocol.Connection, err error) {}
|
||||
|
||||
func (m *mockedModel) DownloadProgress(deviceID protocol.DeviceID, folder string, updates []protocol.FileDownloadProgressUpdate) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) AddConnection(conn protocol.Connection, hello protocol.Hello) {}
|
||||
|
||||
func (m *mockedModel) OnHello(protocol.DeviceID, net.Addr, protocol.Hello) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) GetHello(protocol.DeviceID) protocol.HelloIntf {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedModel) StartDeadlockDetector(timeout time.Duration) {}
|
||||
|
||||
func (m *mockedModel) DBSnapshot(_ string) (*db.Snapshot, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type mockedFolderSummaryService struct{}
|
||||
|
||||
func (m *mockedFolderSummaryService) Serve(context.Context) error { return nil }
|
||||
|
||||
func (m *mockedFolderSummaryService) Summary(folder string) (map[string]interface{}, error) {
|
||||
return map[string]interface{}{"mocked": true}, nil
|
||||
}
|
||||
|
||||
func (m *mockedFolderSummaryService) OnEventRequest() {}
|
1745
lib/config/mocks/mocked_wrapper.go
Normal file
1745
lib/config/mocks/mocked_wrapper.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,8 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate counterfeiter -o mocks/mocked_wrapper.go --fake-name Wrapper . Wrapper
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
|
437
lib/connections/mocks/service.go
Normal file
437
lib/connections/mocks/service.go
Normal file
@ -0,0 +1,437 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/connections"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
AllAddressesStub func() []string
|
||||
allAddressesMutex sync.RWMutex
|
||||
allAddressesArgsForCall []struct {
|
||||
}
|
||||
allAddressesReturns struct {
|
||||
result1 []string
|
||||
}
|
||||
allAddressesReturnsOnCall map[int]struct {
|
||||
result1 []string
|
||||
}
|
||||
ConnectionStatusStub func() map[string]connections.ConnectionStatusEntry
|
||||
connectionStatusMutex sync.RWMutex
|
||||
connectionStatusArgsForCall []struct {
|
||||
}
|
||||
connectionStatusReturns struct {
|
||||
result1 map[string]connections.ConnectionStatusEntry
|
||||
}
|
||||
connectionStatusReturnsOnCall map[int]struct {
|
||||
result1 map[string]connections.ConnectionStatusEntry
|
||||
}
|
||||
ExternalAddressesStub func() []string
|
||||
externalAddressesMutex sync.RWMutex
|
||||
externalAddressesArgsForCall []struct {
|
||||
}
|
||||
externalAddressesReturns struct {
|
||||
result1 []string
|
||||
}
|
||||
externalAddressesReturnsOnCall map[int]struct {
|
||||
result1 []string
|
||||
}
|
||||
ListenerStatusStub func() map[string]connections.ListenerStatusEntry
|
||||
listenerStatusMutex sync.RWMutex
|
||||
listenerStatusArgsForCall []struct {
|
||||
}
|
||||
listenerStatusReturns struct {
|
||||
result1 map[string]connections.ListenerStatusEntry
|
||||
}
|
||||
listenerStatusReturnsOnCall map[int]struct {
|
||||
result1 map[string]connections.ListenerStatusEntry
|
||||
}
|
||||
NATTypeStub func() string
|
||||
nATTypeMutex sync.RWMutex
|
||||
nATTypeArgsForCall []struct {
|
||||
}
|
||||
nATTypeReturns struct {
|
||||
result1 string
|
||||
}
|
||||
nATTypeReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
ServeStub func(context.Context) error
|
||||
serveMutex sync.RWMutex
|
||||
serveArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
}
|
||||
serveReturns struct {
|
||||
result1 error
|
||||
}
|
||||
serveReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *Service) AllAddresses() []string {
|
||||
fake.allAddressesMutex.Lock()
|
||||
ret, specificReturn := fake.allAddressesReturnsOnCall[len(fake.allAddressesArgsForCall)]
|
||||
fake.allAddressesArgsForCall = append(fake.allAddressesArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.AllAddressesStub
|
||||
fakeReturns := fake.allAddressesReturns
|
||||
fake.recordInvocation("AllAddresses", []interface{}{})
|
||||
fake.allAddressesMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Service) AllAddressesCallCount() int {
|
||||
fake.allAddressesMutex.RLock()
|
||||
defer fake.allAddressesMutex.RUnlock()
|
||||
return len(fake.allAddressesArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Service) AllAddressesCalls(stub func() []string) {
|
||||
fake.allAddressesMutex.Lock()
|
||||
defer fake.allAddressesMutex.Unlock()
|
||||
fake.AllAddressesStub = stub
|
||||
}
|
||||
|
||||
func (fake *Service) AllAddressesReturns(result1 []string) {
|
||||
fake.allAddressesMutex.Lock()
|
||||
defer fake.allAddressesMutex.Unlock()
|
||||
fake.AllAddressesStub = nil
|
||||
fake.allAddressesReturns = struct {
|
||||
result1 []string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) AllAddressesReturnsOnCall(i int, result1 []string) {
|
||||
fake.allAddressesMutex.Lock()
|
||||
defer fake.allAddressesMutex.Unlock()
|
||||
fake.AllAddressesStub = nil
|
||||
if fake.allAddressesReturnsOnCall == nil {
|
||||
fake.allAddressesReturnsOnCall = make(map[int]struct {
|
||||
result1 []string
|
||||
})
|
||||
}
|
||||
fake.allAddressesReturnsOnCall[i] = struct {
|
||||
result1 []string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ConnectionStatus() map[string]connections.ConnectionStatusEntry {
|
||||
fake.connectionStatusMutex.Lock()
|
||||
ret, specificReturn := fake.connectionStatusReturnsOnCall[len(fake.connectionStatusArgsForCall)]
|
||||
fake.connectionStatusArgsForCall = append(fake.connectionStatusArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ConnectionStatusStub
|
||||
fakeReturns := fake.connectionStatusReturns
|
||||
fake.recordInvocation("ConnectionStatus", []interface{}{})
|
||||
fake.connectionStatusMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Service) ConnectionStatusCallCount() int {
|
||||
fake.connectionStatusMutex.RLock()
|
||||
defer fake.connectionStatusMutex.RUnlock()
|
||||
return len(fake.connectionStatusArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Service) ConnectionStatusCalls(stub func() map[string]connections.ConnectionStatusEntry) {
|
||||
fake.connectionStatusMutex.Lock()
|
||||
defer fake.connectionStatusMutex.Unlock()
|
||||
fake.ConnectionStatusStub = stub
|
||||
}
|
||||
|
||||
func (fake *Service) ConnectionStatusReturns(result1 map[string]connections.ConnectionStatusEntry) {
|
||||
fake.connectionStatusMutex.Lock()
|
||||
defer fake.connectionStatusMutex.Unlock()
|
||||
fake.ConnectionStatusStub = nil
|
||||
fake.connectionStatusReturns = struct {
|
||||
result1 map[string]connections.ConnectionStatusEntry
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ConnectionStatusReturnsOnCall(i int, result1 map[string]connections.ConnectionStatusEntry) {
|
||||
fake.connectionStatusMutex.Lock()
|
||||
defer fake.connectionStatusMutex.Unlock()
|
||||
fake.ConnectionStatusStub = nil
|
||||
if fake.connectionStatusReturnsOnCall == nil {
|
||||
fake.connectionStatusReturnsOnCall = make(map[int]struct {
|
||||
result1 map[string]connections.ConnectionStatusEntry
|
||||
})
|
||||
}
|
||||
fake.connectionStatusReturnsOnCall[i] = struct {
|
||||
result1 map[string]connections.ConnectionStatusEntry
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ExternalAddresses() []string {
|
||||
fake.externalAddressesMutex.Lock()
|
||||
ret, specificReturn := fake.externalAddressesReturnsOnCall[len(fake.externalAddressesArgsForCall)]
|
||||
fake.externalAddressesArgsForCall = append(fake.externalAddressesArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ExternalAddressesStub
|
||||
fakeReturns := fake.externalAddressesReturns
|
||||
fake.recordInvocation("ExternalAddresses", []interface{}{})
|
||||
fake.externalAddressesMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Service) ExternalAddressesCallCount() int {
|
||||
fake.externalAddressesMutex.RLock()
|
||||
defer fake.externalAddressesMutex.RUnlock()
|
||||
return len(fake.externalAddressesArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Service) ExternalAddressesCalls(stub func() []string) {
|
||||
fake.externalAddressesMutex.Lock()
|
||||
defer fake.externalAddressesMutex.Unlock()
|
||||
fake.ExternalAddressesStub = stub
|
||||
}
|
||||
|
||||
func (fake *Service) ExternalAddressesReturns(result1 []string) {
|
||||
fake.externalAddressesMutex.Lock()
|
||||
defer fake.externalAddressesMutex.Unlock()
|
||||
fake.ExternalAddressesStub = nil
|
||||
fake.externalAddressesReturns = struct {
|
||||
result1 []string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ExternalAddressesReturnsOnCall(i int, result1 []string) {
|
||||
fake.externalAddressesMutex.Lock()
|
||||
defer fake.externalAddressesMutex.Unlock()
|
||||
fake.ExternalAddressesStub = nil
|
||||
if fake.externalAddressesReturnsOnCall == nil {
|
||||
fake.externalAddressesReturnsOnCall = make(map[int]struct {
|
||||
result1 []string
|
||||
})
|
||||
}
|
||||
fake.externalAddressesReturnsOnCall[i] = struct {
|
||||
result1 []string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ListenerStatus() map[string]connections.ListenerStatusEntry {
|
||||
fake.listenerStatusMutex.Lock()
|
||||
ret, specificReturn := fake.listenerStatusReturnsOnCall[len(fake.listenerStatusArgsForCall)]
|
||||
fake.listenerStatusArgsForCall = append(fake.listenerStatusArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ListenerStatusStub
|
||||
fakeReturns := fake.listenerStatusReturns
|
||||
fake.recordInvocation("ListenerStatus", []interface{}{})
|
||||
fake.listenerStatusMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Service) ListenerStatusCallCount() int {
|
||||
fake.listenerStatusMutex.RLock()
|
||||
defer fake.listenerStatusMutex.RUnlock()
|
||||
return len(fake.listenerStatusArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Service) ListenerStatusCalls(stub func() map[string]connections.ListenerStatusEntry) {
|
||||
fake.listenerStatusMutex.Lock()
|
||||
defer fake.listenerStatusMutex.Unlock()
|
||||
fake.ListenerStatusStub = stub
|
||||
}
|
||||
|
||||
func (fake *Service) ListenerStatusReturns(result1 map[string]connections.ListenerStatusEntry) {
|
||||
fake.listenerStatusMutex.Lock()
|
||||
defer fake.listenerStatusMutex.Unlock()
|
||||
fake.ListenerStatusStub = nil
|
||||
fake.listenerStatusReturns = struct {
|
||||
result1 map[string]connections.ListenerStatusEntry
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ListenerStatusReturnsOnCall(i int, result1 map[string]connections.ListenerStatusEntry) {
|
||||
fake.listenerStatusMutex.Lock()
|
||||
defer fake.listenerStatusMutex.Unlock()
|
||||
fake.ListenerStatusStub = nil
|
||||
if fake.listenerStatusReturnsOnCall == nil {
|
||||
fake.listenerStatusReturnsOnCall = make(map[int]struct {
|
||||
result1 map[string]connections.ListenerStatusEntry
|
||||
})
|
||||
}
|
||||
fake.listenerStatusReturnsOnCall[i] = struct {
|
||||
result1 map[string]connections.ListenerStatusEntry
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) NATType() string {
|
||||
fake.nATTypeMutex.Lock()
|
||||
ret, specificReturn := fake.nATTypeReturnsOnCall[len(fake.nATTypeArgsForCall)]
|
||||
fake.nATTypeArgsForCall = append(fake.nATTypeArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.NATTypeStub
|
||||
fakeReturns := fake.nATTypeReturns
|
||||
fake.recordInvocation("NATType", []interface{}{})
|
||||
fake.nATTypeMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Service) NATTypeCallCount() int {
|
||||
fake.nATTypeMutex.RLock()
|
||||
defer fake.nATTypeMutex.RUnlock()
|
||||
return len(fake.nATTypeArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Service) NATTypeCalls(stub func() string) {
|
||||
fake.nATTypeMutex.Lock()
|
||||
defer fake.nATTypeMutex.Unlock()
|
||||
fake.NATTypeStub = stub
|
||||
}
|
||||
|
||||
func (fake *Service) NATTypeReturns(result1 string) {
|
||||
fake.nATTypeMutex.Lock()
|
||||
defer fake.nATTypeMutex.Unlock()
|
||||
fake.NATTypeStub = nil
|
||||
fake.nATTypeReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) NATTypeReturnsOnCall(i int, result1 string) {
|
||||
fake.nATTypeMutex.Lock()
|
||||
defer fake.nATTypeMutex.Unlock()
|
||||
fake.NATTypeStub = nil
|
||||
if fake.nATTypeReturnsOnCall == nil {
|
||||
fake.nATTypeReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.nATTypeReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) Serve(arg1 context.Context) error {
|
||||
fake.serveMutex.Lock()
|
||||
ret, specificReturn := fake.serveReturnsOnCall[len(fake.serveArgsForCall)]
|
||||
fake.serveArgsForCall = append(fake.serveArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
}{arg1})
|
||||
stub := fake.ServeStub
|
||||
fakeReturns := fake.serveReturns
|
||||
fake.recordInvocation("Serve", []interface{}{arg1})
|
||||
fake.serveMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Service) ServeCallCount() int {
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
return len(fake.serveArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Service) ServeCalls(stub func(context.Context) error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = stub
|
||||
}
|
||||
|
||||
func (fake *Service) ServeArgsForCall(i int) context.Context {
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
argsForCall := fake.serveArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *Service) ServeReturns(result1 error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = nil
|
||||
fake.serveReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) ServeReturnsOnCall(i int, result1 error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = nil
|
||||
if fake.serveReturnsOnCall == nil {
|
||||
fake.serveReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.serveReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Service) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.allAddressesMutex.RLock()
|
||||
defer fake.allAddressesMutex.RUnlock()
|
||||
fake.connectionStatusMutex.RLock()
|
||||
defer fake.connectionStatusMutex.RUnlock()
|
||||
fake.externalAddressesMutex.RLock()
|
||||
defer fake.externalAddressesMutex.RUnlock()
|
||||
fake.listenerStatusMutex.RLock()
|
||||
defer fake.listenerStatusMutex.RUnlock()
|
||||
fake.nATTypeMutex.RLock()
|
||||
defer fake.nATTypeMutex.RUnlock()
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *Service) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
||||
|
||||
var _ connections.Service = new(Service)
|
@ -4,6 +4,8 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate counterfeiter -o mocks/service.go --fake-name Service . Service
|
||||
|
||||
package connections
|
||||
|
||||
import (
|
||||
|
@ -4,9 +4,6 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate go run ../../proto/scripts/protofmt.go local.proto
|
||||
//go:generate protoc -I ../../ -I . --gogofast_out=. local.proto
|
||||
|
||||
package discover
|
||||
|
||||
import (
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: local.proto
|
||||
// source: lib/discover/local.proto
|
||||
|
||||
package discover
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
github_com_syncthing_syncthing_lib_protocol "github.com/syncthing/syncthing/lib/protocol"
|
||||
_ "github.com/syncthing/syncthing/proto/ext"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
@ -25,16 +26,16 @@ var _ = math.Inf
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type Announce struct {
|
||||
ID github_com_syncthing_syncthing_lib_protocol.DeviceID `protobuf:"bytes,1,opt,name=id,proto3,customtype=github.com/syncthing/syncthing/lib/protocol.DeviceID" json:"id"`
|
||||
Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"`
|
||||
InstanceID int64 `protobuf:"varint,3,opt,name=instance_id,json=instanceId,proto3" json:"instance_id,omitempty"`
|
||||
ID github_com_syncthing_syncthing_lib_protocol.DeviceID `protobuf:"bytes,1,opt,name=id,proto3,customtype=github.com/syncthing/syncthing/lib/protocol.DeviceID" json:"id" xml:"id"`
|
||||
Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses" xml:"address"`
|
||||
InstanceID int64 `protobuf:"varint,3,opt,name=instance_id,json=instanceId,proto3" json:"instanceId" xml:"instanceId"`
|
||||
}
|
||||
|
||||
func (m *Announce) Reset() { *m = Announce{} }
|
||||
func (m *Announce) String() string { return proto.CompactTextString(m) }
|
||||
func (*Announce) ProtoMessage() {}
|
||||
func (*Announce) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_aaf1a48d01603033, []int{0}
|
||||
return fileDescriptor_18afca46562fdaf4, []int{0}
|
||||
}
|
||||
func (m *Announce) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@ -67,26 +68,31 @@ func init() {
|
||||
proto.RegisterType((*Announce)(nil), "discover.Announce")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("local.proto", fileDescriptor_aaf1a48d01603033) }
|
||||
func init() { proto.RegisterFile("lib/discover/local.proto", fileDescriptor_18afca46562fdaf4) }
|
||||
|
||||
var fileDescriptor_aaf1a48d01603033 = []byte{
|
||||
// 252 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x8e, 0x31, 0x4e, 0x84, 0x40,
|
||||
0x14, 0x86, 0x67, 0x20, 0x31, 0xbb, 0xb3, 0xc6, 0x82, 0x8a, 0x18, 0x33, 0x10, 0x6d, 0xa8, 0xa0,
|
||||
0xd0, 0x0b, 0x48, 0x68, 0xa6, 0xe5, 0x02, 0x06, 0x66, 0x46, 0xf6, 0x25, 0x38, 0x6f, 0xc3, 0xc0,
|
||||
0x26, 0xde, 0xc2, 0x23, 0x78, 0x01, 0xef, 0x41, 0xb9, 0xa5, 0xb1, 0x20, 0x3a, 0x5c, 0xc4, 0x04,
|
||||
0x34, 0xda, 0x7d, 0xef, 0xcb, 0x97, 0xbc, 0x9f, 0xed, 0x5a, 0x94, 0x55, 0x9b, 0x1e, 0x3a, 0xec,
|
||||
0x31, 0xd8, 0x28, 0xb0, 0x12, 0x8f, 0xba, 0xbb, 0xbc, 0xe9, 0xf4, 0x01, 0x6d, 0xb6, 0xe8, 0x7a,
|
||||
0x78, 0xcc, 0x1a, 0x6c, 0x70, 0x39, 0x16, 0x5a, 0xf3, 0xeb, 0x37, 0xca, 0x36, 0xf7, 0xc6, 0xe0,
|
||||
0x60, 0xa4, 0x0e, 0x4a, 0xe6, 0x81, 0x0a, 0x69, 0x4c, 0x93, 0xf3, 0x3c, 0x1f, 0xa7, 0x88, 0x7c,
|
||||
0x4c, 0xd1, 0x5d, 0x03, 0xfd, 0x7e, 0xa8, 0x53, 0x89, 0x4f, 0x99, 0x7d, 0x36, 0xb2, 0xdf, 0x83,
|
||||
0x69, 0xfe, 0x51, 0x0b, 0xf5, 0xfa, 0x42, 0x62, 0x9b, 0x16, 0xfa, 0x08, 0x52, 0x8b, 0xc2, 0x4d,
|
||||
0x91, 0x27, 0x8a, 0xd2, 0x03, 0x15, 0x5c, 0xb1, 0x6d, 0xa5, 0x54, 0xa7, 0xad, 0xd5, 0x36, 0xf4,
|
||||
0x62, 0x3f, 0xd9, 0x96, 0x7f, 0x22, 0xc8, 0xd8, 0x0e, 0x8c, 0xed, 0x2b, 0x23, 0xf5, 0x03, 0xa8,
|
||||
0xd0, 0x8f, 0x69, 0xe2, 0xe7, 0x17, 0x6e, 0x8a, 0x98, 0xf8, 0xd1, 0xa2, 0x28, 0xd9, 0x6f, 0x22,
|
||||
0x54, 0x1e, 0x8f, 0x5f, 0x9c, 0x8c, 0x8e, 0xd3, 0x93, 0xe3, 0xf4, 0xd3, 0x71, 0xf2, 0x32, 0x73,
|
||||
0xf2, 0x3a, 0x73, 0x7a, 0x9a, 0x39, 0x79, 0x9f, 0x39, 0xa9, 0xcf, 0x96, 0x35, 0xb7, 0xdf, 0x01,
|
||||
0x00, 0x00, 0xff, 0xff, 0xbc, 0x46, 0xaf, 0x1d, 0x16, 0x01, 0x00, 0x00,
|
||||
var fileDescriptor_18afca46562fdaf4 = []byte{
|
||||
// 334 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0x31, 0x6b, 0xe3, 0x30,
|
||||
0x18, 0x86, 0x2d, 0x05, 0x8e, 0x44, 0x77, 0x07, 0x87, 0x27, 0x93, 0x41, 0x0a, 0xbe, 0x0c, 0x81,
|
||||
0x42, 0x3c, 0xb4, 0x53, 0x29, 0x85, 0x1a, 0x2f, 0x1e, 0xba, 0x64, 0xec, 0xd0, 0x10, 0x4b, 0xaa,
|
||||
0x23, 0x70, 0xa4, 0x60, 0x39, 0x21, 0xfd, 0x07, 0x1d, 0x4b, 0xb6, 0x6e, 0xfd, 0x39, 0x19, 0x3d,
|
||||
0x96, 0x0e, 0x82, 0xd8, 0x5b, 0xc6, 0xfc, 0x82, 0x12, 0x25, 0x69, 0x32, 0x76, 0x7b, 0xf5, 0xe8,
|
||||
0x95, 0x78, 0xf8, 0x3e, 0xe4, 0x65, 0x22, 0x09, 0x98, 0xd0, 0x54, 0xcd, 0x79, 0x1e, 0x64, 0x8a,
|
||||
0x8e, 0xb2, 0xfe, 0x34, 0x57, 0x85, 0x72, 0x9b, 0x47, 0xda, 0xfe, 0x9f, 0xf3, 0xa9, 0xd2, 0x81,
|
||||
0xc5, 0xc9, 0xec, 0x29, 0x48, 0x55, 0xaa, 0xec, 0xc1, 0xa6, 0x7d, 0xbd, 0xdd, 0xe2, 0x8b, 0x62,
|
||||
0x1f, 0xfd, 0x37, 0x88, 0x9a, 0x77, 0x52, 0xaa, 0x99, 0xa4, 0xdc, 0x95, 0x08, 0x0a, 0xe6, 0x81,
|
||||
0x0e, 0xe8, 0xfd, 0x09, 0x1f, 0x57, 0x86, 0x38, 0x9f, 0x86, 0x5c, 0xa5, 0xa2, 0x18, 0xcf, 0x92,
|
||||
0x3e, 0x55, 0x93, 0x40, 0x3f, 0x4b, 0x5a, 0x8c, 0x85, 0x4c, 0xcf, 0xd2, 0xce, 0xc9, 0x7e, 0x45,
|
||||
0x55, 0xd6, 0x8f, 0xf8, 0x5c, 0x50, 0x1e, 0x47, 0x95, 0x21, 0x30, 0x8e, 0x36, 0x86, 0x40, 0xc1,
|
||||
0xb6, 0x86, 0x34, 0x17, 0x93, 0xec, 0xda, 0x17, 0xcc, 0x7f, 0x29, 0xbb, 0x60, 0x59, 0x76, 0x61,
|
||||
0x1c, 0x0d, 0xa0, 0x60, 0xee, 0x0d, 0x6a, 0x8d, 0x18, 0xcb, 0xb9, 0xd6, 0x5c, 0x7b, 0xb0, 0xd3,
|
||||
0xe8, 0xb5, 0x42, 0xbc, 0x31, 0xe4, 0x04, 0xb7, 0x86, 0xfc, 0xb5, 0x6f, 0x0f, 0xc4, 0x1f, 0x9c,
|
||||
0xee, 0xdc, 0x21, 0xfa, 0x2d, 0xa4, 0x2e, 0x46, 0x92, 0xf2, 0xa1, 0x60, 0x5e, 0xa3, 0x03, 0x7a,
|
||||
0x8d, 0xf0, 0xb6, 0x32, 0x04, 0xc5, 0x07, 0x6c, 0x15, 0xd0, 0xb1, 0x14, 0xef, 0x54, 0xfe, 0xed,
|
||||
0x55, 0xbe, 0x91, 0xbf, 0x2c, 0xbb, 0x67, 0xfd, 0xc1, 0x59, 0x3b, 0xbc, 0x5f, 0xad, 0xb1, 0x53,
|
||||
0xae, 0xb1, 0xb3, 0xaa, 0x30, 0x28, 0x2b, 0x0c, 0x5e, 0x6b, 0xec, 0xbc, 0xd7, 0x18, 0x94, 0x35,
|
||||
0x76, 0x3e, 0x6a, 0xec, 0x3c, 0x5c, 0xfc, 0x60, 0x38, 0xc7, 0xd5, 0x24, 0xbf, 0xec, 0x98, 0x2e,
|
||||
0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0xdc, 0xe8, 0x9a, 0xd0, 0xc7, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Announce) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -1,18 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package discover;
|
||||
|
||||
import "repos/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
option (gogoproto.sizer_all) = false;
|
||||
option (gogoproto.protosizer_all) = true;
|
||||
option (gogoproto.goproto_unkeyed_all) = false;
|
||||
option (gogoproto.goproto_unrecognized_all) = false;
|
||||
option (gogoproto.goproto_sizecache_all) = false;
|
||||
|
||||
message Announce {
|
||||
bytes id = 1 [(gogoproto.customname) = "ID", (gogoproto.customtype) = "github.com/syncthing/syncthing/lib/protocol.DeviceID", (gogoproto.nullable) = false];
|
||||
repeated string addresses = 2;
|
||||
int64 instance_id = 3 [(gogoproto.customname) = "InstanceID"];
|
||||
}
|
@ -4,6 +4,8 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate counterfeiter -o mocks/manager.go --fake-name Manager . Manager
|
||||
|
||||
package discover
|
||||
|
||||
import (
|
||||
|
454
lib/discover/mocks/manager.go
Normal file
454
lib/discover/mocks/manager.go
Normal file
@ -0,0 +1,454 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/discover"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
CacheStub func() map[protocol.DeviceID]discover.CacheEntry
|
||||
cacheMutex sync.RWMutex
|
||||
cacheArgsForCall []struct {
|
||||
}
|
||||
cacheReturns struct {
|
||||
result1 map[protocol.DeviceID]discover.CacheEntry
|
||||
}
|
||||
cacheReturnsOnCall map[int]struct {
|
||||
result1 map[protocol.DeviceID]discover.CacheEntry
|
||||
}
|
||||
ChildErrorsStub func() map[string]error
|
||||
childErrorsMutex sync.RWMutex
|
||||
childErrorsArgsForCall []struct {
|
||||
}
|
||||
childErrorsReturns struct {
|
||||
result1 map[string]error
|
||||
}
|
||||
childErrorsReturnsOnCall map[int]struct {
|
||||
result1 map[string]error
|
||||
}
|
||||
ErrorStub func() error
|
||||
errorMutex sync.RWMutex
|
||||
errorArgsForCall []struct {
|
||||
}
|
||||
errorReturns struct {
|
||||
result1 error
|
||||
}
|
||||
errorReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
LookupStub func(context.Context, protocol.DeviceID) ([]string, error)
|
||||
lookupMutex sync.RWMutex
|
||||
lookupArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
arg2 protocol.DeviceID
|
||||
}
|
||||
lookupReturns struct {
|
||||
result1 []string
|
||||
result2 error
|
||||
}
|
||||
lookupReturnsOnCall map[int]struct {
|
||||
result1 []string
|
||||
result2 error
|
||||
}
|
||||
ServeStub func(context.Context) error
|
||||
serveMutex sync.RWMutex
|
||||
serveArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
}
|
||||
serveReturns struct {
|
||||
result1 error
|
||||
}
|
||||
serveReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
StringStub func() string
|
||||
stringMutex sync.RWMutex
|
||||
stringArgsForCall []struct {
|
||||
}
|
||||
stringReturns struct {
|
||||
result1 string
|
||||
}
|
||||
stringReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *Manager) Cache() map[protocol.DeviceID]discover.CacheEntry {
|
||||
fake.cacheMutex.Lock()
|
||||
ret, specificReturn := fake.cacheReturnsOnCall[len(fake.cacheArgsForCall)]
|
||||
fake.cacheArgsForCall = append(fake.cacheArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.CacheStub
|
||||
fakeReturns := fake.cacheReturns
|
||||
fake.recordInvocation("Cache", []interface{}{})
|
||||
fake.cacheMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Manager) CacheCallCount() int {
|
||||
fake.cacheMutex.RLock()
|
||||
defer fake.cacheMutex.RUnlock()
|
||||
return len(fake.cacheArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Manager) CacheCalls(stub func() map[protocol.DeviceID]discover.CacheEntry) {
|
||||
fake.cacheMutex.Lock()
|
||||
defer fake.cacheMutex.Unlock()
|
||||
fake.CacheStub = stub
|
||||
}
|
||||
|
||||
func (fake *Manager) CacheReturns(result1 map[protocol.DeviceID]discover.CacheEntry) {
|
||||
fake.cacheMutex.Lock()
|
||||
defer fake.cacheMutex.Unlock()
|
||||
fake.CacheStub = nil
|
||||
fake.cacheReturns = struct {
|
||||
result1 map[protocol.DeviceID]discover.CacheEntry
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) CacheReturnsOnCall(i int, result1 map[protocol.DeviceID]discover.CacheEntry) {
|
||||
fake.cacheMutex.Lock()
|
||||
defer fake.cacheMutex.Unlock()
|
||||
fake.CacheStub = nil
|
||||
if fake.cacheReturnsOnCall == nil {
|
||||
fake.cacheReturnsOnCall = make(map[int]struct {
|
||||
result1 map[protocol.DeviceID]discover.CacheEntry
|
||||
})
|
||||
}
|
||||
fake.cacheReturnsOnCall[i] = struct {
|
||||
result1 map[protocol.DeviceID]discover.CacheEntry
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) ChildErrors() map[string]error {
|
||||
fake.childErrorsMutex.Lock()
|
||||
ret, specificReturn := fake.childErrorsReturnsOnCall[len(fake.childErrorsArgsForCall)]
|
||||
fake.childErrorsArgsForCall = append(fake.childErrorsArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ChildErrorsStub
|
||||
fakeReturns := fake.childErrorsReturns
|
||||
fake.recordInvocation("ChildErrors", []interface{}{})
|
||||
fake.childErrorsMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Manager) ChildErrorsCallCount() int {
|
||||
fake.childErrorsMutex.RLock()
|
||||
defer fake.childErrorsMutex.RUnlock()
|
||||
return len(fake.childErrorsArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Manager) ChildErrorsCalls(stub func() map[string]error) {
|
||||
fake.childErrorsMutex.Lock()
|
||||
defer fake.childErrorsMutex.Unlock()
|
||||
fake.ChildErrorsStub = stub
|
||||
}
|
||||
|
||||
func (fake *Manager) ChildErrorsReturns(result1 map[string]error) {
|
||||
fake.childErrorsMutex.Lock()
|
||||
defer fake.childErrorsMutex.Unlock()
|
||||
fake.ChildErrorsStub = nil
|
||||
fake.childErrorsReturns = struct {
|
||||
result1 map[string]error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) ChildErrorsReturnsOnCall(i int, result1 map[string]error) {
|
||||
fake.childErrorsMutex.Lock()
|
||||
defer fake.childErrorsMutex.Unlock()
|
||||
fake.ChildErrorsStub = nil
|
||||
if fake.childErrorsReturnsOnCall == nil {
|
||||
fake.childErrorsReturnsOnCall = make(map[int]struct {
|
||||
result1 map[string]error
|
||||
})
|
||||
}
|
||||
fake.childErrorsReturnsOnCall[i] = struct {
|
||||
result1 map[string]error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) Error() error {
|
||||
fake.errorMutex.Lock()
|
||||
ret, specificReturn := fake.errorReturnsOnCall[len(fake.errorArgsForCall)]
|
||||
fake.errorArgsForCall = append(fake.errorArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ErrorStub
|
||||
fakeReturns := fake.errorReturns
|
||||
fake.recordInvocation("Error", []interface{}{})
|
||||
fake.errorMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Manager) ErrorCallCount() int {
|
||||
fake.errorMutex.RLock()
|
||||
defer fake.errorMutex.RUnlock()
|
||||
return len(fake.errorArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Manager) ErrorCalls(stub func() error) {
|
||||
fake.errorMutex.Lock()
|
||||
defer fake.errorMutex.Unlock()
|
||||
fake.ErrorStub = stub
|
||||
}
|
||||
|
||||
func (fake *Manager) ErrorReturns(result1 error) {
|
||||
fake.errorMutex.Lock()
|
||||
defer fake.errorMutex.Unlock()
|
||||
fake.ErrorStub = nil
|
||||
fake.errorReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) ErrorReturnsOnCall(i int, result1 error) {
|
||||
fake.errorMutex.Lock()
|
||||
defer fake.errorMutex.Unlock()
|
||||
fake.ErrorStub = nil
|
||||
if fake.errorReturnsOnCall == nil {
|
||||
fake.errorReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.errorReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) Lookup(arg1 context.Context, arg2 protocol.DeviceID) ([]string, error) {
|
||||
fake.lookupMutex.Lock()
|
||||
ret, specificReturn := fake.lookupReturnsOnCall[len(fake.lookupArgsForCall)]
|
||||
fake.lookupArgsForCall = append(fake.lookupArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
arg2 protocol.DeviceID
|
||||
}{arg1, arg2})
|
||||
stub := fake.LookupStub
|
||||
fakeReturns := fake.lookupReturns
|
||||
fake.recordInvocation("Lookup", []interface{}{arg1, arg2})
|
||||
fake.lookupMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1, ret.result2
|
||||
}
|
||||
return fakeReturns.result1, fakeReturns.result2
|
||||
}
|
||||
|
||||
func (fake *Manager) LookupCallCount() int {
|
||||
fake.lookupMutex.RLock()
|
||||
defer fake.lookupMutex.RUnlock()
|
||||
return len(fake.lookupArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Manager) LookupCalls(stub func(context.Context, protocol.DeviceID) ([]string, error)) {
|
||||
fake.lookupMutex.Lock()
|
||||
defer fake.lookupMutex.Unlock()
|
||||
fake.LookupStub = stub
|
||||
}
|
||||
|
||||
func (fake *Manager) LookupArgsForCall(i int) (context.Context, protocol.DeviceID) {
|
||||
fake.lookupMutex.RLock()
|
||||
defer fake.lookupMutex.RUnlock()
|
||||
argsForCall := fake.lookupArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *Manager) LookupReturns(result1 []string, result2 error) {
|
||||
fake.lookupMutex.Lock()
|
||||
defer fake.lookupMutex.Unlock()
|
||||
fake.LookupStub = nil
|
||||
fake.lookupReturns = struct {
|
||||
result1 []string
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *Manager) LookupReturnsOnCall(i int, result1 []string, result2 error) {
|
||||
fake.lookupMutex.Lock()
|
||||
defer fake.lookupMutex.Unlock()
|
||||
fake.LookupStub = nil
|
||||
if fake.lookupReturnsOnCall == nil {
|
||||
fake.lookupReturnsOnCall = make(map[int]struct {
|
||||
result1 []string
|
||||
result2 error
|
||||
})
|
||||
}
|
||||
fake.lookupReturnsOnCall[i] = struct {
|
||||
result1 []string
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *Manager) Serve(arg1 context.Context) error {
|
||||
fake.serveMutex.Lock()
|
||||
ret, specificReturn := fake.serveReturnsOnCall[len(fake.serveArgsForCall)]
|
||||
fake.serveArgsForCall = append(fake.serveArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
}{arg1})
|
||||
stub := fake.ServeStub
|
||||
fakeReturns := fake.serveReturns
|
||||
fake.recordInvocation("Serve", []interface{}{arg1})
|
||||
fake.serveMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Manager) ServeCallCount() int {
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
return len(fake.serveArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Manager) ServeCalls(stub func(context.Context) error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = stub
|
||||
}
|
||||
|
||||
func (fake *Manager) ServeArgsForCall(i int) context.Context {
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
argsForCall := fake.serveArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *Manager) ServeReturns(result1 error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = nil
|
||||
fake.serveReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) ServeReturnsOnCall(i int, result1 error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = nil
|
||||
if fake.serveReturnsOnCall == nil {
|
||||
fake.serveReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.serveReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) String() string {
|
||||
fake.stringMutex.Lock()
|
||||
ret, specificReturn := fake.stringReturnsOnCall[len(fake.stringArgsForCall)]
|
||||
fake.stringArgsForCall = append(fake.stringArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.StringStub
|
||||
fakeReturns := fake.stringReturns
|
||||
fake.recordInvocation("String", []interface{}{})
|
||||
fake.stringMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Manager) StringCallCount() int {
|
||||
fake.stringMutex.RLock()
|
||||
defer fake.stringMutex.RUnlock()
|
||||
return len(fake.stringArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Manager) StringCalls(stub func() string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = stub
|
||||
}
|
||||
|
||||
func (fake *Manager) StringReturns(result1 string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = nil
|
||||
fake.stringReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) StringReturnsOnCall(i int, result1 string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = nil
|
||||
if fake.stringReturnsOnCall == nil {
|
||||
fake.stringReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.stringReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Manager) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.cacheMutex.RLock()
|
||||
defer fake.cacheMutex.RUnlock()
|
||||
fake.childErrorsMutex.RLock()
|
||||
defer fake.childErrorsMutex.RUnlock()
|
||||
fake.errorMutex.RLock()
|
||||
defer fake.errorMutex.RUnlock()
|
||||
fake.lookupMutex.RLock()
|
||||
defer fake.lookupMutex.RUnlock()
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
fake.stringMutex.RLock()
|
||||
defer fake.stringMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *Manager) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
||||
|
||||
var _ discover.Manager = new(Manager)
|
@ -4,6 +4,8 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate counterfeiter -o mocks/buffered_subscription.go --fake-name BufferedSubscription . BufferedSubscription
|
||||
|
||||
// Package events provides event subscription and polling functionality.
|
||||
package events
|
||||
|
||||
|
186
lib/events/mocks/buffered_subscription.go
Normal file
186
lib/events/mocks/buffered_subscription.go
Normal file
@ -0,0 +1,186 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
)
|
||||
|
||||
type BufferedSubscription struct {
|
||||
MaskStub func() events.EventType
|
||||
maskMutex sync.RWMutex
|
||||
maskArgsForCall []struct {
|
||||
}
|
||||
maskReturns struct {
|
||||
result1 events.EventType
|
||||
}
|
||||
maskReturnsOnCall map[int]struct {
|
||||
result1 events.EventType
|
||||
}
|
||||
SinceStub func(int, []events.Event, time.Duration) []events.Event
|
||||
sinceMutex sync.RWMutex
|
||||
sinceArgsForCall []struct {
|
||||
arg1 int
|
||||
arg2 []events.Event
|
||||
arg3 time.Duration
|
||||
}
|
||||
sinceReturns struct {
|
||||
result1 []events.Event
|
||||
}
|
||||
sinceReturnsOnCall map[int]struct {
|
||||
result1 []events.Event
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) Mask() events.EventType {
|
||||
fake.maskMutex.Lock()
|
||||
ret, specificReturn := fake.maskReturnsOnCall[len(fake.maskArgsForCall)]
|
||||
fake.maskArgsForCall = append(fake.maskArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.MaskStub
|
||||
fakeReturns := fake.maskReturns
|
||||
fake.recordInvocation("Mask", []interface{}{})
|
||||
fake.maskMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) MaskCallCount() int {
|
||||
fake.maskMutex.RLock()
|
||||
defer fake.maskMutex.RUnlock()
|
||||
return len(fake.maskArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) MaskCalls(stub func() events.EventType) {
|
||||
fake.maskMutex.Lock()
|
||||
defer fake.maskMutex.Unlock()
|
||||
fake.MaskStub = stub
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) MaskReturns(result1 events.EventType) {
|
||||
fake.maskMutex.Lock()
|
||||
defer fake.maskMutex.Unlock()
|
||||
fake.MaskStub = nil
|
||||
fake.maskReturns = struct {
|
||||
result1 events.EventType
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) MaskReturnsOnCall(i int, result1 events.EventType) {
|
||||
fake.maskMutex.Lock()
|
||||
defer fake.maskMutex.Unlock()
|
||||
fake.MaskStub = nil
|
||||
if fake.maskReturnsOnCall == nil {
|
||||
fake.maskReturnsOnCall = make(map[int]struct {
|
||||
result1 events.EventType
|
||||
})
|
||||
}
|
||||
fake.maskReturnsOnCall[i] = struct {
|
||||
result1 events.EventType
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) Since(arg1 int, arg2 []events.Event, arg3 time.Duration) []events.Event {
|
||||
var arg2Copy []events.Event
|
||||
if arg2 != nil {
|
||||
arg2Copy = make([]events.Event, len(arg2))
|
||||
copy(arg2Copy, arg2)
|
||||
}
|
||||
fake.sinceMutex.Lock()
|
||||
ret, specificReturn := fake.sinceReturnsOnCall[len(fake.sinceArgsForCall)]
|
||||
fake.sinceArgsForCall = append(fake.sinceArgsForCall, struct {
|
||||
arg1 int
|
||||
arg2 []events.Event
|
||||
arg3 time.Duration
|
||||
}{arg1, arg2Copy, arg3})
|
||||
stub := fake.SinceStub
|
||||
fakeReturns := fake.sinceReturns
|
||||
fake.recordInvocation("Since", []interface{}{arg1, arg2Copy, arg3})
|
||||
fake.sinceMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2, arg3)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) SinceCallCount() int {
|
||||
fake.sinceMutex.RLock()
|
||||
defer fake.sinceMutex.RUnlock()
|
||||
return len(fake.sinceArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) SinceCalls(stub func(int, []events.Event, time.Duration) []events.Event) {
|
||||
fake.sinceMutex.Lock()
|
||||
defer fake.sinceMutex.Unlock()
|
||||
fake.SinceStub = stub
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) SinceArgsForCall(i int) (int, []events.Event, time.Duration) {
|
||||
fake.sinceMutex.RLock()
|
||||
defer fake.sinceMutex.RUnlock()
|
||||
argsForCall := fake.sinceArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) SinceReturns(result1 []events.Event) {
|
||||
fake.sinceMutex.Lock()
|
||||
defer fake.sinceMutex.Unlock()
|
||||
fake.SinceStub = nil
|
||||
fake.sinceReturns = struct {
|
||||
result1 []events.Event
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) SinceReturnsOnCall(i int, result1 []events.Event) {
|
||||
fake.sinceMutex.Lock()
|
||||
defer fake.sinceMutex.Unlock()
|
||||
fake.SinceStub = nil
|
||||
if fake.sinceReturnsOnCall == nil {
|
||||
fake.sinceReturnsOnCall = make(map[int]struct {
|
||||
result1 []events.Event
|
||||
})
|
||||
}
|
||||
fake.sinceReturnsOnCall[i] = struct {
|
||||
result1 []events.Event
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.maskMutex.RLock()
|
||||
defer fake.maskMutex.RUnlock()
|
||||
fake.sinceMutex.RLock()
|
||||
defer fake.sinceMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *BufferedSubscription) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
||||
|
||||
var _ events.BufferedSubscription = new(BufferedSubscription)
|
@ -1,6 +1,8 @@
|
||||
// Copyright (C) 2014 Jakob Borg. All rights reserved. Use of this source code
|
||||
// is governed by an MIT-style license that can be found in the LICENSE file.
|
||||
|
||||
//go:generate counterfeiter -o mocks/logger.go --fake-name Recorder . Recorder
|
||||
|
||||
// Package logger implements a standardized logger with callback functionality
|
||||
package logger
|
||||
|
||||
|
142
lib/logger/mocks/logger.go
Normal file
142
lib/logger/mocks/logger.go
Normal file
@ -0,0 +1,142 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/logger"
|
||||
)
|
||||
|
||||
type Recorder struct {
|
||||
ClearStub func()
|
||||
clearMutex sync.RWMutex
|
||||
clearArgsForCall []struct {
|
||||
}
|
||||
SinceStub func(time.Time) []logger.Line
|
||||
sinceMutex sync.RWMutex
|
||||
sinceArgsForCall []struct {
|
||||
arg1 time.Time
|
||||
}
|
||||
sinceReturns struct {
|
||||
result1 []logger.Line
|
||||
}
|
||||
sinceReturnsOnCall map[int]struct {
|
||||
result1 []logger.Line
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *Recorder) Clear() {
|
||||
fake.clearMutex.Lock()
|
||||
fake.clearArgsForCall = append(fake.clearArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.ClearStub
|
||||
fake.recordInvocation("Clear", []interface{}{})
|
||||
fake.clearMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.ClearStub()
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *Recorder) ClearCallCount() int {
|
||||
fake.clearMutex.RLock()
|
||||
defer fake.clearMutex.RUnlock()
|
||||
return len(fake.clearArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Recorder) ClearCalls(stub func()) {
|
||||
fake.clearMutex.Lock()
|
||||
defer fake.clearMutex.Unlock()
|
||||
fake.ClearStub = stub
|
||||
}
|
||||
|
||||
func (fake *Recorder) Since(arg1 time.Time) []logger.Line {
|
||||
fake.sinceMutex.Lock()
|
||||
ret, specificReturn := fake.sinceReturnsOnCall[len(fake.sinceArgsForCall)]
|
||||
fake.sinceArgsForCall = append(fake.sinceArgsForCall, struct {
|
||||
arg1 time.Time
|
||||
}{arg1})
|
||||
stub := fake.SinceStub
|
||||
fakeReturns := fake.sinceReturns
|
||||
fake.recordInvocation("Since", []interface{}{arg1})
|
||||
fake.sinceMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *Recorder) SinceCallCount() int {
|
||||
fake.sinceMutex.RLock()
|
||||
defer fake.sinceMutex.RUnlock()
|
||||
return len(fake.sinceArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Recorder) SinceCalls(stub func(time.Time) []logger.Line) {
|
||||
fake.sinceMutex.Lock()
|
||||
defer fake.sinceMutex.Unlock()
|
||||
fake.SinceStub = stub
|
||||
}
|
||||
|
||||
func (fake *Recorder) SinceArgsForCall(i int) time.Time {
|
||||
fake.sinceMutex.RLock()
|
||||
defer fake.sinceMutex.RUnlock()
|
||||
argsForCall := fake.sinceArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *Recorder) SinceReturns(result1 []logger.Line) {
|
||||
fake.sinceMutex.Lock()
|
||||
defer fake.sinceMutex.Unlock()
|
||||
fake.SinceStub = nil
|
||||
fake.sinceReturns = struct {
|
||||
result1 []logger.Line
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Recorder) SinceReturnsOnCall(i int, result1 []logger.Line) {
|
||||
fake.sinceMutex.Lock()
|
||||
defer fake.sinceMutex.Unlock()
|
||||
fake.SinceStub = nil
|
||||
if fake.sinceReturnsOnCall == nil {
|
||||
fake.sinceReturnsOnCall = make(map[int]struct {
|
||||
result1 []logger.Line
|
||||
})
|
||||
}
|
||||
fake.sinceReturnsOnCall[i] = struct {
|
||||
result1 []logger.Line
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Recorder) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.clearMutex.RLock()
|
||||
defer fake.clearMutex.RUnlock()
|
||||
fake.sinceMutex.RLock()
|
||||
defer fake.sinceMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *Recorder) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
||||
|
||||
var _ logger.Recorder = new(Recorder)
|
@ -13,8 +13,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
protocolmocks "github.com/syncthing/syncthing/lib/protocol/mocks"
|
||||
"github.com/syncthing/syncthing/lib/scanner"
|
||||
"github.com/syncthing/syncthing/lib/testutils"
|
||||
)
|
||||
|
||||
type downloadProgressMessage struct {
|
||||
@ -22,97 +22,37 @@ type downloadProgressMessage struct {
|
||||
updates []protocol.FileDownloadProgressUpdate
|
||||
}
|
||||
|
||||
func newFakeConnection(id protocol.DeviceID, model Model) *fakeConnection {
|
||||
f := &fakeConnection{
|
||||
Connection: new(protocolmocks.Connection),
|
||||
id: id,
|
||||
model: model,
|
||||
}
|
||||
f.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
return f.fileData[name], nil
|
||||
})
|
||||
f.IDReturns(id)
|
||||
f.CloseCalls(func(err error) {
|
||||
model.Closed(f, err)
|
||||
f.ClosedReturns(true)
|
||||
})
|
||||
return f
|
||||
}
|
||||
|
||||
type fakeConnection struct {
|
||||
testutils.FakeConnectionInfo
|
||||
*protocolmocks.Connection
|
||||
id protocol.DeviceID
|
||||
downloadProgressMessages []downloadProgressMessage
|
||||
closed bool
|
||||
files []protocol.FileInfo
|
||||
fileData map[string][]byte
|
||||
folder string
|
||||
model *testModel
|
||||
indexFn func(context.Context, string, []protocol.FileInfo)
|
||||
requestFn func(ctx context.Context, folder, name string, offset int64, size int, hash []byte, fromTemporary bool) ([]byte, error)
|
||||
closeFn func(error)
|
||||
clusterConfigFn func(protocol.ClusterConfig)
|
||||
model Model
|
||||
mut sync.Mutex
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Close(err error) {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
if f.closeFn != nil {
|
||||
f.closeFn(err)
|
||||
return
|
||||
}
|
||||
f.closed = true
|
||||
f.model.Closed(f, err)
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Start() {
|
||||
}
|
||||
|
||||
func (f *fakeConnection) ID() protocol.DeviceID {
|
||||
return f.id
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Name() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Option(string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Index(ctx context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
if f.indexFn != nil {
|
||||
f.indexFn(ctx, folder, fs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeConnection) IndexUpdate(ctx context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
if f.indexFn != nil {
|
||||
f.indexFn(ctx, folder, fs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Request(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
if f.requestFn != nil {
|
||||
return f.requestFn(ctx, folder, name, offset, size, hash, fromTemporary)
|
||||
}
|
||||
return f.fileData[name], nil
|
||||
}
|
||||
|
||||
func (f *fakeConnection) ClusterConfig(cc protocol.ClusterConfig) {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
if f.clusterConfigFn != nil {
|
||||
f.clusterConfigFn(cc)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Ping() bool {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
return f.closed
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Closed() bool {
|
||||
f.mut.Lock()
|
||||
defer f.mut.Unlock()
|
||||
return f.closed
|
||||
}
|
||||
|
||||
func (f *fakeConnection) Statistics() protocol.Statistics {
|
||||
return protocol.Statistics{}
|
||||
func (f *fakeConnection) setIndexFn(fn func(_ context.Context, folder string, fs []protocol.FileInfo) error) {
|
||||
f.IndexCalls(fn)
|
||||
f.IndexUpdateCalls(fn)
|
||||
}
|
||||
|
||||
func (f *fakeConnection) DownloadProgress(_ context.Context, folder string, updates []protocol.FileDownloadProgressUpdate) {
|
||||
@ -201,7 +141,7 @@ func (f *fakeConnection) sendIndexUpdate() {
|
||||
}
|
||||
|
||||
func addFakeConn(m *testModel, dev protocol.DeviceID) *fakeConnection {
|
||||
fc := &fakeConnection{id: dev, model: m}
|
||||
fc := newFakeConnection(dev, m)
|
||||
m.AddConnection(fc, protocol.Hello{})
|
||||
|
||||
m.ClusterConfig(dev, protocol.ClusterConfig{
|
||||
|
@ -4,6 +4,8 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate counterfeiter -o mocks/folderSummaryService.go --fake-name FolderSummaryService . FolderSummaryService
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
|
221
lib/model/mocks/folderSummaryService.go
Normal file
221
lib/model/mocks/folderSummaryService.go
Normal file
@ -0,0 +1,221 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/model"
|
||||
)
|
||||
|
||||
type FolderSummaryService struct {
|
||||
OnEventRequestStub func()
|
||||
onEventRequestMutex sync.RWMutex
|
||||
onEventRequestArgsForCall []struct {
|
||||
}
|
||||
ServeStub func(context.Context) error
|
||||
serveMutex sync.RWMutex
|
||||
serveArgsForCall []struct {
|
||||
arg1 context.Context
|
||||
}
|
||||
serveReturns struct {
|
||||
result1 error
|
||||
}
|
||||
serveReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
SummaryStub func(string) (map[string]interface{}, error)
|
||||
summaryMutex sync.RWMutex
|
||||
summaryArgsForCall []struct {
|
||||
arg1 string
|
||||
}
|
||||
summaryReturns struct {
|
||||
result1 map[string]interface{}
|
||||
result2 error
|
||||
}
|
||||
summaryReturnsOnCall map[int]struct {
|
||||
result1 map[string]interface{}
|
||||
result2 error
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) OnEventRequest() {
|
||||
fake.onEventRequestMutex.Lock()
|
||||
fake.onEventRequestArgsForCall = append(fake.onEventRequestArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.OnEventRequestStub
|
||||
fake.recordInvocation("OnEventRequest", []interface{}{})
|
||||
fake.onEventRequestMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.OnEventRequestStub()
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) OnEventRequestCallCount() int {
|
||||
fake.onEventRequestMutex.RLock()
|
||||
defer fake.onEventRequestMutex.RUnlock()
|
||||
return len(fake.onEventRequestArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) OnEventRequestCalls(stub func()) {
|
||||
fake.onEventRequestMutex.Lock()
|
||||
defer fake.onEventRequestMutex.Unlock()
|
||||
fake.OnEventRequestStub = stub
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) Serve(arg1 context.Context) error {
|
||||
fake.serveMutex.Lock()
|
||||
ret, specificReturn := fake.serveReturnsOnCall[len(fake.serveArgsForCall)]
|
||||
fake.serveArgsForCall = append(fake.serveArgsForCall, struct {
|
||||
arg1 context.Context
|
||||
}{arg1})
|
||||
stub := fake.ServeStub
|
||||
fakeReturns := fake.serveReturns
|
||||
fake.recordInvocation("Serve", []interface{}{arg1})
|
||||
fake.serveMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) ServeCallCount() int {
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
return len(fake.serveArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) ServeCalls(stub func(context.Context) error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = stub
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) ServeArgsForCall(i int) context.Context {
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
argsForCall := fake.serveArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) ServeReturns(result1 error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = nil
|
||||
fake.serveReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) ServeReturnsOnCall(i int, result1 error) {
|
||||
fake.serveMutex.Lock()
|
||||
defer fake.serveMutex.Unlock()
|
||||
fake.ServeStub = nil
|
||||
if fake.serveReturnsOnCall == nil {
|
||||
fake.serveReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.serveReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) Summary(arg1 string) (map[string]interface{}, error) {
|
||||
fake.summaryMutex.Lock()
|
||||
ret, specificReturn := fake.summaryReturnsOnCall[len(fake.summaryArgsForCall)]
|
||||
fake.summaryArgsForCall = append(fake.summaryArgsForCall, struct {
|
||||
arg1 string
|
||||
}{arg1})
|
||||
stub := fake.SummaryStub
|
||||
fakeReturns := fake.summaryReturns
|
||||
fake.recordInvocation("Summary", []interface{}{arg1})
|
||||
fake.summaryMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1, ret.result2
|
||||
}
|
||||
return fakeReturns.result1, fakeReturns.result2
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) SummaryCallCount() int {
|
||||
fake.summaryMutex.RLock()
|
||||
defer fake.summaryMutex.RUnlock()
|
||||
return len(fake.summaryArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) SummaryCalls(stub func(string) (map[string]interface{}, error)) {
|
||||
fake.summaryMutex.Lock()
|
||||
defer fake.summaryMutex.Unlock()
|
||||
fake.SummaryStub = stub
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) SummaryArgsForCall(i int) string {
|
||||
fake.summaryMutex.RLock()
|
||||
defer fake.summaryMutex.RUnlock()
|
||||
argsForCall := fake.summaryArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) SummaryReturns(result1 map[string]interface{}, result2 error) {
|
||||
fake.summaryMutex.Lock()
|
||||
defer fake.summaryMutex.Unlock()
|
||||
fake.SummaryStub = nil
|
||||
fake.summaryReturns = struct {
|
||||
result1 map[string]interface{}
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) SummaryReturnsOnCall(i int, result1 map[string]interface{}, result2 error) {
|
||||
fake.summaryMutex.Lock()
|
||||
defer fake.summaryMutex.Unlock()
|
||||
fake.SummaryStub = nil
|
||||
if fake.summaryReturnsOnCall == nil {
|
||||
fake.summaryReturnsOnCall = make(map[int]struct {
|
||||
result1 map[string]interface{}
|
||||
result2 error
|
||||
})
|
||||
}
|
||||
fake.summaryReturnsOnCall[i] = struct {
|
||||
result1 map[string]interface{}
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.onEventRequestMutex.RLock()
|
||||
defer fake.onEventRequestMutex.RUnlock()
|
||||
fake.serveMutex.RLock()
|
||||
defer fake.serveMutex.RUnlock()
|
||||
fake.summaryMutex.RLock()
|
||||
defer fake.summaryMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *FolderSummaryService) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
||||
|
||||
var _ model.FolderSummaryService = new(FolderSummaryService)
|
3238
lib/model/mocks/model.go
Normal file
3238
lib/model/mocks/model.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,8 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:generate counterfeiter -o mocks/model.go --fake-name Model . Model
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/ignore"
|
||||
"github.com/syncthing/syncthing/lib/osutil"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
protocolmocks "github.com/syncthing/syncthing/lib/protocol/mocks"
|
||||
srand "github.com/syncthing/syncthing/lib/rand"
|
||||
"github.com/syncthing/syncthing/lib/testutils"
|
||||
"github.com/syncthing/syncthing/lib/versioner"
|
||||
@ -116,7 +117,7 @@ func newState(t testing.TB, cfg config.Configuration) (*testModel, context.Cance
|
||||
m := setupModel(t, wcfg)
|
||||
|
||||
for _, dev := range cfg.Devices {
|
||||
m.AddConnection(&fakeConnection{id: dev.DeviceID, model: m}, protocol.Hello{})
|
||||
m.AddConnection(newFakeConnection(dev.DeviceID, m), protocol.Hello{})
|
||||
}
|
||||
|
||||
return m, cancel
|
||||
@ -267,7 +268,7 @@ func BenchmarkRequestOut(b *testing.B) {
|
||||
const n = 1000
|
||||
files := genFiles(n)
|
||||
|
||||
fc := &fakeConnection{id: device1, model: m}
|
||||
fc := newFakeConnection(device1, m)
|
||||
for _, f := range files {
|
||||
fc.addFile(f.Name, 0644, protocol.FileInfoTypeFile, []byte("some data to return"))
|
||||
}
|
||||
@ -329,7 +330,7 @@ func TestDeviceRename(t *testing.T) {
|
||||
t.Errorf("Device already has a name")
|
||||
}
|
||||
|
||||
conn := &fakeConnection{id: device1, model: m}
|
||||
conn := newFakeConnection(device1, m)
|
||||
|
||||
m.AddConnection(conn, hello)
|
||||
|
||||
@ -871,9 +872,7 @@ func TestIssue5063(t *testing.T) {
|
||||
m.pmut.Lock()
|
||||
for _, c := range m.conn {
|
||||
conn := c.(*fakeConnection)
|
||||
conn.mut.Lock()
|
||||
conn.closeFn = func(_ error) {}
|
||||
conn.mut.Unlock()
|
||||
conn.CloseCalls(func(_ error) {})
|
||||
defer m.Closed(c, errStopped) // to unblock deferred m.Stop()
|
||||
}
|
||||
m.pmut.Unlock()
|
||||
@ -1324,7 +1323,7 @@ func TestAutoAcceptEnc(t *testing.T) {
|
||||
// Earlier tests might cause the connection to get closed, thus ClusterConfig
|
||||
// would panic.
|
||||
clusterConfig := func(deviceID protocol.DeviceID, cm protocol.ClusterConfig) {
|
||||
m.AddConnection(&fakeConnection{id: deviceID, model: m}, protocol.Hello{})
|
||||
m.AddConnection(newFakeConnection(deviceID, m), protocol.Hello{})
|
||||
m.ClusterConfig(deviceID, cm)
|
||||
}
|
||||
|
||||
@ -2196,9 +2195,9 @@ func TestSharedWithClearedOnDisconnect(t *testing.T) {
|
||||
m := setupModel(t, wcfg)
|
||||
defer cleanupModel(m)
|
||||
|
||||
conn1 := &fakeConnection{id: device1, model: m}
|
||||
conn1 := newFakeConnection(device1, m)
|
||||
m.AddConnection(conn1, protocol.Hello{})
|
||||
conn2 := &fakeConnection{id: device2, model: m}
|
||||
conn2 := newFakeConnection(device2, m)
|
||||
m.AddConnection(conn2, protocol.Hello{})
|
||||
|
||||
m.ClusterConfig(device1, protocol.ClusterConfig{
|
||||
@ -2429,8 +2428,8 @@ func TestNoRequestsFromPausedDevices(t *testing.T) {
|
||||
t.Errorf("should have two available")
|
||||
}
|
||||
|
||||
m.Closed(&fakeConnection{id: device1, model: m}, errDeviceUnknown)
|
||||
m.Closed(&fakeConnection{id: device2, model: m}, errDeviceUnknown)
|
||||
m.Closed(newFakeConnection(device1, m), errDeviceUnknown)
|
||||
m.Closed(newFakeConnection(device2, m), errDeviceUnknown)
|
||||
|
||||
avail = m.Availability("default", file, file.Blocks[0])
|
||||
if len(avail) != 0 {
|
||||
@ -3172,7 +3171,7 @@ func TestConnCloseOnRestart(t *testing.T) {
|
||||
|
||||
br := &testutils.BlockingRW{}
|
||||
nw := &testutils.NoopRW{}
|
||||
m.AddConnection(protocol.NewConnection(device1, br, nw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"fc"}, protocol.CompressionNever), protocol.Hello{})
|
||||
m.AddConnection(protocol.NewConnection(device1, br, nw, testutils.NoopCloser{}, m, new(protocolmocks.ConnectionInfo), protocol.CompressionNever), protocol.Hello{})
|
||||
m.pmut.RLock()
|
||||
if len(m.closed) != 1 {
|
||||
t.Fatalf("Expected just one conn (len(m.conn) == %v)", len(m.conn))
|
||||
@ -3819,20 +3818,14 @@ func testConfigChangeTriggersClusterConfigs(t *testing.T, expectFirst, expectSec
|
||||
|
||||
cc1 := make(chan struct{}, 1)
|
||||
cc2 := make(chan struct{}, 1)
|
||||
fc1 := &fakeConnection{
|
||||
id: device1,
|
||||
model: m,
|
||||
clusterConfigFn: func(_ protocol.ClusterConfig) {
|
||||
cc1 <- struct{}{}
|
||||
},
|
||||
}
|
||||
fc2 := &fakeConnection{
|
||||
id: device2,
|
||||
model: m,
|
||||
clusterConfigFn: func(_ protocol.ClusterConfig) {
|
||||
cc2 <- struct{}{}
|
||||
},
|
||||
}
|
||||
fc1 := newFakeConnection(device1, m)
|
||||
fc1.ClusterConfigCalls(func(_ protocol.ClusterConfig) {
|
||||
cc1 <- struct{}{}
|
||||
})
|
||||
fc2 := newFakeConnection(device2, m)
|
||||
fc2.ClusterConfigCalls(func(_ protocol.ClusterConfig) {
|
||||
cc2 <- struct{}{}
|
||||
})
|
||||
m.AddConnection(fc1, protocol.Hello{})
|
||||
m.AddConnection(fc2, protocol.Hello{})
|
||||
|
||||
|
@ -126,7 +126,7 @@ func TestSendDownloadProgressMessages(t *testing.T) {
|
||||
}
|
||||
waiter.Wait()
|
||||
|
||||
fc := &fakeConnection{}
|
||||
fc := newFakeConnection(protocol.DeviceID{}, nil)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
evLogger := events.NewLogger()
|
||||
|
@ -38,8 +38,7 @@ func TestRequestSimple(t *testing.T) {
|
||||
// We listen for incoming index updates and trigger when we see one for
|
||||
// the expected test file.
|
||||
done := make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-done:
|
||||
t.Error("More than one index update sent")
|
||||
@ -48,11 +47,11 @@ func TestRequestSimple(t *testing.T) {
|
||||
for _, f := range fs {
|
||||
if f.Name == "testfile" {
|
||||
close(done)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// Send an update for the test file, wait for it to sync and be reported back.
|
||||
contents := []byte("test file contents\n")
|
||||
@ -81,8 +80,7 @@ func TestSymlinkTraversalRead(t *testing.T) {
|
||||
// We listen for incoming index updates and trigger when we see one for
|
||||
// the expected test file.
|
||||
done := make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-done:
|
||||
t.Error("More than one index update sent")
|
||||
@ -91,11 +89,11 @@ func TestSymlinkTraversalRead(t *testing.T) {
|
||||
for _, f := range fs {
|
||||
if f.Name == "symlink" {
|
||||
close(done)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// Send an update for the symlink, wait for it to sync and be reported back.
|
||||
contents := []byte("..")
|
||||
@ -127,26 +125,25 @@ func TestSymlinkTraversalWrite(t *testing.T) {
|
||||
done := make(chan struct{}, 1)
|
||||
badReq := make(chan string, 1)
|
||||
badIdx := make(chan string, 1)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
for _, f := range fs {
|
||||
if f.Name == "symlink" {
|
||||
done <- struct{}{}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(f.Name, "symlink") {
|
||||
badIdx <- f.Name
|
||||
return
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
fc.requestFn = func(_ context.Context, folder, name string, offset int64, size int, hash []byte, fromTemporary bool) ([]byte, error) {
|
||||
return nil
|
||||
})
|
||||
fc.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
if name != "symlink" && strings.HasPrefix(name, "symlink") {
|
||||
badReq <- name
|
||||
}
|
||||
return fc.fileData[name], nil
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
})
|
||||
|
||||
// Send an update for the symlink, wait for it to sync and be reported back.
|
||||
contents := []byte("..")
|
||||
@ -186,8 +183,7 @@ func TestRequestCreateTmpSymlink(t *testing.T) {
|
||||
// the expected test file.
|
||||
goodIdx := make(chan struct{})
|
||||
name := fs.TempName("testlink")
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
for _, f := range fs {
|
||||
if f.Name == name {
|
||||
if f.IsInvalid() {
|
||||
@ -196,11 +192,11 @@ func TestRequestCreateTmpSymlink(t *testing.T) {
|
||||
t.Error("Received index with non-invalid temporary file")
|
||||
close(goodIdx)
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// Send an update for the test file, wait for it to sync and be reported back.
|
||||
fc.addFile(name, 0644, protocol.FileInfoTypeSymlink, []byte(".."))
|
||||
@ -244,11 +240,10 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {
|
||||
// We listen for incoming index updates and trigger when we see one for
|
||||
// the expected test file.
|
||||
idx := make(chan int)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
idx <- len(fs)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
waitForIdx := func() {
|
||||
select {
|
||||
@ -335,8 +330,7 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
expected := map[string]struct{}{invIgn: {}, ign: {}, ignExisting: {}}
|
||||
for _, f := range fs {
|
||||
if _, ok := expected[f.Name]; !ok {
|
||||
@ -351,8 +345,8 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
t.Errorf("File %v wasn't added to index", name)
|
||||
}
|
||||
close(done)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
sub := m.evLogger.Subscribe(events.FolderErrors)
|
||||
defer sub.Unsubscribe()
|
||||
@ -372,8 +366,7 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
var expectedMut sync.Mutex
|
||||
// The indexes will normally arrive in one update, but it is possible
|
||||
// that they arrive in separate ones.
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
expectedMut.Lock()
|
||||
for _, f := range fs {
|
||||
_, ok := expected[f.Name]
|
||||
@ -411,13 +404,13 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
||||
close(done)
|
||||
}
|
||||
expectedMut.Unlock()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// Make sure pulling doesn't interfere, as index updates are racy and
|
||||
// thus we cannot distinguish between scan and pull results.
|
||||
fc.requestFn = func(_ context.Context, folder, name string, offset int64, size int, hash []byte, fromTemporary bool) ([]byte, error) {
|
||||
fc.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
})
|
||||
|
||||
if err := m.SetIgnores("default", []string{"*:ignored*"}); err != nil {
|
||||
panic(err)
|
||||
@ -438,11 +431,10 @@ func TestIssue4841(t *testing.T) {
|
||||
defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
||||
|
||||
received := make(chan []protocol.FileInfo)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, _ string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, _ string, fs []protocol.FileInfo) error {
|
||||
received <- fs
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
checkReceived := func(fs []protocol.FileInfo) protocol.FileInfo {
|
||||
t.Helper()
|
||||
if len(fs) != 1 {
|
||||
@ -492,11 +484,10 @@ func TestRescanIfHaveInvalidContent(t *testing.T) {
|
||||
must(t, writeFile(tfs, "foo", payload, 0777))
|
||||
|
||||
received := make(chan []protocol.FileInfo)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, _ string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, _ string, fs []protocol.FileInfo) error {
|
||||
received <- fs
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
checkReceived := func(fs []protocol.FileInfo) protocol.FileInfo {
|
||||
t.Helper()
|
||||
if len(fs) != 1 {
|
||||
@ -560,11 +551,10 @@ func TestParentDeletion(t *testing.T) {
|
||||
received := make(chan []protocol.FileInfo)
|
||||
fc.addFile(parent, 0777, protocol.FileInfoTypeDirectory, nil)
|
||||
fc.addFile(child, 0777, protocol.FileInfoTypeDirectory, nil)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
received <- fs
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
fc.sendIndexUpdate()
|
||||
|
||||
// Get back index from initial setup
|
||||
@ -634,16 +624,15 @@ func TestRequestSymlinkWindows(t *testing.T) {
|
||||
defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
||||
|
||||
received := make(chan []protocol.FileInfo)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-received:
|
||||
t.Error("More than one index update sent")
|
||||
default:
|
||||
}
|
||||
received <- fs
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
fc.addFile("link", 0644, protocol.FileInfoTypeSymlink, nil)
|
||||
fc.sendIndexUpdate()
|
||||
@ -705,16 +694,15 @@ func TestRequestRemoteRenameChanged(t *testing.T) {
|
||||
defer cleanupModelAndRemoveDir(m, tfs.URI())
|
||||
|
||||
received := make(chan []protocol.FileInfo)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-received:
|
||||
t.Error("More than one index update sent")
|
||||
default:
|
||||
}
|
||||
received <- fs
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// setup
|
||||
a := "a"
|
||||
@ -743,12 +731,11 @@ func TestRequestRemoteRenameChanged(t *testing.T) {
|
||||
|
||||
var gotA, gotB, gotConfl bool
|
||||
done := make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-done:
|
||||
t.Error("Received more index updates than expected")
|
||||
return
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
for _, f := range fs {
|
||||
@ -780,8 +767,8 @@ func TestRequestRemoteRenameChanged(t *testing.T) {
|
||||
if gotA && gotB && gotConfl {
|
||||
close(done)
|
||||
}
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
fd, err := tfs.OpenFile(b, fs.OptReadWrite, 0644)
|
||||
if err != nil {
|
||||
@ -841,11 +828,10 @@ func TestRequestRemoteRenameConflict(t *testing.T) {
|
||||
defer cleanupModelAndRemoveDir(m, tmpDir)
|
||||
|
||||
recv := make(chan int)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
recv <- len(fs)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// setup
|
||||
a := "a"
|
||||
@ -932,16 +918,15 @@ func TestRequestDeleteChanged(t *testing.T) {
|
||||
defer cleanupModelAndRemoveDir(m, tfs.URI())
|
||||
|
||||
done := make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-done:
|
||||
t.Error("More than one index update sent")
|
||||
default:
|
||||
}
|
||||
close(done)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
// setup
|
||||
a := "a"
|
||||
@ -955,16 +940,15 @@ func TestRequestDeleteChanged(t *testing.T) {
|
||||
t.Fatal("timed out")
|
||||
}
|
||||
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case <-done:
|
||||
t.Error("More than one index update sent")
|
||||
default:
|
||||
}
|
||||
close(done)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
fd, err := tfs.OpenFile(a, fs.OptReadWrite, 0644)
|
||||
if err != nil {
|
||||
@ -1006,11 +990,9 @@ func TestNeedFolderFiles(t *testing.T) {
|
||||
defer sub.Unsubscribe()
|
||||
|
||||
errPreventSync := errors.New("you aren't getting any of this")
|
||||
fc.mut.Lock()
|
||||
fc.requestFn = func(context.Context, string, string, int64, int, []byte, bool) ([]byte, error) {
|
||||
fc.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
return nil, errPreventSync
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
})
|
||||
|
||||
data := []byte("foo")
|
||||
num := 20
|
||||
@ -1073,12 +1055,11 @@ func TestIgnoreDeleteUnignore(t *testing.T) {
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
basicCheck(fs)
|
||||
close(done)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
if err := writeFile(fss, file, contents, 0644); err != nil {
|
||||
panic(err)
|
||||
@ -1092,16 +1073,15 @@ func TestIgnoreDeleteUnignore(t *testing.T) {
|
||||
}
|
||||
|
||||
done = make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
basicCheck(fs)
|
||||
f := fs[0]
|
||||
if !f.IsInvalid() {
|
||||
t.Errorf("Received non-invalid index update")
|
||||
}
|
||||
close(done)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
if err := m.SetIgnores("default", []string{"foobar"}); err != nil {
|
||||
panic(err)
|
||||
@ -1114,8 +1094,7 @@ func TestIgnoreDeleteUnignore(t *testing.T) {
|
||||
}
|
||||
|
||||
done = make(chan struct{})
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
basicCheck(fs)
|
||||
f := fs[0]
|
||||
if f.IsInvalid() {
|
||||
@ -1126,8 +1105,8 @@ func TestIgnoreDeleteUnignore(t *testing.T) {
|
||||
}
|
||||
l.Infoln(f)
|
||||
close(done)
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
if err := fss.Remove(file); err != nil {
|
||||
t.Fatal(err)
|
||||
@ -1153,8 +1132,7 @@ func TestRequestLastFileProgress(t *testing.T) {
|
||||
|
||||
done := make(chan struct{})
|
||||
|
||||
fc.mut.Lock()
|
||||
fc.requestFn = func(_ context.Context, folder, name string, _ int64, _ int, _ []byte, _ bool) ([]byte, error) {
|
||||
fc.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
|
||||
defer close(done)
|
||||
progress, queued, rest, err := m.NeedFolderFiles(folder, 1, 10)
|
||||
must(t, err)
|
||||
@ -1165,8 +1143,7 @@ func TestRequestLastFileProgress(t *testing.T) {
|
||||
t.Error("Expected exactly one item in progress.")
|
||||
}
|
||||
return fc.fileData[name], nil
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
})
|
||||
|
||||
contents := []byte("test file contents\n")
|
||||
fc.addFile("testfile", 0644, protocol.FileInfoTypeFile, contents)
|
||||
@ -1189,15 +1166,14 @@ func TestRequestIndexSenderPause(t *testing.T) {
|
||||
defer cleanupModelAndRemoveDir(m, tfs.URI())
|
||||
|
||||
indexChan := make(chan []protocol.FileInfo)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(ctx context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(ctx context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case indexChan <- fs:
|
||||
case <-done:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
var seq int64 = 1
|
||||
files := []protocol.FileInfo{{Name: "foo", Size: 10, Version: protocol.Vector{}.Update(myID.Short()), Sequence: seq}}
|
||||
@ -1324,20 +1300,19 @@ func TestRequestIndexSenderClusterConfigBeforeStart(t *testing.T) {
|
||||
defer close(done) // Must be the last thing to be deferred, thus first to run.
|
||||
indexChan := make(chan []protocol.FileInfo, 1)
|
||||
ccChan := make(chan protocol.ClusterConfig, 1)
|
||||
fc.mut.Lock()
|
||||
fc.indexFn = func(_ context.Context, folder string, fs []protocol.FileInfo) {
|
||||
fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case indexChan <- fs:
|
||||
case <-done:
|
||||
}
|
||||
}
|
||||
fc.clusterConfigFn = func(cc protocol.ClusterConfig) {
|
||||
return nil
|
||||
})
|
||||
fc.ClusterConfigCalls(func(cc protocol.ClusterConfig) {
|
||||
select {
|
||||
case ccChan <- cc:
|
||||
case <-done:
|
||||
}
|
||||
}
|
||||
fc.mut.Unlock()
|
||||
})
|
||||
|
||||
m.ServeBackground()
|
||||
|
||||
@ -1388,16 +1363,14 @@ func TestRequestReceiveEncryptedLocalNoSend(t *testing.T) {
|
||||
indexChan := make(chan []protocol.FileInfo, 1)
|
||||
done := make(chan struct{})
|
||||
defer close(done)
|
||||
fc := &fakeConnection{
|
||||
id: device1,
|
||||
model: m,
|
||||
indexFn: func(_ context.Context, _ string, fs []protocol.FileInfo) {
|
||||
select {
|
||||
case indexChan <- fs:
|
||||
case <-done:
|
||||
}
|
||||
},
|
||||
}
|
||||
fc := newFakeConnection(device1, m)
|
||||
fc.setIndexFn(func(_ context.Context, _ string, fs []protocol.FileInfo) error {
|
||||
select {
|
||||
case indexChan <- fs:
|
||||
case <-done:
|
||||
}
|
||||
return nil
|
||||
})
|
||||
m.AddConnection(fc, protocol.Hello{})
|
||||
m.ClusterConfig(device1, protocol.ClusterConfig{
|
||||
Folders: []protocol.Folder{
|
||||
|
@ -60,9 +60,9 @@ func benchmarkRequestsTLS(b *testing.B, conn0, conn1 net.Conn) {
|
||||
|
||||
func benchmarkRequestsConnPair(b *testing.B, conn0, conn1 net.Conn) {
|
||||
// Start up Connections on them
|
||||
c0 := NewConnection(LocalDeviceID, conn0, conn0, testutils.NoopCloser{}, new(fakeModel), &testutils.FakeConnectionInfo{"c0"}, CompressionMetadata)
|
||||
c0 := NewConnection(LocalDeviceID, conn0, conn0, testutils.NoopCloser{}, new(fakeModel), new(mockedConnectionInfo), CompressionMetadata)
|
||||
c0.Start()
|
||||
c1 := NewConnection(LocalDeviceID, conn1, conn1, testutils.NoopCloser{}, new(fakeModel), &testutils.FakeConnectionInfo{"c1"}, CompressionMetadata)
|
||||
c1 := NewConnection(LocalDeviceID, conn1, conn1, testutils.NoopCloser{}, new(fakeModel), new(mockedConnectionInfo), CompressionMetadata)
|
||||
c1.Start()
|
||||
|
||||
// Satisfy the assertions in the protocol by sending an initial cluster config
|
||||
|
@ -1,8 +1,5 @@
|
||||
// Copyright (C) 2014 The Protocol Authors.
|
||||
|
||||
//go:generate go run ../../proto/scripts/protofmt.go deviceid_test.proto
|
||||
//go:generate protoc -I ../../ -I . --gogofast_out=. deviceid_test.proto
|
||||
|
||||
package protocol
|
||||
|
||||
import "testing"
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: deviceid_test.proto
|
||||
// source: lib/protocol/deviceid_test.proto
|
||||
|
||||
package protocol
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
fmt "fmt"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
_ "github.com/syncthing/syncthing/proto/ext"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
@ -24,14 +25,14 @@ var _ = math.Inf
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
type TestOldDeviceID struct {
|
||||
Test []byte `protobuf:"bytes,1,opt,name=test,proto3" json:"test,omitempty"`
|
||||
Test []byte `protobuf:"bytes,1,opt,name=test,proto3" json:"test" xml:"test"`
|
||||
}
|
||||
|
||||
func (m *TestOldDeviceID) Reset() { *m = TestOldDeviceID{} }
|
||||
func (m *TestOldDeviceID) String() string { return proto.CompactTextString(m) }
|
||||
func (*TestOldDeviceID) ProtoMessage() {}
|
||||
func (*TestOldDeviceID) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_a5b590761a4231d0, []int{0}
|
||||
return fileDescriptor_f4a75253a19e48a2, []int{0}
|
||||
}
|
||||
func (m *TestOldDeviceID) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@ -61,14 +62,14 @@ func (m *TestOldDeviceID) XXX_DiscardUnknown() {
|
||||
var xxx_messageInfo_TestOldDeviceID proto.InternalMessageInfo
|
||||
|
||||
type TestNewDeviceID struct {
|
||||
Test DeviceID `protobuf:"bytes,1,opt,name=test,proto3,customtype=DeviceID" json:"test"`
|
||||
Test DeviceID `protobuf:"bytes,1,opt,name=test,proto3,customtype=DeviceID" json:"test" xml:"test"`
|
||||
}
|
||||
|
||||
func (m *TestNewDeviceID) Reset() { *m = TestNewDeviceID{} }
|
||||
func (m *TestNewDeviceID) String() string { return proto.CompactTextString(m) }
|
||||
func (*TestNewDeviceID) ProtoMessage() {}
|
||||
func (*TestNewDeviceID) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_a5b590761a4231d0, []int{1}
|
||||
return fileDescriptor_f4a75253a19e48a2, []int{1}
|
||||
}
|
||||
func (m *TestNewDeviceID) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
@ -102,22 +103,25 @@ func init() {
|
||||
proto.RegisterType((*TestNewDeviceID)(nil), "protocol.TestNewDeviceID")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("deviceid_test.proto", fileDescriptor_a5b590761a4231d0) }
|
||||
func init() { proto.RegisterFile("lib/protocol/deviceid_test.proto", fileDescriptor_f4a75253a19e48a2) }
|
||||
|
||||
var fileDescriptor_a5b590761a4231d0 = []byte{
|
||||
// 182 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4e, 0x49, 0x2d, 0xcb,
|
||||
0x4c, 0x4e, 0xcd, 0x4c, 0x89, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
|
||||
0xe2, 0x00, 0x53, 0xc9, 0xf9, 0x39, 0x52, 0xca, 0x45, 0xa9, 0x05, 0xf9, 0xc5, 0xfa, 0x60, 0x7e,
|
||||
0x52, 0x69, 0x9a, 0x7e, 0x7a, 0x7e, 0x7a, 0x3e, 0x98, 0x03, 0x66, 0x41, 0x94, 0x2b, 0xa9, 0x72,
|
||||
0xf1, 0x87, 0xa4, 0x16, 0x97, 0xf8, 0xe7, 0xa4, 0xb8, 0x80, 0x0d, 0xf3, 0x74, 0x11, 0x12, 0xe2,
|
||||
0x62, 0x01, 0x99, 0x27, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x66, 0x2b, 0x99, 0x43, 0x94,
|
||||
0xf9, 0xa5, 0x96, 0xc3, 0x95, 0xa9, 0x20, 0x2b, 0x73, 0x12, 0x38, 0x71, 0x4f, 0x9e, 0xe1, 0xd6,
|
||||
0x3d, 0x79, 0x0e, 0x98, 0x3c, 0x44, 0xa3, 0x93, 0xc6, 0x89, 0x87, 0x72, 0x0c, 0x17, 0x1e, 0xca,
|
||||
0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x0c, 0x2f, 0x1e,
|
||||
0xc9, 0x31, 0x4c, 0x78, 0x2c, 0xc7, 0xb0, 0xe0, 0xb1, 0x1c, 0xe3, 0x85, 0xc7, 0x72, 0x0c, 0x37,
|
||||
0x1e, 0xcb, 0x31, 0x24, 0xb1, 0x81, 0x1d, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x96,
|
||||
0x3e, 0xc0, 0xd6, 0x00, 0x00, 0x00,
|
||||
var fileDescriptor_f4a75253a19e48a2 = []byte{
|
||||
// 237 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xc8, 0xc9, 0x4c, 0xd2,
|
||||
0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0xce, 0xcf, 0xd1, 0x4f, 0x49, 0x2d, 0xcb, 0x4c, 0x4e, 0xcd,
|
||||
0x4c, 0x89, 0x2f, 0x49, 0x2d, 0x2e, 0xd1, 0x03, 0x0b, 0x0b, 0x71, 0xc0, 0x64, 0xa5, 0x38, 0x53,
|
||||
0x2b, 0xa0, 0x82, 0x52, 0xca, 0x45, 0xa9, 0x05, 0xf9, 0xc5, 0x10, 0x8d, 0x49, 0xa5, 0x69, 0xfa,
|
||||
0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x0e, 0x98, 0x05, 0x51, 0xa4, 0x64, 0xcb, 0xc5, 0x1f, 0x92, 0x5a,
|
||||
0x5c, 0xe2, 0x9f, 0x93, 0xe2, 0x02, 0x36, 0xd7, 0xd3, 0x45, 0x48, 0x8b, 0x8b, 0x05, 0x64, 0xb4,
|
||||
0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, 0x93, 0xd8, 0xab, 0x7b, 0xf2, 0x60, 0xfe, 0xa7, 0x7b, 0xf2,
|
||||
0x5c, 0x15, 0xb9, 0x39, 0x56, 0x4a, 0x20, 0x8e, 0x52, 0x10, 0x58, 0x4c, 0x29, 0x10, 0xa2, 0xdd,
|
||||
0x2f, 0xb5, 0x1c, 0xae, 0xdd, 0x0e, 0x45, 0xbb, 0xd6, 0x89, 0x7b, 0xf2, 0x0c, 0xb7, 0xee, 0xc9,
|
||||
0x73, 0xc0, 0xe4, 0xb1, 0x1b, 0xd7, 0x71, 0x41, 0x85, 0x11, 0x62, 0xa4, 0x93, 0xef, 0x89, 0x87,
|
||||
0x72, 0x0c, 0x17, 0x1e, 0xca, 0x31, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x84,
|
||||
0xc7, 0x72, 0x0c, 0x0b, 0x1e, 0xcb, 0x31, 0x5e, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43,
|
||||
0x94, 0x76, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x71, 0x65, 0x5e,
|
||||
0x72, 0x49, 0x46, 0x66, 0x5e, 0x3a, 0x12, 0x0b, 0x39, 0xb8, 0x92, 0xd8, 0xc0, 0x2c, 0x63, 0x40,
|
||||
0x00, 0x00, 0x00, 0xff, 0xff, 0x9a, 0x0a, 0x77, 0x43, 0x45, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *TestOldDeviceID) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -1,23 +0,0 @@
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package protocol;
|
||||
|
||||
import "repos/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
option (gogoproto.sizer_all) = false;
|
||||
option (gogoproto.protosizer_all) = true;
|
||||
option (gogoproto.goproto_enum_stringer_all) = false;
|
||||
option (gogoproto.goproto_enum_prefix_all) = false;
|
||||
option (gogoproto.goproto_unkeyed_all) = false;
|
||||
option (gogoproto.goproto_unrecognized_all) = false;
|
||||
option (gogoproto.goproto_sizecache_all) = false;
|
||||
|
||||
message TestOldDeviceID {
|
||||
bytes test = 1;
|
||||
}
|
||||
|
||||
message TestNewDeviceID {
|
||||
bytes test = 1 [(gogoproto.customtype) = "DeviceID", (gogoproto.nullable) = false];
|
||||
}
|
490
lib/protocol/mocked_connection_info_test.go
Normal file
490
lib/protocol/mocked_connection_info_test.go
Normal file
@ -0,0 +1,490 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type mockedConnectionInfo struct {
|
||||
CryptoStub func() string
|
||||
cryptoMutex sync.RWMutex
|
||||
cryptoArgsForCall []struct {
|
||||
}
|
||||
cryptoReturns struct {
|
||||
result1 string
|
||||
}
|
||||
cryptoReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
EstablishedAtStub func() time.Time
|
||||
establishedAtMutex sync.RWMutex
|
||||
establishedAtArgsForCall []struct {
|
||||
}
|
||||
establishedAtReturns struct {
|
||||
result1 time.Time
|
||||
}
|
||||
establishedAtReturnsOnCall map[int]struct {
|
||||
result1 time.Time
|
||||
}
|
||||
PriorityStub func() int
|
||||
priorityMutex sync.RWMutex
|
||||
priorityArgsForCall []struct {
|
||||
}
|
||||
priorityReturns struct {
|
||||
result1 int
|
||||
}
|
||||
priorityReturnsOnCall map[int]struct {
|
||||
result1 int
|
||||
}
|
||||
RemoteAddrStub func() net.Addr
|
||||
remoteAddrMutex sync.RWMutex
|
||||
remoteAddrArgsForCall []struct {
|
||||
}
|
||||
remoteAddrReturns struct {
|
||||
result1 net.Addr
|
||||
}
|
||||
remoteAddrReturnsOnCall map[int]struct {
|
||||
result1 net.Addr
|
||||
}
|
||||
StringStub func() string
|
||||
stringMutex sync.RWMutex
|
||||
stringArgsForCall []struct {
|
||||
}
|
||||
stringReturns struct {
|
||||
result1 string
|
||||
}
|
||||
stringReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
TransportStub func() string
|
||||
transportMutex sync.RWMutex
|
||||
transportArgsForCall []struct {
|
||||
}
|
||||
transportReturns struct {
|
||||
result1 string
|
||||
}
|
||||
transportReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
TypeStub func() string
|
||||
typeMutex sync.RWMutex
|
||||
typeArgsForCall []struct {
|
||||
}
|
||||
typeReturns struct {
|
||||
result1 string
|
||||
}
|
||||
typeReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) Crypto() string {
|
||||
fake.cryptoMutex.Lock()
|
||||
ret, specificReturn := fake.cryptoReturnsOnCall[len(fake.cryptoArgsForCall)]
|
||||
fake.cryptoArgsForCall = append(fake.cryptoArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.CryptoStub
|
||||
fakeReturns := fake.cryptoReturns
|
||||
fake.recordInvocation("Crypto", []interface{}{})
|
||||
fake.cryptoMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) CryptoCallCount() int {
|
||||
fake.cryptoMutex.RLock()
|
||||
defer fake.cryptoMutex.RUnlock()
|
||||
return len(fake.cryptoArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) CryptoCalls(stub func() string) {
|
||||
fake.cryptoMutex.Lock()
|
||||
defer fake.cryptoMutex.Unlock()
|
||||
fake.CryptoStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) CryptoReturns(result1 string) {
|
||||
fake.cryptoMutex.Lock()
|
||||
defer fake.cryptoMutex.Unlock()
|
||||
fake.CryptoStub = nil
|
||||
fake.cryptoReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) CryptoReturnsOnCall(i int, result1 string) {
|
||||
fake.cryptoMutex.Lock()
|
||||
defer fake.cryptoMutex.Unlock()
|
||||
fake.CryptoStub = nil
|
||||
if fake.cryptoReturnsOnCall == nil {
|
||||
fake.cryptoReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.cryptoReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) EstablishedAt() time.Time {
|
||||
fake.establishedAtMutex.Lock()
|
||||
ret, specificReturn := fake.establishedAtReturnsOnCall[len(fake.establishedAtArgsForCall)]
|
||||
fake.establishedAtArgsForCall = append(fake.establishedAtArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.EstablishedAtStub
|
||||
fakeReturns := fake.establishedAtReturns
|
||||
fake.recordInvocation("EstablishedAt", []interface{}{})
|
||||
fake.establishedAtMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) EstablishedAtCallCount() int {
|
||||
fake.establishedAtMutex.RLock()
|
||||
defer fake.establishedAtMutex.RUnlock()
|
||||
return len(fake.establishedAtArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) EstablishedAtCalls(stub func() time.Time) {
|
||||
fake.establishedAtMutex.Lock()
|
||||
defer fake.establishedAtMutex.Unlock()
|
||||
fake.EstablishedAtStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) EstablishedAtReturns(result1 time.Time) {
|
||||
fake.establishedAtMutex.Lock()
|
||||
defer fake.establishedAtMutex.Unlock()
|
||||
fake.EstablishedAtStub = nil
|
||||
fake.establishedAtReturns = struct {
|
||||
result1 time.Time
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) EstablishedAtReturnsOnCall(i int, result1 time.Time) {
|
||||
fake.establishedAtMutex.Lock()
|
||||
defer fake.establishedAtMutex.Unlock()
|
||||
fake.EstablishedAtStub = nil
|
||||
if fake.establishedAtReturnsOnCall == nil {
|
||||
fake.establishedAtReturnsOnCall = make(map[int]struct {
|
||||
result1 time.Time
|
||||
})
|
||||
}
|
||||
fake.establishedAtReturnsOnCall[i] = struct {
|
||||
result1 time.Time
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) Priority() int {
|
||||
fake.priorityMutex.Lock()
|
||||
ret, specificReturn := fake.priorityReturnsOnCall[len(fake.priorityArgsForCall)]
|
||||
fake.priorityArgsForCall = append(fake.priorityArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.PriorityStub
|
||||
fakeReturns := fake.priorityReturns
|
||||
fake.recordInvocation("Priority", []interface{}{})
|
||||
fake.priorityMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) PriorityCallCount() int {
|
||||
fake.priorityMutex.RLock()
|
||||
defer fake.priorityMutex.RUnlock()
|
||||
return len(fake.priorityArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) PriorityCalls(stub func() int) {
|
||||
fake.priorityMutex.Lock()
|
||||
defer fake.priorityMutex.Unlock()
|
||||
fake.PriorityStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) PriorityReturns(result1 int) {
|
||||
fake.priorityMutex.Lock()
|
||||
defer fake.priorityMutex.Unlock()
|
||||
fake.PriorityStub = nil
|
||||
fake.priorityReturns = struct {
|
||||
result1 int
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) PriorityReturnsOnCall(i int, result1 int) {
|
||||
fake.priorityMutex.Lock()
|
||||
defer fake.priorityMutex.Unlock()
|
||||
fake.PriorityStub = nil
|
||||
if fake.priorityReturnsOnCall == nil {
|
||||
fake.priorityReturnsOnCall = make(map[int]struct {
|
||||
result1 int
|
||||
})
|
||||
}
|
||||
fake.priorityReturnsOnCall[i] = struct {
|
||||
result1 int
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) RemoteAddr() net.Addr {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
ret, specificReturn := fake.remoteAddrReturnsOnCall[len(fake.remoteAddrArgsForCall)]
|
||||
fake.remoteAddrArgsForCall = append(fake.remoteAddrArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.RemoteAddrStub
|
||||
fakeReturns := fake.remoteAddrReturns
|
||||
fake.recordInvocation("RemoteAddr", []interface{}{})
|
||||
fake.remoteAddrMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) RemoteAddrCallCount() int {
|
||||
fake.remoteAddrMutex.RLock()
|
||||
defer fake.remoteAddrMutex.RUnlock()
|
||||
return len(fake.remoteAddrArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) RemoteAddrCalls(stub func() net.Addr) {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
defer fake.remoteAddrMutex.Unlock()
|
||||
fake.RemoteAddrStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) RemoteAddrReturns(result1 net.Addr) {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
defer fake.remoteAddrMutex.Unlock()
|
||||
fake.RemoteAddrStub = nil
|
||||
fake.remoteAddrReturns = struct {
|
||||
result1 net.Addr
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) RemoteAddrReturnsOnCall(i int, result1 net.Addr) {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
defer fake.remoteAddrMutex.Unlock()
|
||||
fake.RemoteAddrStub = nil
|
||||
if fake.remoteAddrReturnsOnCall == nil {
|
||||
fake.remoteAddrReturnsOnCall = make(map[int]struct {
|
||||
result1 net.Addr
|
||||
})
|
||||
}
|
||||
fake.remoteAddrReturnsOnCall[i] = struct {
|
||||
result1 net.Addr
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) String() string {
|
||||
fake.stringMutex.Lock()
|
||||
ret, specificReturn := fake.stringReturnsOnCall[len(fake.stringArgsForCall)]
|
||||
fake.stringArgsForCall = append(fake.stringArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.StringStub
|
||||
fakeReturns := fake.stringReturns
|
||||
fake.recordInvocation("String", []interface{}{})
|
||||
fake.stringMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) StringCallCount() int {
|
||||
fake.stringMutex.RLock()
|
||||
defer fake.stringMutex.RUnlock()
|
||||
return len(fake.stringArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) StringCalls(stub func() string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) StringReturns(result1 string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = nil
|
||||
fake.stringReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) StringReturnsOnCall(i int, result1 string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = nil
|
||||
if fake.stringReturnsOnCall == nil {
|
||||
fake.stringReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.stringReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) Transport() string {
|
||||
fake.transportMutex.Lock()
|
||||
ret, specificReturn := fake.transportReturnsOnCall[len(fake.transportArgsForCall)]
|
||||
fake.transportArgsForCall = append(fake.transportArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.TransportStub
|
||||
fakeReturns := fake.transportReturns
|
||||
fake.recordInvocation("Transport", []interface{}{})
|
||||
fake.transportMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TransportCallCount() int {
|
||||
fake.transportMutex.RLock()
|
||||
defer fake.transportMutex.RUnlock()
|
||||
return len(fake.transportArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TransportCalls(stub func() string) {
|
||||
fake.transportMutex.Lock()
|
||||
defer fake.transportMutex.Unlock()
|
||||
fake.TransportStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TransportReturns(result1 string) {
|
||||
fake.transportMutex.Lock()
|
||||
defer fake.transportMutex.Unlock()
|
||||
fake.TransportStub = nil
|
||||
fake.transportReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TransportReturnsOnCall(i int, result1 string) {
|
||||
fake.transportMutex.Lock()
|
||||
defer fake.transportMutex.Unlock()
|
||||
fake.TransportStub = nil
|
||||
if fake.transportReturnsOnCall == nil {
|
||||
fake.transportReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.transportReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) Type() string {
|
||||
fake.typeMutex.Lock()
|
||||
ret, specificReturn := fake.typeReturnsOnCall[len(fake.typeArgsForCall)]
|
||||
fake.typeArgsForCall = append(fake.typeArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.TypeStub
|
||||
fakeReturns := fake.typeReturns
|
||||
fake.recordInvocation("Type", []interface{}{})
|
||||
fake.typeMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TypeCallCount() int {
|
||||
fake.typeMutex.RLock()
|
||||
defer fake.typeMutex.RUnlock()
|
||||
return len(fake.typeArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TypeCalls(stub func() string) {
|
||||
fake.typeMutex.Lock()
|
||||
defer fake.typeMutex.Unlock()
|
||||
fake.TypeStub = stub
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TypeReturns(result1 string) {
|
||||
fake.typeMutex.Lock()
|
||||
defer fake.typeMutex.Unlock()
|
||||
fake.TypeStub = nil
|
||||
fake.typeReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) TypeReturnsOnCall(i int, result1 string) {
|
||||
fake.typeMutex.Lock()
|
||||
defer fake.typeMutex.Unlock()
|
||||
fake.TypeStub = nil
|
||||
if fake.typeReturnsOnCall == nil {
|
||||
fake.typeReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.typeReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.cryptoMutex.RLock()
|
||||
defer fake.cryptoMutex.RUnlock()
|
||||
fake.establishedAtMutex.RLock()
|
||||
defer fake.establishedAtMutex.RUnlock()
|
||||
fake.priorityMutex.RLock()
|
||||
defer fake.priorityMutex.RUnlock()
|
||||
fake.remoteAddrMutex.RLock()
|
||||
defer fake.remoteAddrMutex.RUnlock()
|
||||
fake.stringMutex.RLock()
|
||||
defer fake.stringMutex.RUnlock()
|
||||
fake.transportMutex.RLock()
|
||||
defer fake.transportMutex.RUnlock()
|
||||
fake.typeMutex.RLock()
|
||||
defer fake.typeMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *mockedConnectionInfo) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
1112
lib/protocol/mocks/connection.go
Normal file
1112
lib/protocol/mocks/connection.go
Normal file
File diff suppressed because it is too large
Load Diff
494
lib/protocol/mocks/connection_info.go
Normal file
494
lib/protocol/mocks/connection_info.go
Normal file
@ -0,0 +1,494 @@
|
||||
// Code generated by counterfeiter. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
)
|
||||
|
||||
type ConnectionInfo struct {
|
||||
CryptoStub func() string
|
||||
cryptoMutex sync.RWMutex
|
||||
cryptoArgsForCall []struct {
|
||||
}
|
||||
cryptoReturns struct {
|
||||
result1 string
|
||||
}
|
||||
cryptoReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
EstablishedAtStub func() time.Time
|
||||
establishedAtMutex sync.RWMutex
|
||||
establishedAtArgsForCall []struct {
|
||||
}
|
||||
establishedAtReturns struct {
|
||||
result1 time.Time
|
||||
}
|
||||
establishedAtReturnsOnCall map[int]struct {
|
||||
result1 time.Time
|
||||
}
|
||||
PriorityStub func() int
|
||||
priorityMutex sync.RWMutex
|
||||
priorityArgsForCall []struct {
|
||||
}
|
||||
priorityReturns struct {
|
||||
result1 int
|
||||
}
|
||||
priorityReturnsOnCall map[int]struct {
|
||||
result1 int
|
||||
}
|
||||
RemoteAddrStub func() net.Addr
|
||||
remoteAddrMutex sync.RWMutex
|
||||
remoteAddrArgsForCall []struct {
|
||||
}
|
||||
remoteAddrReturns struct {
|
||||
result1 net.Addr
|
||||
}
|
||||
remoteAddrReturnsOnCall map[int]struct {
|
||||
result1 net.Addr
|
||||
}
|
||||
StringStub func() string
|
||||
stringMutex sync.RWMutex
|
||||
stringArgsForCall []struct {
|
||||
}
|
||||
stringReturns struct {
|
||||
result1 string
|
||||
}
|
||||
stringReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
TransportStub func() string
|
||||
transportMutex sync.RWMutex
|
||||
transportArgsForCall []struct {
|
||||
}
|
||||
transportReturns struct {
|
||||
result1 string
|
||||
}
|
||||
transportReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
TypeStub func() string
|
||||
typeMutex sync.RWMutex
|
||||
typeArgsForCall []struct {
|
||||
}
|
||||
typeReturns struct {
|
||||
result1 string
|
||||
}
|
||||
typeReturnsOnCall map[int]struct {
|
||||
result1 string
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) Crypto() string {
|
||||
fake.cryptoMutex.Lock()
|
||||
ret, specificReturn := fake.cryptoReturnsOnCall[len(fake.cryptoArgsForCall)]
|
||||
fake.cryptoArgsForCall = append(fake.cryptoArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.CryptoStub
|
||||
fakeReturns := fake.cryptoReturns
|
||||
fake.recordInvocation("Crypto", []interface{}{})
|
||||
fake.cryptoMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) CryptoCallCount() int {
|
||||
fake.cryptoMutex.RLock()
|
||||
defer fake.cryptoMutex.RUnlock()
|
||||
return len(fake.cryptoArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) CryptoCalls(stub func() string) {
|
||||
fake.cryptoMutex.Lock()
|
||||
defer fake.cryptoMutex.Unlock()
|
||||
fake.CryptoStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) CryptoReturns(result1 string) {
|
||||
fake.cryptoMutex.Lock()
|
||||
defer fake.cryptoMutex.Unlock()
|
||||
fake.CryptoStub = nil
|
||||
fake.cryptoReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) CryptoReturnsOnCall(i int, result1 string) {
|
||||
fake.cryptoMutex.Lock()
|
||||
defer fake.cryptoMutex.Unlock()
|
||||
fake.CryptoStub = nil
|
||||
if fake.cryptoReturnsOnCall == nil {
|
||||
fake.cryptoReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.cryptoReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) EstablishedAt() time.Time {
|
||||
fake.establishedAtMutex.Lock()
|
||||
ret, specificReturn := fake.establishedAtReturnsOnCall[len(fake.establishedAtArgsForCall)]
|
||||
fake.establishedAtArgsForCall = append(fake.establishedAtArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.EstablishedAtStub
|
||||
fakeReturns := fake.establishedAtReturns
|
||||
fake.recordInvocation("EstablishedAt", []interface{}{})
|
||||
fake.establishedAtMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) EstablishedAtCallCount() int {
|
||||
fake.establishedAtMutex.RLock()
|
||||
defer fake.establishedAtMutex.RUnlock()
|
||||
return len(fake.establishedAtArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) EstablishedAtCalls(stub func() time.Time) {
|
||||
fake.establishedAtMutex.Lock()
|
||||
defer fake.establishedAtMutex.Unlock()
|
||||
fake.EstablishedAtStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) EstablishedAtReturns(result1 time.Time) {
|
||||
fake.establishedAtMutex.Lock()
|
||||
defer fake.establishedAtMutex.Unlock()
|
||||
fake.EstablishedAtStub = nil
|
||||
fake.establishedAtReturns = struct {
|
||||
result1 time.Time
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) EstablishedAtReturnsOnCall(i int, result1 time.Time) {
|
||||
fake.establishedAtMutex.Lock()
|
||||
defer fake.establishedAtMutex.Unlock()
|
||||
fake.EstablishedAtStub = nil
|
||||
if fake.establishedAtReturnsOnCall == nil {
|
||||
fake.establishedAtReturnsOnCall = make(map[int]struct {
|
||||
result1 time.Time
|
||||
})
|
||||
}
|
||||
fake.establishedAtReturnsOnCall[i] = struct {
|
||||
result1 time.Time
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) Priority() int {
|
||||
fake.priorityMutex.Lock()
|
||||
ret, specificReturn := fake.priorityReturnsOnCall[len(fake.priorityArgsForCall)]
|
||||
fake.priorityArgsForCall = append(fake.priorityArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.PriorityStub
|
||||
fakeReturns := fake.priorityReturns
|
||||
fake.recordInvocation("Priority", []interface{}{})
|
||||
fake.priorityMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) PriorityCallCount() int {
|
||||
fake.priorityMutex.RLock()
|
||||
defer fake.priorityMutex.RUnlock()
|
||||
return len(fake.priorityArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) PriorityCalls(stub func() int) {
|
||||
fake.priorityMutex.Lock()
|
||||
defer fake.priorityMutex.Unlock()
|
||||
fake.PriorityStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) PriorityReturns(result1 int) {
|
||||
fake.priorityMutex.Lock()
|
||||
defer fake.priorityMutex.Unlock()
|
||||
fake.PriorityStub = nil
|
||||
fake.priorityReturns = struct {
|
||||
result1 int
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) PriorityReturnsOnCall(i int, result1 int) {
|
||||
fake.priorityMutex.Lock()
|
||||
defer fake.priorityMutex.Unlock()
|
||||
fake.PriorityStub = nil
|
||||
if fake.priorityReturnsOnCall == nil {
|
||||
fake.priorityReturnsOnCall = make(map[int]struct {
|
||||
result1 int
|
||||
})
|
||||
}
|
||||
fake.priorityReturnsOnCall[i] = struct {
|
||||
result1 int
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) RemoteAddr() net.Addr {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
ret, specificReturn := fake.remoteAddrReturnsOnCall[len(fake.remoteAddrArgsForCall)]
|
||||
fake.remoteAddrArgsForCall = append(fake.remoteAddrArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.RemoteAddrStub
|
||||
fakeReturns := fake.remoteAddrReturns
|
||||
fake.recordInvocation("RemoteAddr", []interface{}{})
|
||||
fake.remoteAddrMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) RemoteAddrCallCount() int {
|
||||
fake.remoteAddrMutex.RLock()
|
||||
defer fake.remoteAddrMutex.RUnlock()
|
||||
return len(fake.remoteAddrArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) RemoteAddrCalls(stub func() net.Addr) {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
defer fake.remoteAddrMutex.Unlock()
|
||||
fake.RemoteAddrStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) RemoteAddrReturns(result1 net.Addr) {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
defer fake.remoteAddrMutex.Unlock()
|
||||
fake.RemoteAddrStub = nil
|
||||
fake.remoteAddrReturns = struct {
|
||||
result1 net.Addr
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) RemoteAddrReturnsOnCall(i int, result1 net.Addr) {
|
||||
fake.remoteAddrMutex.Lock()
|
||||
defer fake.remoteAddrMutex.Unlock()
|
||||
fake.RemoteAddrStub = nil
|
||||
if fake.remoteAddrReturnsOnCall == nil {
|
||||
fake.remoteAddrReturnsOnCall = make(map[int]struct {
|
||||
result1 net.Addr
|
||||
})
|
||||
}
|
||||
fake.remoteAddrReturnsOnCall[i] = struct {
|
||||
result1 net.Addr
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) String() string {
|
||||
fake.stringMutex.Lock()
|
||||
ret, specificReturn := fake.stringReturnsOnCall[len(fake.stringArgsForCall)]
|
||||
fake.stringArgsForCall = append(fake.stringArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.StringStub
|
||||
fakeReturns := fake.stringReturns
|
||||
fake.recordInvocation("String", []interface{}{})
|
||||
fake.stringMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) StringCallCount() int {
|
||||
fake.stringMutex.RLock()
|
||||
defer fake.stringMutex.RUnlock()
|
||||
return len(fake.stringArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) StringCalls(stub func() string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) StringReturns(result1 string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = nil
|
||||
fake.stringReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) StringReturnsOnCall(i int, result1 string) {
|
||||
fake.stringMutex.Lock()
|
||||
defer fake.stringMutex.Unlock()
|
||||
fake.StringStub = nil
|
||||
if fake.stringReturnsOnCall == nil {
|
||||
fake.stringReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.stringReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) Transport() string {
|
||||
fake.transportMutex.Lock()
|
||||
ret, specificReturn := fake.transportReturnsOnCall[len(fake.transportArgsForCall)]
|
||||
fake.transportArgsForCall = append(fake.transportArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.TransportStub
|
||||
fakeReturns := fake.transportReturns
|
||||
fake.recordInvocation("Transport", []interface{}{})
|
||||
fake.transportMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TransportCallCount() int {
|
||||
fake.transportMutex.RLock()
|
||||
defer fake.transportMutex.RUnlock()
|
||||
return len(fake.transportArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TransportCalls(stub func() string) {
|
||||
fake.transportMutex.Lock()
|
||||
defer fake.transportMutex.Unlock()
|
||||
fake.TransportStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TransportReturns(result1 string) {
|
||||
fake.transportMutex.Lock()
|
||||
defer fake.transportMutex.Unlock()
|
||||
fake.TransportStub = nil
|
||||
fake.transportReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TransportReturnsOnCall(i int, result1 string) {
|
||||
fake.transportMutex.Lock()
|
||||
defer fake.transportMutex.Unlock()
|
||||
fake.TransportStub = nil
|
||||
if fake.transportReturnsOnCall == nil {
|
||||
fake.transportReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.transportReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) Type() string {
|
||||
fake.typeMutex.Lock()
|
||||
ret, specificReturn := fake.typeReturnsOnCall[len(fake.typeArgsForCall)]
|
||||
fake.typeArgsForCall = append(fake.typeArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.TypeStub
|
||||
fakeReturns := fake.typeReturns
|
||||
fake.recordInvocation("Type", []interface{}{})
|
||||
fake.typeMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TypeCallCount() int {
|
||||
fake.typeMutex.RLock()
|
||||
defer fake.typeMutex.RUnlock()
|
||||
return len(fake.typeArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TypeCalls(stub func() string) {
|
||||
fake.typeMutex.Lock()
|
||||
defer fake.typeMutex.Unlock()
|
||||
fake.TypeStub = stub
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TypeReturns(result1 string) {
|
||||
fake.typeMutex.Lock()
|
||||
defer fake.typeMutex.Unlock()
|
||||
fake.TypeStub = nil
|
||||
fake.typeReturns = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) TypeReturnsOnCall(i int, result1 string) {
|
||||
fake.typeMutex.Lock()
|
||||
defer fake.typeMutex.Unlock()
|
||||
fake.TypeStub = nil
|
||||
if fake.typeReturnsOnCall == nil {
|
||||
fake.typeReturnsOnCall = make(map[int]struct {
|
||||
result1 string
|
||||
})
|
||||
}
|
||||
fake.typeReturnsOnCall[i] = struct {
|
||||
result1 string
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.cryptoMutex.RLock()
|
||||
defer fake.cryptoMutex.RUnlock()
|
||||
fake.establishedAtMutex.RLock()
|
||||
defer fake.establishedAtMutex.RUnlock()
|
||||
fake.priorityMutex.RLock()
|
||||
defer fake.priorityMutex.RUnlock()
|
||||
fake.remoteAddrMutex.RLock()
|
||||
defer fake.remoteAddrMutex.RUnlock()
|
||||
fake.stringMutex.RLock()
|
||||
defer fake.stringMutex.RUnlock()
|
||||
fake.transportMutex.RLock()
|
||||
defer fake.transportMutex.RUnlock()
|
||||
fake.typeMutex.RLock()
|
||||
defer fake.typeMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
}
|
||||
return copiedInvocations
|
||||
}
|
||||
|
||||
func (fake *ConnectionInfo) recordInvocation(key string, args []interface{}) {
|
||||
fake.invocationsMutex.Lock()
|
||||
defer fake.invocationsMutex.Unlock()
|
||||
if fake.invocations == nil {
|
||||
fake.invocations = map[string][][]interface{}{}
|
||||
}
|
||||
if fake.invocations[key] == nil {
|
||||
fake.invocations[key] = [][]interface{}{}
|
||||
}
|
||||
fake.invocations[key] = append(fake.invocations[key], args)
|
||||
}
|
||||
|
||||
var _ protocol.ConnectionInfo = new(ConnectionInfo)
|
@ -1,5 +1,12 @@
|
||||
// Copyright (C) 2014 The Protocol Authors.
|
||||
|
||||
// Prevents import loop, for internal testing
|
||||
//go:generate counterfeiter -o mocked_connection_info_test.go --fake-name mockedConnectionInfo . ConnectionInfo
|
||||
//go:generate go run ../../script/prune_mocks.go -t mocked_connection_info_test.go
|
||||
|
||||
//go:generate counterfeiter -o mocks/connection_info.go --fake-name ConnectionInfo . ConnectionInfo
|
||||
//go:generate counterfeiter -o mocks/connection.go --fake-name Connection . Connection
|
||||
|
||||
package protocol
|
||||
|
||||
import (
|
||||
|
@ -31,10 +31,10 @@ func TestPing(t *testing.T) {
|
||||
ar, aw := io.Pipe()
|
||||
br, bw := io.Pipe()
|
||||
|
||||
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, newTestModel(), &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c0.Start()
|
||||
defer closeAndWait(c0, ar, bw)
|
||||
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, newTestModel(), &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, newTestModel(), new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c1.Start()
|
||||
defer closeAndWait(c1, ar, bw)
|
||||
c0.ClusterConfig(ClusterConfig{})
|
||||
@ -57,10 +57,10 @@ func TestClose(t *testing.T) {
|
||||
ar, aw := io.Pipe()
|
||||
br, bw := io.Pipe()
|
||||
|
||||
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c0.Start()
|
||||
defer closeAndWait(c0, ar, bw)
|
||||
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, &testutils.FakeConnectionInfo{"name"}, CompressionAlways)
|
||||
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionAlways)
|
||||
c1.Start()
|
||||
defer closeAndWait(c1, ar, bw)
|
||||
c0.ClusterConfig(ClusterConfig{})
|
||||
@ -102,7 +102,7 @@ func TestCloseOnBlockingSend(t *testing.T) {
|
||||
m := newTestModel()
|
||||
|
||||
rw := testutils.NewBlockingRW()
|
||||
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c.Start()
|
||||
defer closeAndWait(c, rw)
|
||||
|
||||
@ -153,10 +153,10 @@ func TestCloseRace(t *testing.T) {
|
||||
ar, aw := io.Pipe()
|
||||
br, bw := io.Pipe()
|
||||
|
||||
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, &testutils.FakeConnectionInfo{"c0"}, CompressionNever).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c0 := NewConnection(c0ID, ar, bw, testutils.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionNever).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c0.Start()
|
||||
defer closeAndWait(c0, ar, bw)
|
||||
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, &testutils.FakeConnectionInfo{"c1"}, CompressionNever)
|
||||
c1 := NewConnection(c1ID, br, aw, testutils.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionNever)
|
||||
c1.Start()
|
||||
defer closeAndWait(c1, ar, bw)
|
||||
c0.ClusterConfig(ClusterConfig{})
|
||||
@ -193,7 +193,7 @@ func TestClusterConfigFirst(t *testing.T) {
|
||||
m := newTestModel()
|
||||
|
||||
rw := testutils.NewBlockingRW()
|
||||
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c.Start()
|
||||
defer closeAndWait(c, rw)
|
||||
|
||||
@ -245,7 +245,7 @@ func TestCloseTimeout(t *testing.T) {
|
||||
m := newTestModel()
|
||||
|
||||
rw := testutils.NewBlockingRW()
|
||||
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c.Start()
|
||||
defer closeAndWait(c, rw)
|
||||
|
||||
@ -865,7 +865,7 @@ func TestClusterConfigAfterClose(t *testing.T) {
|
||||
m := newTestModel()
|
||||
|
||||
rw := testutils.NewBlockingRW()
|
||||
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c := NewConnection(c0ID, rw, rw, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c.Start()
|
||||
defer closeAndWait(c, rw)
|
||||
|
||||
@ -889,7 +889,7 @@ func TestDispatcherToCloseDeadlock(t *testing.T) {
|
||||
// the model callbacks (ClusterConfig).
|
||||
m := newTestModel()
|
||||
rw := testutils.NewBlockingRW()
|
||||
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, &testutils.FakeConnectionInfo{"name"}, CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
c := NewConnection(c0ID, rw, &testutils.NoopRW{}, testutils.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways).(wireFormatConnection).Connection.(*rawConnection)
|
||||
m.ccFn = func(devID DeviceID, cc ClusterConfig) {
|
||||
c.Close(errManual)
|
||||
}
|
||||
|
@ -8,9 +8,7 @@ package testutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ErrClosed = errors.New("closed")
|
||||
@ -60,47 +58,3 @@ type NoopCloser struct{}
|
||||
func (NoopCloser) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FakeConnectionInfo implements the methods of protocol.Connection that are
|
||||
// not implemented by protocol.Connection
|
||||
type FakeConnectionInfo struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) RemoteAddr() net.Addr {
|
||||
return &FakeAddr{}
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) Type() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) Crypto() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) Transport() string {
|
||||
return "fake"
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) Priority() int {
|
||||
return 9000
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (f *FakeConnectionInfo) EstablishedAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
type FakeAddr struct{}
|
||||
|
||||
func (FakeAddr) Network() string {
|
||||
return "network"
|
||||
}
|
||||
|
||||
func (FakeAddr) String() string {
|
||||
return "address"
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ var copyrightRegexps = []string{
|
||||
`package auto`,
|
||||
`automatically generated by genxdr`,
|
||||
`generated by protoc`,
|
||||
`^// Code generated .* DO NOT EDIT\.$`,
|
||||
}
|
||||
|
||||
var copyrightRe = regexp.MustCompile(strings.Join(copyrightRegexps, "|"))
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
|
||||
// Inception, go generate calls the script itself that then deals with generation.
|
||||
// This is only done because go:generate does not support wildcards in paths.
|
||||
//go:generate go run generate.go lib/protocol lib/config lib/fs lib/db
|
||||
//go:generate go run generate.go lib/protocol lib/config lib/fs lib/db lib/discover
|
||||
|
||||
func main() {
|
||||
for _, path := range os.Args[1:] {
|
||||
|
13
proto/lib/discover/local.proto
Normal file
13
proto/lib/discover/local.proto
Normal file
@ -0,0 +1,13 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package discover;
|
||||
|
||||
import "repos/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
import "ext.proto";
|
||||
|
||||
message Announce {
|
||||
bytes id = 1 [(ext.goname) = "ID", (ext.device_id) = true, (gogoproto.nullable) = false];
|
||||
repeated string addresses = 2;
|
||||
int64 instance_id = 3 [(ext.goname) = "InstanceID"];
|
||||
}
|
15
proto/lib/protocol/deviceid_test.proto
Normal file
15
proto/lib/protocol/deviceid_test.proto
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package protocol;
|
||||
|
||||
import "ext.proto";
|
||||
import "repos/protobuf/gogoproto/gogo.proto";
|
||||
|
||||
message TestOldDeviceID {
|
||||
bytes test = 1;
|
||||
}
|
||||
|
||||
message TestNewDeviceID {
|
||||
bytes test = 1 [(ext.device_id) = true, (gogoproto.nullable) = false];
|
||||
}
|
79
script/prune_mocks.go
Normal file
79
script/prune_mocks.go
Normal file
@ -0,0 +1,79 @@
|
||||
// Copyright (C) 2021 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var path string
|
||||
flag.StringVar(&path, "t", "", "Name of file to prune")
|
||||
flag.Parse()
|
||||
|
||||
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
return nil
|
||||
}
|
||||
err = pruneInterfaceCheck(path, info.Size())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = exec.Command("goimports", "-w", path).Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func pruneInterfaceCheck(path string, size int64) error {
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
tmp, err := ioutil.TempFile(".", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(fd)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "var _ ") {
|
||||
continue
|
||||
}
|
||||
if _, err := tmp.WriteString(line + "\n"); err != nil {
|
||||
os.Remove(tmp.Name())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := fd.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Remove(path); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(tmp.Name(), path)
|
||||
}
|
Loading…
Reference in New Issue
Block a user