MCPcopy Create free account
hub / github.com/daodst/chat / TestMain

Function TestMain

federationapi/federationapi_keys_test.go:54–110  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

52}
53
54func TestMain(m *testing.M) {
55 // Set up the server key API for each "server" that we
56 // will use in our tests.
57 os.Exit(func() int {
58 for _, s := range servers {
59 // Generate a new key.
60 _, testPriv, err := ed25519.GenerateKey(nil)
61 if err != nil {
62 panic("can't generate identity key: " + err.Error())
63 }
64
65 // Create a new cache but don't enable prometheus!
66 s.cache = caching.NewRistrettoCache(8*1024*1024, time.Hour, false)
67
68 // Create a temporary directory for JetStream.
69 d, err := os.MkdirTemp("./", "jetstream*")
70 if err != nil {
71 panic(err)
72 }
73 defer os.RemoveAll(d)
74
75 // Draw up just enough Dendrite config for the server key
76 // API to work.
77 cfg := &config.Dendrite{}
78 cfg.Defaults(true)
79 cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
80 cfg.Global.PrivateKey = testPriv
81 cfg.Global.JetStream.InMemory = true
82 cfg.Global.JetStream.TopicPrefix = string(s.name[:1])
83 cfg.Global.JetStream.StoragePath = config.Path(d)
84 cfg.Global.KeyID = serverKeyID
85 cfg.Global.KeyValidityPeriod = s.validity
86 cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
87 s.config = &cfg.FederationAPI
88
89 // Create a transport which redirects federation requests to
90 // the mock round tripper. Since we're not *really* listening for
91 // federation requests then this will return the key instead.
92 transport := &http.Transport{}
93 transport.RegisterProtocol("matrix", &MockRoundTripper{})
94
95 // Create the federation client.
96 s.fedclient = gomatrixserverlib.NewFederationClient(
97 s.config.Matrix.ServerName, serverKeyID, testPriv,
98 gomatrixserverlib.WithTransport(transport),
99 )
100
101 // Finally, build the server key APIs.
102 sbase := base.NewBaseDendrite(cfg, "Monolith", base.DisableMetrics)
103 s.api = NewInternalAPI(sbase, s.fedclient, nil, s.cache, nil, true)
104 }
105
106 // Now that we have built our server key APIs, start the
107 // rest of the tests.
108 return m.Run()
109 }())
110}
111

Callers

nothing calls this directly

Calls 4

DefaultsMethod · 0.95
RunMethod · 0.80
NewInternalAPIFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected