You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: server.go
    path of file: ./repos/juju/apiserver/testserver
    
    the code of the file until where you have to start completion: // Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package testserver

import (
	"crypto/tls"
	"fmt"
	"net"
	"net/http"
	"net/http/httptest"

	"github.com/juju/clock"
	"github.com/juju/names/v5"
	jc "github.com/juju/testing/checkers"
	"github.com/pkg/errors"
	gc "gopkg.in/check.v1"

	"github.com/juju/juju/api"
	"github.com/juju/juju/apiserver"
	"github.com/juju/juju/apiserver/apiserverhttp"
	"github.com/juju/juju/apiserver/observer"
	"github.com/juju/juju/apiserver/observer/fakeobserver"
	"github.com/juju/juju/apiserver/stateauthenticator"
	apitesting "github.com/juju/juju/apiserver/testing"
	"github.com/juju/juju/core/auditlog"
	"github.com/juju/juju/core/cache"
	coredatabase "github.com/juju/juju/core/database"
	corelogger "github.com/juju/juju/core/logger"
	"github.com/juju/juju/core/multiwatcher"
	"github.com/juju/juju/core/presence"
	"github.com/juju/juju/pubsub/centralhub"
	"github.com/juju/juju/state"
	coretesting "github.com/juju/juju/testing"
)

// DefaultServerConfig returns the default configuration for starting a test server.
func DefaultServerConfig(c *gc.C, testclock clock.Clock) apiserver.ServerConfig {
	if testclock == nil {
		testclock = clock.WallClock
	}
	fakeOrigin := names.NewMachineTag("0")
	hub := centralhub.New(fakeOrigin, centralhub.PubsubNoOpMetrics{})
	return apiserver.ServerConfig{
    
func NewServerWithConfig(c *gc.C, statePool *state.StatePool, cfg apiserver.ServerConfig) *Server {
	// Note that we can't listen on localhost here because
	// TestAPIServerCanListenOnBothIPv4AndIPv6 assumes
	// that we listen on IPv6 too, and listening on localhost does not do that.
	listener, err := net.Listen("tcp", ":0")
	c.Assert(err, jc.ErrorIsNil)
	certPool, err := api.CreateCertPool(coretesting.CACert)
	if err != nil {
		c.Fatalf(err.Error())
	}
	tlsConfig := api.NewTLSConfig(certPool)
	tlsConfig.ServerName = "juju-apiserver"
	tlsConfig.Certificates = []tls.Certificate{*coretesting.ServerTLSCert}
	mux := apiserverhttp.NewMux()
	httpServer := &httptest.Server{
		Listener: listener,
		Config:   &http.Server{Handler: mux},
		TLS:      tlsConfig,
	}

	cfg.Mux = mux
	cfg.StatePool = statePool

	if cfg.LocalMacaroonAuthenticator == nil {
		authenticator, err := stateauthenticator.NewAuthenticator(statePool, cfg.Clock)
		c.Assert(err, jc.ErrorIsNil)
		cfg.LocalMacaroonAuthenticator = authenticator
	}

	if cfg.MetricsCollector == nil {
		cfg.MetricsCollector = apiserver.NewMetricsCollector()
	}

	srv, err := apiserver.NewServer(cfg)
	c.Assert(err, jc.ErrorIsNil)
	httpServer.StartTLS()

	return &Server{
		APIServer:  srv,
		HTTPServer: httpServer,
		Info: &api.Info{
			Addrs:  []string{fmt.Sprintf("localhost:%d", listener.Addr().(*net.TCPAddr).Port)},
			CACert: coretesting.CACert,
		},
	}
}