/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
I'm cool as heck!
", Discoverable: true, URI: "https://example.org/users/neato_bombeato", URL: "https://example.org/@neato_bombeato", LastWebfingeredAt: time.Now(), InboxURL: "https://example.org/users/neato_bombeato/inbox", OutboxURL: "https://example.org/users/neato_bombeato/outbox", SharedInboxURL: "https://example.org/inbox", FollowersURL: "https://example.org/users/neato_bombeato/followers", FeaturedCollectionURL: "https://example.org/users/neato_bombeato/collections/featured", } suite.testUser = &model.User{ ID: uuid.NewString(), EncryptedPassword: string(encryptedPassword), Email: "user@example.org", AccountID: acctID, } } // SetupTest creates a postgres connection and creates the oauth_clients table before each test func (suite *AccountTestSuite) SetupTest() { log := logrus.New() log.SetLevel(logrus.TraceLevel) db, err := db.New(context.Background(), suite.config, log) if err != nil { logrus.Panicf("error creating database connection: %s", err) } suite.db = db models := []interface{}{ &model.User{}, &model.Account{}, &model.Follow{}, &model.Status{}, } for _, m := range models { if err := suite.db.CreateTable(m); err != nil { logrus.Panicf("db connection error: %s", err) } } if err := suite.db.Put(suite.testAccountLocal); err != nil { logrus.Panicf("could not insert test account into db: %s", err) } if err := suite.db.Put(suite.testUser); err != nil { logrus.Panicf("could not insert test user into db: %s", err) } } // TearDownTest drops the oauth_clients table and closes the pg connection after each test func (suite *AccountTestSuite) TearDownTest() { models := []interface{}{ &model.User{}, &model.Account{}, &model.Follow{}, &model.Status{}, } for _, m := range models { if err := suite.db.DropTable(m); err != nil { logrus.Panicf("error dropping table: %s", err) } } if err := suite.db.Stop(context.Background()); err != nil { logrus.Panicf("error closing db connection: %s", err) } suite.db = nil } func (suite *AccountTestSuite) TestAPIInitialize() { log := logrus.New() log.SetLevel(logrus.TraceLevel) r, err := router.New(suite.config, log) if err != nil { suite.FailNow(fmt.Sprintf("error mapping routes onto router: %s", err)) } r.AttachMiddleware(func(c *gin.Context) { c.Set(oauth.SessionAuthorizedUser, suite.testUser.ID) }) acct := New(suite.config, suite.db) acct.Route(r) r.Start() defer r.Stop(context.Background()) time.Sleep(10 * time.Second) } func TestAccountTestSuite(t *testing.T) { suite.Run(t, new(AccountTestSuite)) }