2017-04-07 11:56:28 +02:00
|
|
|
package runtime
|
2017-04-04 07:46:09 +02:00
|
|
|
|
|
|
|
import (
|
2017-04-07 11:32:49 +02:00
|
|
|
"net/http"
|
2017-04-04 07:46:09 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProductExists(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2017-04-04 08:18:58 +02:00
|
|
|
|
2017-04-07 13:13:37 +02:00
|
|
|
ProductURL = "http://localhost:8080/api-test/product/%d/"
|
2017-04-07 11:32:49 +02:00
|
|
|
router := http.FileServer(http.Dir("../webroot"))
|
|
|
|
srv := &http.Server{
|
|
|
|
Addr: ":8080",
|
|
|
|
Handler: router,
|
|
|
|
}
|
|
|
|
go srv.ListenAndServe()
|
|
|
|
|
2017-04-07 13:13:37 +02:00
|
|
|
ok, err := ProductExists(3)
|
2017-04-04 08:18:58 +02:00
|
|
|
assert.True(ok)
|
|
|
|
assert.NoError(err)
|
2017-04-04 07:46:09 +02:00
|
|
|
|
2017-04-04 08:18:58 +02:00
|
|
|
// test cache
|
2017-04-07 13:13:37 +02:00
|
|
|
ok, err = ProductExists(3)
|
2017-04-04 07:46:09 +02:00
|
|
|
assert.True(ok)
|
|
|
|
assert.NoError(err)
|
2017-04-04 08:18:58 +02:00
|
|
|
|
2017-04-07 13:13:37 +02:00
|
|
|
productExistCache = make(map[int64]boolMicroServiceCache)
|
|
|
|
ProductURL = "http://localhost:8081/api-test/product/%d/"
|
|
|
|
|
|
|
|
ok, err = ProductExists(3)
|
|
|
|
assert.Error(err)
|
2017-04-07 11:32:49 +02:00
|
|
|
|
|
|
|
srv.Close()
|
2017-04-04 07:46:09 +02:00
|
|
|
}
|