* finally remove utils.Cfg

* fix compile error

* another test compilation fix
Этот коммит содержится в:
Chris
2018-01-17 12:38:37 -06:00
коммит произвёл Harrison Healey
родитель dce0616305
Коммит 4e6cc846a6
20 изменённых файлов: 157 добавлений и 153 удалений

Просмотреть файл

@@ -5,6 +5,8 @@ package api
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
@@ -24,7 +26,7 @@ import (
type TestHelper struct {
App *app.App
originalConfig *model.Config
tempConfigPath string
BasicClient *model.Client
BasicTeam *model.Team
@@ -64,7 +66,22 @@ func StopTestStore() {
}
func setupTestHelper(enterprise bool) *TestHelper {
options := []app.Option{app.DisableConfigWatch}
permConfig, err := os.Open(utils.FindConfigFile("config.json"))
if err != nil {
panic(err)
}
defer permConfig.Close()
tempConfig, err := ioutil.TempFile("", "")
if err != nil {
panic(err)
}
_, err = io.Copy(tempConfig, permConfig)
tempConfig.Close()
if err != nil {
panic(err)
}
options := []app.Option{app.ConfigFile(tempConfig.Name()), app.DisableConfigWatch}
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
}
@@ -75,9 +92,9 @@ func setupTestHelper(enterprise bool) *TestHelper {
}
th := &TestHelper{
App: a,
App: a,
tempConfigPath: tempConfig.Name(),
}
th.originalConfig = th.App.Config().Clone()
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.TeamSettings.MaxUsersPerTeam = 50
@@ -176,7 +193,7 @@ func (me *TestHelper) CreateTeam(client *model.Client) *model.Team {
team := &model.Team{
DisplayName: "dn_" + id,
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Type: model.TEAM_OPEN,
}
@@ -190,7 +207,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
id := model.NewId()
user := &model.User{
Email: GenerateTestEmail(),
Email: me.GenerateTestEmail(),
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
@@ -353,8 +370,8 @@ func (me *TestHelper) LoginSystemAdmin() {
utils.EnableDebugLogForTest()
}
func GenerateTestEmail() string {
if utils.Cfg.EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
func (me *TestHelper) GenerateTestEmail() string {
if me.App.Config().EmailSettings.SMTPServer != "dockerhost" && os.Getenv("CI_INBUCKET_PORT") == "" {
return strings.ToLower("success+" + model.NewId() + "@simulator.amazonses.com")
}
return strings.ToLower(model.NewId() + "@dockerhost")
@@ -365,11 +382,8 @@ func GenerateTestTeamName() string {
}
func (me *TestHelper) TearDown() {
me.App.UpdateConfig(func(cfg *model.Config) {
*cfg = *me.originalConfig
})
me.App.Shutdown()
os.Remove(me.tempConfigPath)
if err := recover(); err != nil {
StopTestStore()
panic(err)

Просмотреть файл

@@ -88,8 +88,6 @@ func TestOAuthRegisterApp(t *testing.T) {
t.Fatal("should have failed. not enough permissions")
}
adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
th.LoginBasic()
@@ -741,9 +739,6 @@ func TestOAuthComplete(t *testing.T) {
// We are going to use mattermost as the provider emulating gitlab
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOAuthServiceProvider = true })
adminOnly := *th.App.Config().ServiceSettings.EnableOnlyAdminIntegrations
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = false })
oauthApp := &model.OAuthApp{

Просмотреть файл

@@ -66,7 +66,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
@@ -84,7 +84,7 @@ func TestCreateTeamSanitization(t *testing.T) {
team := &model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}
@@ -304,7 +304,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
@@ -317,7 +317,7 @@ func TestGetAllTeamsSanitization(t *testing.T) {
if res, err := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
@@ -418,7 +418,7 @@ func TestGetAllTeamListingsSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
@@ -432,7 +432,7 @@ func TestGetAllTeamListingsSanitization(t *testing.T) {
if res, err := th.SystemAdminClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_2",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
AllowOpenInvite: true,
@@ -665,7 +665,7 @@ func TestUpdateTeamSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
@@ -772,7 +772,7 @@ func TestGetMyTeamSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {
@@ -1192,7 +1192,7 @@ func TestGetTeamByNameSanitization(t *testing.T) {
if res, err := th.BasicClient.CreateTeam(&model.Team{
DisplayName: t.Name() + "_1",
Name: GenerateTestTeamName(),
Email: GenerateTestEmail(),
Email: th.GenerateTestEmail(),
Type: model.TEAM_OPEN,
AllowedDomains: "simulator.amazonses.com",
}); err != nil {