package controllers import ( "bytes" "encoding/json" "fmt" "net/http" "net/http/httptest" "os" "testing" "github.com/gorilla/handlers" "github.com/gophish/gophish/config" "github.com/gophish/gophish/models" "github.com/stretchr/testify/suite" ) // ControllersSuite is a suite of tests to cover API related functions type ControllersSuite struct { suite.Suite ApiKey string } // as is the Admin Server for our API calls var as *httptest.Server = httptest.NewUnstartedServer(handlers.CombinedLoggingHandler(os.Stdout, CreateAdminRouter())) func (s *ControllersSuite) SetupSuite() { config.Conf.DBPath = ":memory:" err := models.Setup() if err != nil { s.T().Fatalf("Failed creating database: %v", err) } s.Nil(err) // Setup the admin server for use in testing as.Config.Addr = config.Conf.AdminURL as.Start() // Get the API key to use for these tests u, err := models.GetUser(1) s.Nil(err) s.ApiKey = u.ApiKey } func (s *ControllersSuite) TestSiteImportBaseHref() { h := "
" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, h) })) hr := fmt.Sprintf("