-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(test): Setup test environment for executor #20
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
06e7912
Set up integration test configuration in build.sbt
mvelimir 44535e9
Set up a Docker test container
mvelimir 1968fbc
Add LiveSpec
mvelimir c337e96
Add integration tests to CI workflow
mvelimir 50b7432
Add tests for getting by id
dbulaja98 9965bf1
Set up integration test configuration in build.sbt
mvelimir 8f32f0e
Set up a Docker test container
mvelimir 51b8d85
Add LiveSpec
mvelimir 78e8ddc
Add integration tests to CI workflow
mvelimir 8af319c
Add tests for getting by id
dbulaja98 42469c9
Generate document ID for every test
mvelimir 408858f
Correctly specify location in docker compose
mvelimir e88f1d4
Merge changes
mvelimir f92913c
Transfer docker-compose.yml to root
dbulaja98 e071286
Fix code remarks
dbulaja98 e4c032d
Fix ci.yml
dbulaja98 10de585
Fix IndexName validation
dbulaja98 89605eb
Fix IndexName validation
dbulaja98 cbcf979
Fix IndexName validation
dbulaja98 044ec5b
Revert changes on IndexName validation
dbulaja98 110a38b
Add environment to es in docker-compose.yml
dbulaja98 4e62eb6
Fix code remarks
dbulaja98 ebe10bc
Fix IndexName validation
dbulaja98 89e794f
Fix IndexName validation
dbulaja98 75fcedd
Refactor tests
dbulaja98 90f3297
Fix code remarks
dbulaja98 5174e25
Refactor tests
dbulaja98 cdb6b3f
Fix code remarks
dbulaja98 56df2f3
Refactor IntegrationSpec
dbulaja98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.8' | ||
|
||
services: | ||
elasticsearch: | ||
image: elasticsearch:7.17.6 | ||
container_name: zio-elasticsearch-test | ||
ports: | ||
- "9200:9200" | ||
environment: | ||
discovery.type: "single-node" | ||
xpack.security.enabled: "false" | ||
ES_JAVA_OPTS: "-Xms512m -Xmx512m" |
42 changes: 42 additions & 0 deletions
42
modules/library/src/it/scala/zio/elasticsearch/HttpExecutorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package zio.elasticsearch | ||
|
||
import zio.elasticsearch.ElasticError.DocumentRetrievingError.{DecoderError, DocumentNotFound} | ||
import zio.test.Assertion.equalTo | ||
import zio.test.TestAspect.nondeterministic | ||
import zio.test._ | ||
|
||
object HttpExecutorSpec extends IntegrationSpec { | ||
|
||
override def spec: Spec[TestEnvironment, Any] = | ||
suite("HTTP Executor")( | ||
suite("retrieving document by ID")( | ||
test("successfully return document") { | ||
checkOnce(genDocumentId, genCustomer) { (documentId, customer) => | ||
val result = for { | ||
_ <- ElasticRequest.upsert[CustomerDocument](index, documentId, customer).execute | ||
document <- ElasticRequest.getById[CustomerDocument](index, documentId).execute | ||
} yield document | ||
|
||
assertZIO(result)(Assertion.isRight(equalTo(customer))) | ||
} | ||
}, | ||
test("return DocumentNotFound if the document does not exist") { | ||
checkOnce(genDocumentId) { documentId => | ||
assertZIO(ElasticRequest.getById[CustomerDocument](index, documentId).execute)( | ||
Assertion.isLeft(equalTo(DocumentNotFound)) | ||
) | ||
} | ||
}, | ||
test("fail with decoding error") { | ||
checkOnce(genDocumentId, genEmployee) { (documentId, employee) => | ||
val result = for { | ||
_ <- ElasticRequest.upsert[EmployeeDocument](index, documentId, employee).execute | ||
document <- ElasticRequest.getById[CustomerDocument](index, documentId).execute | ||
} yield document | ||
|
||
assertZIO(result)(Assertion.isLeft(equalTo(DecoderError(".address(missing)")))) | ||
} | ||
} | ||
) @@ nondeterministic | ||
).provideShared(elasticsearchLayer) | ||
} |
30 changes: 30 additions & 0 deletions
30
modules/library/src/it/scala/zio/elasticsearch/IntegrationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package zio.elasticsearch | ||
|
||
import sttp.client3.httpclient.zio.HttpClientZioBackend | ||
import zio.ZLayer | ||
import zio.test.CheckVariants.CheckN | ||
import zio.test.{Gen, ZIOSpecDefault, checkN} | ||
|
||
trait IntegrationSpec extends ZIOSpecDefault { | ||
val elasticsearchLayer: ZLayer[Any, Throwable, ElasticExecutor] = | ||
HttpClientZioBackend.layer() >>> ElasticExecutor.local | ||
|
||
val index: IndexName = IndexName("users") | ||
|
||
def genDocumentId: Gen[Any, DocumentId] = Gen.stringBounded(10, 40)(Gen.alphaNumericChar).map(DocumentId(_)) | ||
|
||
def genCustomer: Gen[Any, CustomerDocument] = for { | ||
id <- Gen.stringBounded(5, 10)(Gen.alphaNumericChar) | ||
name <- Gen.stringBounded(5, 10)(Gen.alphaChar) | ||
address <- Gen.stringBounded(5, 10)(Gen.alphaNumericChar) | ||
balance <- Gen.bigDecimal(100, 10000) | ||
} yield CustomerDocument(id = id, name = name, address = address, balance = balance) | ||
|
||
def genEmployee: Gen[Any, EmployeeDocument] = for { | ||
id <- Gen.stringBounded(5, 10)(Gen.alphaNumericChar) | ||
name <- Gen.stringBounded(5, 10)(Gen.alphaChar) | ||
degree <- Gen.stringBounded(5, 10)(Gen.alphaChar) | ||
} yield EmployeeDocument(id = id, name = name, degree = degree) | ||
|
||
def checkOnce: CheckN = checkN(1) | ||
} |
15 changes: 15 additions & 0 deletions
15
modules/library/src/it/scala/zio/elasticsearch/UserDocument.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package zio.elasticsearch | ||
|
||
import zio.schema.{DeriveSchema, Schema} | ||
|
||
final case class CustomerDocument(id: String, name: String, address: String, balance: BigDecimal) | ||
|
||
final case class EmployeeDocument(id: String, name: String, degree: String) | ||
|
||
object CustomerDocument { | ||
implicit val schema: Schema[CustomerDocument] = DeriveSchema.gen[CustomerDocument] | ||
} | ||
|
||
object EmployeeDocument { | ||
implicit val schema: Schema[EmployeeDocument] = DeriveSchema.gen[EmployeeDocument] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how it's organized, is there any chance to run test container only along with integration tests?