Пример #1
0
func configGetterForExampleConfig(path, defaultPath, zone2Path string) config.Getter {
	return func() (*config.Config, error) {
		var examplePath = filepath.Join(path, "config.example.json")
		var cfg, err = config.Parse(examplePath)
		if err != nil {
			return nil, err
		}

		// Create temporary direcotories for the cache zones
		cfg.CacheZones["default"].Path = defaultPath
		cfg.CacheZones["zone2"].Path = zone2Path

		// To make sure no output is emitted during testing
		cfg.Logger.Type = "nillogger"
		return cfg, nil
	}
}
func getConfigGetter(tmpPath string) func() (*config.Config, error) {
	return func() (*config.Config, error) {
		path, err := utils.ProjectPath()
		if err != nil {
			return nil, fmt.Errorf("Was not able to find project path: %s", err)
		}

		cfg, err := config.Parse(filepath.Join(path, "config.example.json"))
		if err != nil {
			return nil, fmt.Errorf("Parsing the example config returned: %s", err)
		}

		for k := range cfg.CacheZones {
			// Fix and create storage paths
			cfg.CacheZones[k].Path = filepath.Join(tmpPath, k)
			if err := os.Mkdir(cfg.CacheZones[k].Path, os.FileMode(0700|os.ModeDir)); err != nil {
				return nil, err
			}
		}

		return cfg, nil
	}
}