Esempio n. 1
0
func main() {
	var configPath string

	flag.StringVar(&configPath, "c", "config.json", "Path to config file")
	flag.Parse()
	flag.Visit(func(v *flag.Flag) {
		fmt.Printf("%s - %s: %s\n", v.Usage, v.Name, v.Value)
	})

	config := libs.NewConfigFile(configPath)

	app := libs.NewApp(config)
	app.UseStaticRouter("./static/")
	app.UseRouter("/", &routes.Index{})
	app.UseRouter("/api", &routes.Api{})
	app.Run()
}
Esempio n. 2
0
func TestEnvConfig(t *testing.T) {
	fixture := `{"env":"development"}`

	config, err := ioutil.TempFile("", "tetris-config")
	require.Nil(t, err)
	defer os.Remove(config.Name())

	_, err = config.WriteString(fixture)
	require.Nil(t, err)
	err = config.Close()
	require.Nil(t, err)

	os.Setenv("ENV_TETRIS_ENV", "testing")
	os.Setenv("ENV_TETRIS_GITHUB_TOKEN", "testToken")

	conf := libs.NewConfigFile(config.Name())

	assert.Equal(t, "testing", conf.Env)
	assert.Equal(t, "testToken", conf.Github.Token)
}
Esempio n. 3
0
func TestValidConfigFile(t *testing.T) {
	fixtures := []string{
		`{}`,
		`{"env":""}`,
		`{"env":"testing"}`,
		`{"listen":{}}`,
		`{"github":{}}`,
		`{"template":{}}`,
		`{"listen":{"address":"localhost:1234"}}`,
		`{"github":{"token":"xxxxxxxxxx"}}`,
		`{"github":{"username":"******"}}`,
		`{"template":{"path":"../"}}`,
	}

	for testn, fixture := range fixtures {
		func() {
			// Setup
			config, err := ioutil.TempFile("", "tetris-config")
			require.Nil(t, err)
			if os.Getenv("TEST_PRESERVE") == "" {
				defer os.Remove(config.Name())
			}

			_, err = config.WriteString(fixture)
			require.Nil(t, err)
			err = config.Close()
			require.Nil(t, err)

			// Verification
			var conf *libs.Config

			assert.NotPanics(t, func() {
				conf = libs.NewConfigFile(config.Name())
			}, "[%d:%s] parse errors", testn, fixture)
			assert.NotNil(t, conf, "[%d:%s] invalid config", testn, fixture)
		}()
	}
}