func NewServer(t *testing.T, deployment *docker.Deployment, opts ...func(*Server)) *Server {
	// generate signing key
	_, priv, err := ed25519.GenerateKey(nil)
	if err != nil {
		t.Fatalf("federation.NewServer failed to generate ed25519 key: %s", err)
	}

	srv := &Server{
		t:                           t,
		Priv:                        priv,
		KeyID:                       "ed25519:complement",
		mux:                         mux.NewRouter(),
		ServerName:                  docker.HostnameRunningComplement,
		rooms:                       make(map[string]*ServerRoom),
		aliases:                     make(map[string]string),
		UnexpectedRequestsAreErrors: true,
	}
	fetcher := &basicKeyFetcher{
		KeyFetcher: &gomatrixserverlib.DirectKeyFetcher{
			Client: gomatrixserverlib.NewClient(
				gomatrixserverlib.WithTransport(&docker.RoundTripper{Deployment: deployment}),
			),
		},
		srv: srv,
	}
	srv.keyRing = &gomatrixserverlib.KeyRing{
		KeyDatabase: &nopKeyDatabase{},
		KeyFetchers: []gomatrixserverlib.KeyFetcher{
			fetcher,
		},
	}
	srv.mux.Use(func(h http.Handler) http.Handler {
		// Return a json Content-Type header to all requests by default
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			w.Header().Add("Content-Type", "application/json")
			h.ServeHTTP(w, r)
		})
	})
	srv.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		if srv.UnexpectedRequestsAreErrors {
			t.Errorf("Server.UnexpectedRequestsAreErrors=true received unexpected request to server: %s %s", req.Method, req.URL.Path)
		} else {
			t.Logf("Server.UnexpectedRequestsAreErrors=false received unexpected request to server: %s %s", req.Method, req.URL.Path)
		}
		w.WriteHeader(404)
		w.Write([]byte("complement: federation server is not listening for this path"))
	})

	// generate certs and an http.Server
	httpServer, certPath, keyPath, err := federationServer("name", srv.mux)
	if err != nil {
		t.Fatalf("complement: unable to create federation server and certificates: %s", err.Error())
	}
	srv.certPath = certPath
	srv.keyPath = keyPath
	srv.srv = httpServer

	for _, opt := range opts {
		opt(srv)
	}
	return srv
}
// NewServer creates a new federation server with configured options.
NewServer creates a new federation server with configured options.
// NewServer creates a new federation server with configured options .
func NewServer(t *testing.T, deployment *docker.Deployment, opts ...func(*Server)) *Server {
	_, priv, err := ed25519.GenerateKey(nil)
	if err != nil {
		t.Fatalf("federation.NewServer failed to generate ed25519 key: %s", err)
	}
	srv := &Server{
		t:                           t,
		Priv:                        priv,
		KeyID:                       "ed25519:complement",
		mux:                         mux.NewRouter(),
		ServerName:                  docker.HostnameRunningComplement,
		rooms:                       make(map[string]*ServerRoom),
		aliases:                     make(map[string]string),
		UnexpectedRequestsAreErrors: true,
	}
	fetcher := &basicKeyFetcher{
		KeyFetcher: &gomatrixserverlib.DirectKeyFetcher{
			Client: gomatrixserverlib.NewClient(
				gomatrixserverlib.WithTransport(&docker.RoundTripper{Deployment: deployment}),
			),
		},
		srv: srv,
	}
	srv.keyRing = &gomatrixserverlib.KeyRing{
		KeyDatabase: &nopKeyDatabase{},
		KeyFetchers: []gomatrixserverlib.KeyFetcher{
			fetcher,
		},
	}
	srv.mux.Use(func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			w.Header().Add("Content-Type", "application/json")
			h.ServeHTTP(w, r)
		})
	})
	srv.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		if srv.UnexpectedRequestsAreErrors {
			t.Errorf("Server.UnexpectedRequestsAreErrors=true received unexpected request to server: %s %s", req.Method, req.URL.Path)
		} else {
			t.Logf("Server.UnexpectedRequestsAreErrors=false received unexpected request to server: %s %s", req.Method, req.URL.Path)
		}
		w.WriteHeader(404)
		w.Write([]byte("complement: federation server is not listening for this path"))
	})
	httpServer, certPath, keyPath, err := federationServer("name", srv.mux)
	if err != nil {
		t.Fatalf("complement: unable to create federation server and certificates: %s", err.Error())
	}
	srv.certPath = certPath
	srv.keyPath = keyPath
	srv.srv = httpServer
	for _, opt := range opts {
		opt(srv)
	}
	return srv
}
func NewServer ( t * testing . T , deployment * docker . Deployment , opts ... func ( * Server ) ) * Server { _ , priv , err := ed25519 . GenerateKey ( nil ) if err != nil { t . Fatalf ( " " , err ) } srv := & Server { t : t , Priv : priv , KeyID : " " , mux : mux . NewRouter ( ) , ServerName : docker . HostnameRunningComplement , rooms : make ( map [ string ] * ServerRoom ) , aliases : make ( map [ string ] string ) , UnexpectedRequestsAreErrors : true , } fetcher := & basicKeyFetcher { KeyFetcher : & gomatrixserverlib . DirectKeyFetcher { Client : gomatrixserverlib . NewClient ( gomatrixserverlib . WithTransport ( & docker . RoundTripper { Deployment : deployment } ) , ) , } , srv : srv , } srv . keyRing = & gomatrixserverlib . KeyRing { KeyDatabase : & nopKeyDatabase { } , KeyFetchers : [ ] gomatrixserverlib . KeyFetcher { fetcher , } , } srv . mux . Use ( func ( h http . Handler ) http . Handler { return http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { w . Header ( ) . Add ( " " , " " ) h . ServeHTTP ( w , r ) } ) } ) srv . mux . NotFoundHandler = http . HandlerFunc ( func ( w http . ResponseWriter , req * http . Request ) { if srv . UnexpectedRequestsAreErrors { t . Errorf ( " " , req . Method , req . URL . Path ) } else { t . Logf ( " " , req . Method , req . URL . Path ) } w . WriteHeader ( 404 ) w . Write ( [ ] byte ( " " ) ) } ) httpServer , certPath , keyPath , err := federationServer ( " " , srv . mux ) if err != nil { t . Fatalf ( " " , err . Error ( ) ) } srv . certPath = certPath srv . keyPath = keyPath srv . srv = httpServer for _ , opt := range opts { opt ( srv ) } return srv }
NewServer creates a new federation server with configured options.
NewServer creates a new federation server with configured options .
// generate signing key // Return a json Content-Type header to all requests by default // generate certs and an http.Server