Пример #1
0
func TestConvertToJson(t *testing.T) {
	fmt.Println("TestConvertToJson...")
	dtsource := MockDataSource{}
	conv := converter.Converter{DataSource: dtsource}
	xmlRecord, _ := conv.GetXmlRecord(countryName)
	jsonStr, _ := conv.ConvertToJson(xmlRecord)
	if string(jsonStr) != belarusCitiesJson {
		t.Error("Expected "+belarusCitiesJson+", got ", jsonStr)
	}
}
Пример #2
0
func TestGetXml(t *testing.T) {
	fmt.Println("TestGetXml...")
	dtsource := MockDataSource{}
	conv := converter.Converter{DataSource: dtsource}

	xmlStr, _ := conv.GetXml(countryName)

	if xmlStr != belarusCitiesXml {
		t.Error("Expected "+belarusCitiesXml+", got ", xmlStr)
	}

}
Пример #3
0
func TestGetXmlRecord(t *testing.T) {
	fmt.Println("TestGetXmlRecord...")
	xmlRecord0 := converter.XmlRecord{}
	xml.Unmarshal([]byte(belarusCitiesXml), &xmlRecord0)

	dtsource := MockDataSource{}
	conv := converter.Converter{DataSource: dtsource}

	xmlRecord1, _ := conv.GetXmlRecord(countryName)
	if !xmlRecord0.Equals(xmlRecord1) {
		t.Error("XmlRecords mismatch.")
	}
}
Пример #4
0
func TestGetCities(t *testing.T) {
	fmt.Println("TestGetCities...")
	dtsource := MockDataSource{}
	conv := converter.Converter{DataSource: dtsource}

	var msgs = make(chan string)
	var wg sync.WaitGroup

	wg.Add(1)
	go conv.GetCities(countryName, msgs, &wg)

	message := <-msgs
	fmt.Println("Message: ", message)
	if message != belarusCitiesJson {
		t.Error("Expected "+belarusCitiesJson+", got ", message)
	}
	wg.Wait()
}
Пример #5
0
func main() {
	conf := config.ReadConfig()
	dtsource := datasource.GetDataSource{Url: conf.Url}
	conv := converter.Converter{DataSource: dtsource}
	fileLogger := logger.FileLogger{LogFileName: conf.LogFileNane}

	countries := os.Args[1:]

	var msgs = make(chan string, len(countries))
	var wg sync.WaitGroup

	for _, country := range countries {
		wg.Add(1)
		go conv.GetCities(country, msgs, &wg)
	}

	wg.Add(1)
	go fileLogger.Log(len(countries), msgs, &wg)
	wg.Wait()

	fmt.Println("main finished")
}