Exemplo n.º 1
0
// Not a test
func loadData(t *testing.T) *models.TrainEventList {

	// quickest way
	mockserver.HttpServerDSBTestApi(t, 44444)
	remoteAPI := dsb.NewDSBFacadeWithEndpoint("http://localhost:44444")
	successC, errC := remoteAPI.GetTrains("", "")

	select {
	case response := <-successC:
		return response
	case <-errC:
		return &models.TrainEventList{nil}
	}
}
Exemplo n.º 2
0
func TestStations(t *testing.T) {
	assert := assert.New(t)

	// well behaved DSB API
	mockserver.HttpServerDSBTestApi(t, 7777)

	if req, err := http.NewRequest("GET", "http://localhost:8081/api/v1/stations", nil); err == nil {
		response, _ := http.DefaultClient.Do(req)
		defer response.Body.Close()
		bytes, _ := ioutil.ReadAll(response.Body)
		jsonString := string(bytes)
		prefix := `{"Count":349,"Stations":[{"Id":"8600020","Name":"Aalborg","CountryCode":"DK"}`
		assert.True(strings.HasPrefix(jsonString, prefix), jsonString[:160])
	} else {
		t.Fail()
	}
}
Exemplo n.º 3
0
func TestWithMockRemote(t *testing.T) {
	assert := assert.New(t)

	mockserver.HttpServerDSBTestApi(t, 44444)

	remoteAPI := NewDSBFacadeWithEndpoint("http://localhost:44444")

	successC, errC := remoteAPI.GetStations()

	resultSize := 0

	select {
	case response := <-successC:
		resultSize = len(response.Stations)
	case err := <-errC:
		fmt.Printf("Error %s", err)
	}

	fmt.Printf("Response size %d", resultSize)
	assert.Equal(349, resultSize)
}