MCPcopy
hub / github.com/syncthing/syncthing / TestStartupFail

Function TestStartupFail

lib/syncthing/syncthing_test.go:58–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestStartupFail(t *testing.T) {
59 cert, err := tlsutil.NewCertificateInMemory("syncthing", 365)
60 if err != nil {
61 t.Fatal(err)
62 }
63 id := protocol.NewDeviceID(cert.Certificate[0])
64 conflID := protocol.DeviceID{}
65 copy(conflID[:8], id[:8])
66
67 cfg := config.Wrap(tempCfgFilename(t), config.Configuration{
68 Devices: []config.DeviceConfiguration{
69 {DeviceID: id},
70 {DeviceID: conflID},
71 },
72 }, protocol.LocalDeviceID, events.NoopLogger)
73 defer os.Remove(cfg.ConfigPath())
74
75 sdb, err := sqlite.Open(t.TempDir())
76 if err != nil {
77 t.Fatal(err)
78 }
79 t.Cleanup(func() {
80 sdb.Close()
81 })
82 app, err := New(cfg, sdb, events.NoopLogger, cert, Options{})
83 if err != nil {
84 t.Fatal(err)
85 }
86 startErr := app.Start()
87 if startErr == nil {
88 t.Fatal("Expected an error from Start, got nil")
89 }
90
91 done := make(chan struct{})
92 var waitE svcutil.ExitStatus
93 go func() {
94 waitE = app.Wait()
95 close(done)
96 }()
97
98 select {
99 case <-time.After(time.Second):
100 t.Fatal("Wait did not return within 1s")
101 case <-done:
102 }
103
104 if waitE != svcutil.ExitError {
105 t.Errorf("Got exit status %v, expected %v", waitE, svcutil.ExitError)
106 }
107
108 if err = app.Error(); err != startErr {
109 t.Errorf(`Got different errors "%v" from Start and "%v" from Error`, startErr, err)
110 }
111
112 if _, err := sdb.ListFolders(); err == nil {
113 t.Error("Expected error due to db being closed, got nil")
114 } else if !strings.Contains(err.Error(), "closed") {
115 t.Error("Expected error due to db being closed, got", err)

Callers

nothing calls this directly

Calls 15

NewCertificateInMemoryFunction · 0.92
NewDeviceIDFunction · 0.92
WrapFunction · 0.92
OpenFunction · 0.92
tempCfgFilenameFunction · 0.85
FatalMethod · 0.80
ContainsMethod · 0.80
NewFunction · 0.70
RemoveMethod · 0.65
ConfigPathMethod · 0.65
CloseMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected