Exemple #1
0
func main() {
	opts := &command.Options{
		Options: &commonOptions{},
		Func: func(_ *command.Cmd, opts *command.Options) error {
			copts := opts.Options.(*commonOptions)
			if copts.Quiet {
				log.SetLevel(log.LError)
			} else {
				log.SetLevel(log.LDebug)
			}
			return nil
		},
	}
	command.Exit(command.RunOpts(nil, opts, commands))
}
Exemple #2
0
func newOrm(t testing.TB, url string, logging bool) *Orm {
	clearRegistry(nil)
	o, err := New(config.MustParseURL(url))
	if err != nil {
		t.Fatal(err)
	}
	if logging {
		// Set logger
		o.SetLogger(log.Std)
		if testing.Verbose() && os.Getenv("ORM_TEST_DEBUG") != "" {
			log.SetLevel(log.LDebug)
		}
	} else {
		log.SetLevel(log.LInfo)
	}
	return o
}
Exemple #3
0
func testCache(t *testing.T, url string) {
	if testing.Verbose() {
		log.SetLevel(log.LDebug)
	}
	c, err := newCache(url)
	if err != nil {
		t.Fatal(err)
	}
	for _, v := range tests {
		v(t, c)
	}
}
Exemple #4
0
func benchmarkCache(b *testing.B, config string) {
	c, err := newCache(config)
	if err != nil {
		b.Fatal(err)
	}
	log.SetLevel(log.LInfo)
	b.ResetTimer()
	for ii := 0; ii < b.N; ii++ {
		for _, v := range benchmarks {
			v(b, c)
		}
	}
}
Exemple #5
0
func devCommand(args *command.Args, opts *devOptions) error {
	if !opts.Verbose {
		log.SetLevel(log.LInfo)
	}
	dir := opts.Dir
	if dir == "" {
		dir = "."
	}
	path, err := filepath.Abs(dir)
	if err != nil {
		return err
	}
	configPath := findConfig(dir, opts.Config)
	if configPath == "" {
		name := opts.Config
		if name == "" {
			name = fmt.Sprintf("(tried %s)", strings.Join(autoConfigNames(), ", "))
		}
		log.Panicf("can't find configuration file %s in %s", name, dir)
	}
	log.Infof("Using config file %s", configPath)
	p := NewProject(path, configPath)
	p.port = opts.Port
	p.tags = opts.Tags
	p.goFlags = opts.GoFlags
	p.noDebug = opts.NoDebug
	p.noCache = opts.NoCache
	p.profile = opts.Profile
	go p.Build()
	log.Infof("Starting Gondola development server on port %d (press Control+C to exit)", p.port)
	if !opts.NoBrowser {
		time.AfterFunc(time.Second, func() {
			host := "localhost"
			if sshConn := os.Getenv("SSH_CONNECTION"); sshConn != "" {
				parts := strings.Split(sshConn, " ")
				// e.g. SSH_CONNECTION="10.211.55.2 56989 10.211.55.8 22"
				if len(parts) == 4 {
					if net.ParseIP(parts[2]) != nil {
						host = parts[2]
					}
				}
			}
			url := fmt.Sprintf("http://%s:%d", host, p.App.Config().Port)
			if err := browser.Open(url); err != nil {
				log.Errorf("error opening browser: open %s manually (error was %s)", url, err)
			}
		})
	}
	p.Listen()
	return nil
}
func openTestFileWriter(t *testing.T) (*fileWriter, string) {
	if testing.Verbose() {
		log.SetLevel(log.LDebug)
	}
	dir, err := ioutil.TempDir("", "filewriter")
	if err != nil {
		t.Fatal(err)
	}
	w := &fileWriter{dir: dir, maxSize: 128, count: 3, waitCompress: true}
	if err := w.Open("test"); err != nil {
		os.RemoveAll(dir)
		t.Fatal(err)
	}
	return w, dir
}
Exemple #7
0
func prepareGovernatorTest(t testing.TB) *Governator {
	if testing.Verbose() {
		log.SetLevel(log.LDebug)
	}
	g, err := NewGovernator("")
	if err != nil {
		t.Fatal(err)
	}
	go func() {
		if err := g.Run(); err != nil {
			t.Fatal("error running goernator: %s", err)
		}
	}()
	return g
}
Exemple #8
0
func TestExtract(t *testing.T) {
	if testing.Verbose() {
		log.SetLevel(log.LDebug)
	}
	m, err := Extract("_test_data", DefaultExtractOptions())
	if err != nil {
		t.Error(err)
	}
	var buf bytes.Buffer
	if err := Write(&buf, m); err != nil {
		t.Error(err)
	}
	t.Logf("Messages:\n%s", string(buf.Bytes()))
	b, err := ioutil.ReadFile(filepath.Join("_test_data", "test.pot"))
	if err != nil {
		t.Error(err)
	}
	if len(b) != len(buf.Bytes()) || bytes.Compare(b, buf.Bytes()) != 0 {
		t.Errorf("invalid messages (expected %d bytes - got %d)", len(b), len(buf.Bytes()))
	}
	if *output != "" {
		ioutil.WriteFile(*output, buf.Bytes(), 0644)
	}
}
Exemple #9
0
func main() {
	var (
		daemon       = flag.Bool("D", false, "Run in daemon mode")
		debug        = flag.Bool("d", false, "Enable debug logging")
		testConfig   = flag.Bool("t", false, "Test configuration files")
		configDir    = flag.String("c", defaultConfigDir, "Configuration directory")
		serverAddr   = flag.String("daemon", "unix://"+socketPath, "Daemon URL to listen on in daemon mode or to connect to in client mode")
		printVersion = flag.Bool("V", false, "Print version and exit")
	)
	flag.Parse()
	if *debug {
		log.SetLevel(log.LDebug)
	}
	switch {
	case *printVersion:
		fmt.Println(governatorVersion, gitVersion)
	case *testConfig:
		g, err := NewGovernator(*configDir)
		if err != nil {
			die(fmt.Errorf("error initializing daemon: %s", err))
		}
		testConfigurations(g)
	case *daemon:
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, os.Signal(syscall.SIGTERM), os.Kill)
		if os.Geteuid() != 0 {
			die(errors.New("govenator daemon must be run as root"))
		}
		g, err := NewGovernator(*configDir)
		if err != nil {
			die(fmt.Errorf("error initializing daemon: %s", err))
		}
		g.ServerAddr = *serverAddr
		if err := g.LoadServices(); err != nil {
			die(fmt.Errorf("error loading services: %s", err))
		}
		go func() {
			// Wait for signal
			<-c
			g.StopRunning()
		}()
		if err := g.Run(); err != nil {
			die(fmt.Errorf("error starting daemon: %s", err))
		}
	default:
		ok, err := clientMain(*serverAddr, flag.Args())
		if err != nil {
			if oe, ok := err.(*net.OpError); ok {
				switch {
				case oe.Err == syscall.EACCES:
					fmt.Fprint(os.Stderr, "can't connect to governator, permission denied\n")
					os.Exit(1)
				case oe.Err == syscall.ENOENT:
					fmt.Fprint(os.Stderr, "governator daemon is not running\n")
					os.Exit(1)
				}
			}
			fmt.Fprintf(os.Stderr, "error running client: %s\n", err)
			os.Exit(1)
		}
		if !ok {
			os.Exit(1)
		}
	}
}