Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Dec 12, 2023
1 parent 67bd302 commit cbeae49
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class KinesisConfigurationSpec extends Specification {
context = ApplicationContext.run()
then:
context.getBeanDefinitions(KinesisService).size() == 1
context.getBean(KinesisConfiguration).stream == ''
context.getBean(KinesisConfiguration).stream == null
}

void 'configure single service'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ dependencies {
testImplementation project(':micronaut-amazon-awssdk-cloudwatchlogs')
testImplementation 'org.zeroturnaround:zt-zip:1.15'
testImplementation 'com.agorapulse.testing:fixt:0.2.3'

testRuntimeOnly 'org.yaml:snakeyaml'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.zeroturnaround.zip.ZipUtil
import software.amazon.awssdk.core.SdkBytes
import software.amazon.awssdk.services.lambda.LambdaClient
import software.amazon.awssdk.services.lambda.model.Runtime
import software.amazon.awssdk.services.lambda.model.State
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.TempDir
Expand Down Expand Up @@ -62,12 +63,16 @@ abstract class AbstractClientSpec extends Specification {
lambda.createFunction {
it.functionName('HelloFunction')
.runtime(Runtime.NODEJS16_X)
.role('HelloRole')
.role('arn:aws:iam::123456789012:role/HelloRole')
.handler('index.handler')
.code { it.zipFile(SdkBytes.fromByteArray(functionArchive.bytes)) }
.environment { it.variables(MICRNOAUT_ENVIRONMENT: 'itest') }
.build()
}

while (lambda.getFunction { it.functionName('HelloFunction') }.configuration().state() != State.ACTIVE) {
Thread.sleep(100)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
localstack:
services: lambda
shared: true
env:
PROVIDER_OVERRIDE_LAMBDA: asf
DEBUG: 1

aws:
lambda:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SimpleStorageServiceConfigurationSpec extends Specification {
context.getBeanDefinitions(S3Client).size() == 1
context.getBeanDefinitions(S3AsyncClient).size() == 1
context.getBeanDefinitions(S3Presigner).size() == 1
context.getBean(SimpleStorageServiceConfiguration).bucket == ''
context.getBean(SimpleStorageServiceConfiguration).bucket == null
}

void 'configure single service'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import java.time.Duration
* Tests for SimpleStorageService based on Testcontainers with Minio server.
*/
@Property(name = 'aws.s3.force-path-style', value = 'true')
@Property(name = 'aws.s3.bucket', value = MY_BUCKET)
class SimpleStorageServiceMinioSpec extends SimpleStorageServiceSpec implements TestPropertyProvider {

private static final int MINIO_PORT = 9000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class SimpleStorageServiceSpec extends Specification {

// end::header[]

private static final String KEY = 'foo/bar.baz'
private static final String UPLOAD_KEY = 'foo/foo.two'
private static final String MY_BUCKET = 'testbucket'
private static final String OTHER_BUCKET = 'otherbucket'
private static final String SAMPLE_CONTENT = 'hello world!'
private static final Date TOMORROW = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000)
private static final String NO_SUCH_BUCKET = 'no-such-bucket'
protected static final String KEY = 'foo/bar.baz'
protected static final String UPLOAD_KEY = 'foo/foo.two'
protected static final String MY_BUCKET = 'testbucket'
protected static final String OTHER_BUCKET = 'otherbucket'
protected static final String SAMPLE_CONTENT = 'hello world!'
protected static final Date TOMORROW = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000)
protected static final String NO_SUCH_BUCKET = 'no-such-bucket'

@TempDir File tmp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class KinesisConfigurationSpec extends Specification {
context = ApplicationContext.run()
then:
context.getBeanDefinitions(KinesisService).size() == 1
context.getBean(KinesisConfiguration).stream == ''
context.getBean(KinesisConfiguration).stream == null
}

void 'configure single service'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ dependencies {
testImplementation project(':micronaut-aws-sdk-cloudwatchlogs')
testImplementation 'org.zeroturnaround:zt-zip:1.15'
testImplementation 'com.agorapulse.testing:fixt:0.2.3'

testRuntimeOnly('org.yaml:snakeyaml')
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.amazonaws.services.lambda.AWSLambda
import com.amazonaws.services.lambda.model.CreateFunctionRequest
import com.amazonaws.services.lambda.model.Environment
import com.amazonaws.services.lambda.model.FunctionCode
import com.amazonaws.services.lambda.model.GetFunctionRequest
import com.amazonaws.services.lambda.model.Runtime
import groovy.transform.CompileStatic
import org.zeroturnaround.zip.ZipUtil
Expand Down Expand Up @@ -67,12 +68,16 @@ abstract class AbstractClientSpec extends Specification {
CreateFunctionRequest request = new CreateFunctionRequest()
.withFunctionName('HelloFunction')
.withRuntime(Runtime.Nodejs16X)
.withRole('HelloRole')
.withRole('arn:aws:iam::123456789012:role/HelloRole')
.withHandler('index.handler')
.withCode(new FunctionCode().withZipFile(ByteBuffer.wrap(functionArchive.bytes)))
.withEnvironment(new Environment(variables: [MICRONAUT_ENVIRONMENTS: 'itest']))

lambda.createFunction(request)

while (lambda.getFunction(new GetFunctionRequest().withFunctionName('HelloFunction')).configuration.state != 'Active') {
Thread.sleep(100)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
localstack:
services: lambda
shared: true
env:
PROVIDER_OVERRIDE_LAMBDA: asf
DEBUG: 1

aws:
lambda:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SimpleStorageServiceConfigurationSpec extends Specification {
context = ApplicationContext.run()
then:
context.getBeanDefinitions(SimpleStorageService).size() == 1
context.getBean(SimpleStorageServiceConfiguration).bucket == ''
context.getBean(SimpleStorageServiceConfiguration).bucket == null
}

void 'configure single service'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ class SimpleStorageServiceWithMockSpec extends Specification {

void "Storing file"() {
given:
File file = Mock(File)
String path = 'filePrefix.txt'
File file = new File(path)

when:
String url = service.storeFile(path, file)
Expand All @@ -253,8 +253,8 @@ class SimpleStorageServiceWithMockSpec extends Specification {

void "Storing file exception"() {
given:
File file = Mock(File)
String path = 'filePrefix.txt'
File file = new File(path)

when:
String url = service.storeFile(path, file)
Expand Down

0 comments on commit cbeae49

Please sign in to comment.