Beispiel #1
0
func spawnServer() error {
	config.RuntimeConfig = new(config.Config)
	config.RuntimeConfig.Port = 3396
	config.RuntimeConfig.Debug = false
	config.RuntimeConfig.Driver = "sqlite3"
	config.RuntimeConfig.ConnectionString = ":memory:"
	if os.Getenv("IS_TRAVIS") == "YES" {
		config.RuntimeConfig.SSHPublicKeyPath = "/home/travis/gopath/src/github.com/vodolaz095/gossha/test/gossha_test.pub"
		config.RuntimeConfig.SSHPrivateKeyPath = "/home/travis/gopath/src/github.com/vodolaz095/gossha/test/gossha_test"
	} else {
		config.RuntimeConfig.SSHPublicKeyPath, _ = config.GetPublicKeyPath()
		config.RuntimeConfig.SSHPrivateKeyPath, _ = config.GetPrivateKeyPath()
	}

	config.RuntimeConfig.Homedir, _ = config.GetHomeDir()
	config.RuntimeConfig.ExecuteOnMessage = ""
	config.RuntimeConfig.ExecuteOnPrivateMessage = ""
	err := models.InitDatabase("sqlite3", ":memory:", true)
	if err != nil {
		return err
	}
	err = models.CreateUser("a", "a", false)
	if err != nil {
		return err
	}
	err = models.CreateUser("b", "b", false)
	if err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func main() {
	defer func() {
		err := recover()
		if err != nil {
			trace := make([]byte, 1024)
			count := runtime.Stack(trace, true)
			fmt.Println("====================================================")
			fmt.Println("Error! Error! Error!")
			fmt.Printf("Version: %v\n", version.Version)
			fmt.Printf("Recover from panic: %s\n", err)
			fmt.Printf("Stack of %d bytes:\n %s\n", count, trace)
			fmt.Println("====================================================")
			fmt.Println("Please, report this error on `https://github.com/vodolaz095/gossha/issues` !\nThanks!")
		}
	}()

	cfg, err := config.InitConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error while creating config file: %s \n", err))
	}

	err = models.InitDatabase(cfg.Driver, cfg.ConnectionString, cfg.Debug)
	if err != nil {
		panic(fmt.Errorf("Fatal error while initializing database: %s \n", err))
	}
	cli.ProcessConsoleCommand()
}
Beispiel #3
0
func TestSqlite3InitDatabase(t *testing.T) {
	err := models.InitDatabase("sqlite3", ":memory:", true)
	if err != nil {
		t.Error(err.Error())
	}
	err = models.CreateUser("testUser", "testPassword", false)
	if err != nil {
		t.Error(err.Error())
	}
}