2017-05-03 08:02:29 +02:00
|
|
|
// Package with supporting functionality to run the microservice
|
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"
|
|
|
|
|
2017-05-18 00:34:26 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/test"
|
2017-04-04 07:46:09 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-05-03 08:02:29 +02:00
|
|
|
// Function to test, if and which products exist (get information from the products catalogue)
|
2017-04-04 07:46:09 +02:00
|
|
|
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"))
|
2017-05-18 00:34:26 +02:00
|
|
|
mock := test.MockTransport{Handler: router}
|
|
|
|
http.DefaultClient.Transport = &mock
|
|
|
|
mock.Start()
|
2017-04-07 11:32:49 +02:00
|
|
|
|
2017-05-05 10:56:03 +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-05-05 10:56:03 +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-05-18 00:34:26 +02:00
|
|
|
mock.Close()
|
2017-04-07 13:13:37 +02:00
|
|
|
productExistCache = make(map[int64]boolMicroServiceCache)
|
|
|
|
|
2017-05-05 10:56:03 +02:00
|
|
|
ok, err = ProductExists(3)
|
2017-04-07 13:13:37 +02:00
|
|
|
assert.Error(err)
|
2017-04-07 11:32:49 +02:00
|
|
|
|
2017-04-04 07:46:09 +02:00
|
|
|
}
|