Skip to content

Commit

Permalink
Add Travis (#2)
Browse files Browse the repository at this point in the history
* Add travis and bump coverage min.
* fix issues with test order and akka system cleanup
  • Loading branch information
rmmeans authored Jul 13, 2016
1 parent 2eb9a8b commit 08bd5dc
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 33 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
jdk:
- oraclejdk8
language: scala
script: sbt clean compile coverage test
before_cache:
- find $HOME/.ivy2 -name "ivydata-*.properties" -delete
- find $HOME/.sbt -name "*.lock" -delete
cache:
directories:
- $HOME/.ivy2/cache
- $HOME/.sbt/boot/
sudo: false
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/lifeway/Chadash.svg?branch=master)](https://travis-ci.org/lifeway/Chadash)

# Chadash
An immutable cloud deployer for AWS EC2 Instances.

Expand Down
5 changes: 3 additions & 2 deletions app/global/AppGlobalSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package global
import actors.ChadashSystem
import com.google.inject.{Guice, Module}
import play.api.mvc.{EssentialAction, Filters}
import play.api.{Application, GlobalSettings, Logger}
import play.api.{Application, GlobalSettings, Logger, Mode}
import play.filters.gzip.GzipFilter
import play.filters.headers.SecurityHeadersFilter

Expand All @@ -19,7 +19,8 @@ trait AppGlobalSettings extends GlobalSettings {

override def onStop(app: Application) {
Logger.info("Application shutdown...")
ChadashSystem.system.shutdown()
if(app.mode != Mode.Test)
ChadashSystem.system.shutdown()
}

override def doFilter(next: EssentialAction): EssentialAction = {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ buildInfoKeys ++= Seq[BuildInfoKey](
)
buildInfoPackage := "com.lifeway.chadash.appversion"

ScoverageSbtPlugin.ScoverageKeys.coverageMinimum := 14.50
ScoverageSbtPlugin.ScoverageKeys.coverageMinimum := 60
ScoverageSbtPlugin.ScoverageKeys.coverageFailOnMinimum := false
ScoverageSbtPlugin.ScoverageKeys.coverageHighlighting := true

Expand Down
4 changes: 2 additions & 2 deletions conf/application.test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ logger {
aws {
credentialsProvider = "TypesafeConfigAWSCredentialsProvider"
# If you use a "TypesafeConfigAWSCredentialsProvider" credentialsProvider, you can specify the crendetials in the following fields:
#accessKey = ""
#secretKey = ""
accessKey = "fake-key"
secretKey = "fake-secret-key"
}

akka {
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/ASGInfoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.amazonaws.services.autoscaling.model._
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils._

import scala.concurrent.duration._

class ASGInfoSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike with Matchers
with MockitoSugar {
with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonAutoScaling]
val describeASGRequest = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames("test-asg-name")
Expand All @@ -30,6 +30,10 @@ class ASGInfoSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testC
Mockito.when(mockedClient.describeAutoScalingGroups(describeASGReqFail)).thenThrow(new AmazonServiceException("failed"))
Mockito.when(mockedClient.describeAutoScalingGroups(describeASGReqClientExc)).thenThrow(new AmazonClientException("connection problems")).thenReturn(describeASGResult)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"An ASGInfo fetcher" should "return a valid response if AWS is up" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, ASGInfo, system, TestActorFactory)
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/ASGSizeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.amazonaws.services.autoscaling.model.{AutoScalingGroup, DescribeAutoS
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class ASGSizeSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike with
Matchers with MockitoSugar {
Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonAutoScaling]
val describeASGReq = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames("test-asg-name")
Expand All @@ -33,6 +33,10 @@ class ASGSizeSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testC
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).describeAutoScalingGroups(failReq)
Mockito.doThrow(new AmazonClientException("connection problems")).doReturn(describeASGResult).when(mockedClient).describeAutoScalingGroups(clientExceptionReq)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"An ASGSize actor" should "return an ASG size response if an ASG is queried" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, ASGSize, system, TestActorFactory)
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/DeleteStackSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.amazonaws.services.cloudformation.model.DeleteStackRequest
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class DeleteStackSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers with MockitoSugar {
with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonCloudFormation]
val successReq = new DeleteStackRequest().withStackName("delete-success")
Expand All @@ -29,6 +29,10 @@ class DeleteStackSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.t
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).deleteStack(failReq)
Mockito.doThrow(new AmazonClientException("connection problems")).doNothing().when(mockedClient).deleteStack(clientExceptionReq)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A DeleteStack actor" should "request to delete the stack and return a response" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, DeleteStack, system, TestActorFactory)
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/ELBHealthInstanceCheckerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.amazonaws.services.elasticloadbalancing.model.{DescribeInstanceHealth
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class ELBHealthInstanceCheckerSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig))
with FlatSpecLike with Matchers with MockitoSugar {
with FlatSpecLike with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonElasticLoadBalancing]
val instance = new Instance("instance-1")
Expand All @@ -36,6 +36,10 @@ class ELBHealthInstanceCheckerSpec extends TestKit(ActorSystem("TestKit", TestCo
Mockito.when(mockedClient.describeInstanceHealth(failReq)).thenThrow(new AmazonServiceException("failed"))
Mockito.when(mockedClient.describeInstanceHealth(clientExceptionReq)).thenThrow(new AmazonClientException("connection problems")).thenReturn(successResultAllHealthy)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A ELBHealthInstanceChecker actor" should "return an all healthy message if all instance are healthy" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, ELBHealthyInstanceChecker, system, TestActorFactory)
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/FreezeASGSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import com.amazonaws.services.autoscaling.model.SuspendProcessesRequest
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.collection.JavaConverters._
import scala.concurrent.duration._

class FreezeASGSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers
with MockitoSugar {
with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonAutoScaling]
val successReq = new SuspendProcessesRequest().withAutoScalingGroupName("freeze-success").withScalingProcesses(Seq("AlarmNotification", "ScheduledActions").asJava)
Expand All @@ -31,6 +31,10 @@ class FreezeASGSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.tes
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).suspendProcesses(reqFail)
Mockito.doThrow(new AmazonClientException("connection problems")).doNothing().when(mockedClient).suspendProcesses(reqClientExc)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A FreezeASG actor" should " return a freeze completed response if successful" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, FreezeASG, system, TestActorFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import com.amazonaws.services.cloudformation.model.{DescribeStacksRequest, Descr
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

class StackCreateCompleteMonitorSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig))
with FlatSpecLike with Matchers with MockitoSugar {
with FlatSpecLike with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonCloudFormation]
val createCompleteReq = new DescribeStacksRequest().withStackName("create-completed")
Expand All @@ -43,6 +43,9 @@ class StackCreateCompleteMonitorSpec extends TestKit(ActorSystem("TestKit", Test
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).describeStacks(awsFailReq)
Mockito.doThrow(new AmazonClientException("connection problems")).doReturn(stackPendingResp).doReturn(stackCompleteResp).when(mockedClient).describeStacks(clientExceptionReq)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A StackCreateComplete Monitor actor" should "send a create complete message when the stack has reached CREATE_COMPLETE status" in {
val props = Props(new StackCreateCompleteMonitor(null, "create-completed") with Override)
Expand Down
7 changes: 5 additions & 2 deletions test/actors/workflow/tasks/StackCreatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import com.amazonaws.services.cloudformation.model.{Capability, CreateStackReque
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import play.api.libs.json.Json
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class StackCreatorSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers with MockitoSugar {
with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonCloudFormation]
val appVersionTag = new Tag().withKey("ApplicationVersion").withValue("1.0")
Expand All @@ -36,6 +36,9 @@ class StackCreatorSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).createStack(reqFail)
Mockito.doThrow(new AmazonClientException("connection problems")).doReturn(null).when(mockedClient).createStack(reqClientExc)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A stack creator actor" should "return a stack create request completed if successful" in {
val probe = TestProbe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import com.amazonaws.services.cloudformation.model.{DescribeStacksRequest, Descr
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

class StackDeleteCompleteMonitorSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig))
with FlatSpecLike with Matchers with MockitoSugar {
with FlatSpecLike with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonCloudFormation]
val deleteCompleteReq = new DescribeStacksRequest().withStackName("delete-completed")
Expand All @@ -42,6 +42,10 @@ class StackDeleteCompleteMonitorSpec extends TestKit(ActorSystem("TestKit", Test
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).describeStacks(awsFailReq)
Mockito.doThrow(new AmazonClientException("connection problems")).doReturn(stackPendingResp).doReturn(stackCompleteResp).when(mockedClient).describeStacks(clientExceptionReq)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A StackDeleteComplete Monitor actor" should "send a delete complete message when the stack has reached DELETE_COMPLETE status" in {
val props = Props(new StackDeleteCompleteMonitor(null, "delete-completed", "delete-completed") with Override)
val factory = new TestActorFactory(props)
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/StackInfoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.amazonaws.services.cloudformation.model.{DescribeStacksRequest, Descr
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class StackInfoSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers with MockitoSugar {
with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonCloudFormation]
val asgSuccessReq = new DescribeStacksRequest().withStackName("asg-name-query")
Expand All @@ -35,6 +35,10 @@ class StackInfoSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.tes
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).describeStacks(failReq)
Mockito.doThrow(new AmazonClientException("connection problems")).doReturn(idSuccessResult).when(mockedClient).describeStacks(clientExceptionReq)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A StackInfo actor" should "return the name of the ASG for a given stack" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, StackInfo, system, TestActorFactory)
Expand Down
7 changes: 5 additions & 2 deletions test/actors/workflow/tasks/StackListSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import com.amazonaws.services.cloudformation.model.{ListStacksRequest, ListStack
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class StackListSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers with MockitoSugar {
with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonCloudFormation]
val failMockedClient = mock[AmazonCloudFormation]
Expand All @@ -31,6 +31,9 @@ class StackListSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.tes
.doReturn(successResp)
.when(mockedClient).listStacks(req)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A StackList actor" should "retrieve filtered stacks" in {
val probe = TestProbe()
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/StackLoaderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import com.amazonaws.services.s3.model.S3Object
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import play.api.libs.json.{JsString, Json}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class StackLoaderSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers with MockitoSugar {
with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonS3]
val s3successObject = new S3Object()
Expand All @@ -36,6 +36,10 @@ class StackLoaderSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.t
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).getObject("test-bucket-name", "chadash-stacks/test-aws-down.json")
Mockito.doThrow(new AmazonClientException("connection problems")).doReturn(s3restartObject).when(mockedClient).getObject("test-bucket-name", "chadash-stacks/test-aws-restart.json")

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A StackLoader actor" should "return a JSON value for a valid stack" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, StackLoader, system, TestActorFactory)
Expand Down
8 changes: 6 additions & 2 deletions test/actors/workflow/tasks/UnfreezeASGSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.amazonaws.services.autoscaling.model.ResumeProcessesRequest
import com.amazonaws.{AmazonClientException, AmazonServiceException}
import org.mockito.Mockito
import org.scalatest.mock.MockitoSugar
import org.scalatest.{FlatSpecLike, Matchers}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import utils.{ActorFactory, PropFactory, TestConfiguration}

import scala.concurrent.duration._

class UnfreezeASGSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.testConfig)) with FlatSpecLike
with Matchers with MockitoSugar {
with Matchers with MockitoSugar with BeforeAndAfterAll {

val mockedClient = mock[AmazonAutoScaling]
val successReq = new ResumeProcessesRequest().withAutoScalingGroupName("success-req")
Expand All @@ -29,6 +29,10 @@ class UnfreezeASGSpec extends TestKit(ActorSystem("TestKit", TestConfiguration.t
Mockito.doThrow(new AmazonServiceException("failed")).when(mockedClient).resumeProcesses(failReq)
Mockito.doThrow(new AmazonClientException("client-exception-req")).doNothing().when(mockedClient).resumeProcesses(clientExceptionReq)

override def afterAll {
TestKit.shutdownActorSystem(system)
}

"A UnfreezeASG actor" should "unfreeze an ASG successfully" in {
val probe = TestProbe()
val proxy = TaskProxyBuilder(probe, UnfreezeASG, system, TestActorFactory)
Expand Down
Loading

0 comments on commit 08bd5dc

Please sign in to comment.