Comments (14)
Another workaround, without returning errors:
// Needed as the es client >[email protected] validates whether it is connected to a real ES instance
// by GETting / and checking these fields in the response
esMock.add({ method: "GET", path: "/" }, () => ({
name: "mocked-es-instance",
version: {
number: "7.12.1",
build_flavor: "default",
},
tagline: "You Know, for Search",
}));
from elasticsearch-js-mock.
Workaround for client verification:
mock.add({ method: 'GET', path: '/' }, () => new ResponseError({ statusCode: 401, body: '' }));
from elasticsearch-js-mock.
Updating to @elastic/elasticsearch 7.14.0
make my unit tests failing with that error:
ResponseError: Response Error
at onBody (../node_modules/@elastic/elasticsearch/lib/Transport.js:349:23)
at Class.onEnd (../node_modules/@elastic/elasticsearch/lib/Transport.js:275:11)
at endReadableNT (../node_modules/readable-stream/lib/_stream_readable.js:1010:12)
Still works well with 7.13.0
from elasticsearch-js-mock.
@delvedor I believe I've narrowed it down to the following mock being added in some of our tests (where function is checking an index size as part of its other operations):
mock.add({
method: 'GET',
path: `/*/_stats`
}, () => {
return {
_all: {
total: {
store: {
size_in_bytes: 1000000000
}
}
}
}
});
Previously, this works fine. It seems that now if you have this you also need the explicit hack:
mock.add({ method: "GET", path: "/" }, () => ({
name: "mocked-es-instance",
version: {
number: "7.14.1",
build_flavor: "default",
},
tagline: "You Know, for Search",
}));
Otherwise in our case, @elastic/elasticsearch 7.14.1
will bomb out with the product license error hitting the elasticsearch-mock 0.3.1
values.
Let me know if this is enough to reproduce.
from elasticsearch-js-mock.
I am also getting an error since 7.14.0. ProductNotSupportedError: The client noticed that the server is not Elasticsearch and we do not support this unknown product.
from elasticsearch-js-mock.
Relate to elastic/elasticsearch-js#1487
from elasticsearch-js-mock.
The problem is since elastic-search 7.12.0
from elasticsearch-js-mock.
Another possible hack. This one is not specific to mock and that can be also used to continue to use elasticsearch-js with AWS Elasticsearch
const client = new Client(...);
const productCheckSymbol = Object.getOwnPropertySymbols(client.transport).find(({ description }) => description === 'product check');
if (productCheckSymbol) {
client.transport[productCheckSymbol] = 2;
}
from elasticsearch-js-mock.
I am jumping on this bandwagon and confirming my tests are broken on 7.14.0 and not 7.13.0.
from elasticsearch-js-mock.
Hello! Bug confirmed, thank you for reporting!
I'll work on a fix.
from elasticsearch-js-mock.
Fixed in v0.3.1, please update the client to at least v7.14.1
as well.
from elasticsearch-js-mock.
FYI @delvedor there's some edge case here where this is still broken, I don't know exactly what it is.
90%+ of my tests worked with 0.3.1, but there was some that were still broken.
For some reason, I still end up needing one of the hacks above in some tests.
// ProductNotSupportedError: The client noticed that the server is not Elasticsearch and we do not support this unknown product.
mock.add({ method: "GET", path: "/" }, () => ({
name: "mocked-es-instance",
version: {
number: "7.14.1",
build_flavor: "default",
},
tagline: "You Know, for Search",
}));
It's perhaps related to an issue with nock
or possibly mock.clearAll
in a beforeEach
being used in those tests (which we use for non-es testing). Not sure. Burned a bunch of time on this already.
As an aside, the fact that the product checking wasn't part of a major release was a major disservice to developers. I say this as developers bought into the ES ecosystem, not even pursuing OSS version.
This was exposed for us as an issue with a routine winston-elasticsearch
patch bump, (which included 7.14 es), and exposed cascading dependency failures in our tests, and even after switching the rest of the app to 7.14 (and 0.3.1 of this lib) we still had failures.
from elasticsearch-js-mock.
Hi @seancolyer, can you provide a way to reproduce the bug you are experiencing? It would be really helpful to debug it.
I say this as developers bought into the ES ecosystem, not even pursuing OSS version.
The product check should be transparent if you are using a genuine version of ES, what issue are you facing?
from elasticsearch-js-mock.
It looks like it's an issue in the routing library, until it's fixed the only workaround is what you are doing already. Nice catch!
from elasticsearch-js-mock.
Related Issues (20)
- Ignore deep equal check for params body HOT 1
- Clear mocks HOT 1
- Same request with no data and with data gets the same result even if they don't have same response. HOT 1
- TypeError: Cannot destructure property 'ConfigurationError' of 'errors' as it is undefined. HOT 6
- Mocking a "scroll" search HOT 6
- How to create ResponseErrors in TypeScript HOT 4
- How to mock bulk method HOT 1
- Support for multiple definitions
- how to use with multiple versions ? HOT 2
- Does not work with 8.x version of the client. HOT 1
- ReferenceError: setImmediate is not defined HOT 4
- elastic mocks timeout when used with jest fake timers
- How to use elastic-mock properly? HOT 4
- Upgrading of elasticsearch-mock form v1.0 to v2.0 HOT 1
- How to simulate a delayed response or error?
- High level API around the http mock
- ProductNotSupportedError for elasticsearch-js-mock >=v0.3.1 <=1.0.0 and @elasticsearch/elasticsearch >7.13.0 <= 7.17.0
- How to seperate mocks from implementation?
- Making assertions about how the mock was used HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-js-mock.