Ejemplo n.º 1
0
func TestBadImportCountries(t *testing.T) {
	conn, err := transaction.CreateConnection()
	if err != nil {
		t.Errorf("Connection creation failed, err: %v", err)
	}

	var countries model.YAMLCountries
	path, _ := filepath.Abs("../fake_data/bad_countries.yml")
	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		t.Errorf("Error during the reading of the YAML, err: %v", err)
	}

	err = yaml.Unmarshal(yamlFile, &countries)
	if err != nil {
		t.Errorf("Error during the reading of the YAML file, err: %v", err)
	}

	err = importCountries(conn, countries)
	if err == nil {
		t.Error("The import should fails with missing country and translation")
	}

	conn.Finish(err)
}
Ejemplo n.º 2
0
func TestGoodImportPhoneNumbersCategories(t *testing.T) {
	conn, err := transaction.CreateConnection()
	if err != nil {
		t.Errorf("Connection creation failed, err: %v", err)
	}

	var categories model.YAMLPhoneNumbersCategories
	path, _ := filepath.Abs("../fake_data/good_phone_numbers_categories.yml")
	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		t.Errorf("Error during the reading of the YAML, err: %v", err)
	}

	err = yaml.Unmarshal(yamlFile, &categories)
	if err != nil {
		t.Errorf("Error during the reading of the YAML file, err: %v", err)
	}

	err = importPhoneNumbersCategories(conn, categories)
	if err != nil {
		t.Errorf("The import should be ok, err: %v", err)
	}

	conn.Finish(err)
}
Ejemplo n.º 3
0
func TestBadImportPhoneNumbers(t *testing.T) {
	conn, err := transaction.CreateConnection()
	if err != nil {
		t.Errorf("Connection creation failed, err: %v", err)
	}

	var phonenumbers model.YAMLPhoneNumbers
	path, _ := filepath.Abs("../fake_data/bad_phone_numbers.yml")
	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		t.Errorf("Error during the reading of the YAML, err: %v", err)
	}

	err = yaml.Unmarshal(yamlFile, &phonenumbers)
	if err != nil {
		t.Errorf("Error during the reading of the YAML file, err: %v", err)
	}

	err = importPhoneNumbers(conn, phonenumbers)
	if err == nil {
		t.Error("The import should fails with missing country and category")
	}

	conn.Finish(err)
}
Ejemplo n.º 4
0
// IsDatabaseEmpty will return if the database has no
// initial data inside that should be provided by the importer
func IsDatabaseEmpty() (bool, error) {
	conn, err := transaction.CreateConnection()
	if err != nil {
		log.Info("Error in database connection")
		return false, err
	}
	defer conn.Finish(nil)

	return conn.IsDatabaseEmpty()
}
Ejemplo n.º 5
0
// Refresh will launch the process of updating the database
func Refresh() {
	log.Info("Refresh started")
	conn, err := transaction.CreateConnection()

	if err != nil {
		log.Info("Error in database connection")
		return
	}

	defer conn.Finish(err)

	path, _ := filepath.Abs("/etc/data/countries.yml")
	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		return
	}

	var countries model.YAMLCountries
	err = yaml.Unmarshal(yamlFile, &countries)
	if err != nil {
		return
	}

	if err = importCountries(conn, countries); err != nil {
		log.Infof("Error in import of countries, err: %v", err)
		return
	}

	path, _ = filepath.Abs("/etc/data/phone_numbers_categories.yml")
	yamlFile, err = ioutil.ReadFile(path)
	if err != nil {
		return
	}

	var categories model.YAMLPhoneNumbersCategories
	err = yaml.Unmarshal(yamlFile, &categories)
	if err != nil {
		return
	}

	if err = importPhoneNumbersCategories(conn, categories); err != nil {
		log.Infof("Error in import of categories, err: %v", err)
		return
	}

	path, _ = filepath.Abs("/etc/data/phone_numbers.yml")
	yamlFile, err = ioutil.ReadFile(path)
	if err != nil {
		return
	}

	var phonenumbers model.YAMLPhoneNumbers
	err = yaml.Unmarshal(yamlFile, &phonenumbers)
	if err != nil {
		return
	}

	if err = importPhoneNumbers(conn, phonenumbers); err != nil {
		log.Infof("Error in import of phonenumbers, err: %v", err)
		return
	}
	log.Info("Refresh finished")
}