38 lines
688 B
Go
38 lines
688 B
Go
package runtime
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestProductExists(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
ProductURL = "http://localhost:8080/api-test/product/%d/"
|
|
router := http.FileServer(http.Dir("../webroot"))
|
|
srv := &http.Server{
|
|
Addr: ":8080",
|
|
Handler: router,
|
|
}
|
|
go srv.ListenAndServe()
|
|
|
|
ok, err := ProductExists(3)
|
|
assert.True(ok)
|
|
assert.NoError(err)
|
|
|
|
// test cache
|
|
ok, err = ProductExists(3)
|
|
assert.True(ok)
|
|
assert.NoError(err)
|
|
|
|
productExistCache = make(map[int64]boolMicroServiceCache)
|
|
ProductURL = "http://localhost:8081/api-test/product/%d/"
|
|
|
|
ok, err = ProductExists(3)
|
|
assert.Error(err)
|
|
|
|
srv.Close()
|
|
}
|