Пример #1
0
func LoadBagValidationConfig(pathToConfigFile string) (*BagValidationConfig, []error) {
	errors := make([]error, 0)
	file, err := fileutil.LoadRelativeFile(pathToConfigFile)
	if err != nil {
		detailedError := fmt.Errorf(
			"Error reading bag validation config file '%s': %v\n",
			pathToConfigFile, err)
		errors = append(errors, detailedError)
		return nil, errors
	}
	bagValidationConfig := NewBagValidationConfig()
	err = json.Unmarshal(file, bagValidationConfig)
	if err != nil {
		detailedError := fmt.Errorf(
			"Error parsing JSON from bag validation config file '%s': %v",
			pathToConfigFile, err)
		errors = append(errors, detailedError)
		return nil, errors
	}
	configErrors := bagValidationConfig.ValidateConfig()
	regexErr := bagValidationConfig.CompileFileNameRegex()
	if regexErr != nil {
		configErrors = append(configErrors, regexErr)
	}
	return bagValidationConfig, configErrors
}
Пример #2
0
func TestLoadRelativeFile(t *testing.T) {
	path := filepath.Join("testdata", "json_objects", "ingest_result.json")
	data, err := fileutil.LoadRelativeFile(path)
	if err != nil {
		t.Error(err)
	}
	if data == nil || len(data) == 0 {
		t.Errorf("Read no data out of file '%s'", path)
	}
}
Пример #3
0
// Loads an IntellectualObject fixture (a JSON file) from
// the testdata directory for testing.
func LoadIntelObjFixture(filename string) (*models.IntellectualObject, error) {
	data, err := fileutil.LoadRelativeFile(filename)
	if err != nil {
		return nil, err
	}
	intelObj := &models.IntellectualObject{}
	err = json.Unmarshal(data, intelObj)
	if err != nil {
		return nil, err
	}
	return intelObj, nil
}
Пример #4
0
// This returns the configuration that the user requested,
// which is specified in the -config flag when we run a
// program from the command line
func LoadConfigFile(pathToConfigFile string) (*Config, error) {
	file, err := fileutil.LoadRelativeFile(pathToConfigFile)
	if err != nil {
		detailedError := fmt.Errorf("Error reading config file '%s': %v\n",
			pathToConfigFile, err)
		return nil, detailedError
	}
	config := &Config{}
	err = json.Unmarshal(file, config)
	if err != nil {
		detailedError := fmt.Errorf("Error parsing JSON from config file '%s': %v",
			pathToConfigFile, err)
		return nil, detailedError
	}
	config.ActiveConfig = pathToConfigFile
	return config, nil
}