Skip to content

Commit

Permalink
✅ : cover job and stack page with percy
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Feb 5, 2020
1 parent a553d1a commit 3c8981a
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/templates/stack.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h2>
</div>
<div class="block_content">
<b-form-group label="Name">
<b-input id="var-name"
<b-input id="stack.name"
v-model="stack.name"
:state="stack.name !== ''"
aria-describedby="input-live-help input-live-feedback"
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/io/codeka/gaia/e2e/JobPage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.codeka.gaia.e2e

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy

class JobPage(webDriver: WebDriver) {

init {
if(! webDriver.currentUrl.contains("/jobs/")){
throw IllegalStateException("This is not the job page. Current page is ${webDriver.currentUrl}")
}
}

}
32 changes: 29 additions & 3 deletions src/test/java/io/codeka/gaia/e2e/SeleniumIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public class SeleniumIT {
private static MongoContainer mongoContainer = new MongoContainer()
.withScript("src/test/resources/db/00_team.js")
.withScript("src/test/resources/db/10_user.js")
.withScript("src/test/resources/db/20_module.js");
.withScript("src/test/resources/db/20_module.js")
.withScript("src/test/resources/db/30_stack.js")
.withScript("src/test/resources/db/40_job.js")
.withScript("src/test/resources/db/50_step.js")
.withScript("src/test/resources/db/60_terraformState.js");

private static WebDriver driver;

Expand Down Expand Up @@ -75,7 +79,7 @@ private String testUrl(){

@Test
@Order(1) // this test runs first as it logs the user in !
void loginPage() throws IOException {
void loginPage() {
driver.get(testUrl());
driver.manage().window().setSize(new Dimension(1280,800));

Expand All @@ -93,7 +97,7 @@ void dashboardPage_showsModuleCount() throws IOException {
var page = PageFactory.initElements(driver, DashboardPage.class);

assertEquals(3, page.modulesCount());
assertEquals(0, page.stacksCount());
assertEquals(1, page.stacksCount());
assertEquals(0, page.stacksToUpdateCount());

percy.snapshot("Dashboard");
Expand Down Expand Up @@ -123,6 +127,28 @@ void modulePage_showsModuleDetails() throws IOException {
percy.snapshot("Module Details");
}

@Test
void stackPage_showsStackDetails() throws IOException {
driver.get(testUrl()+"/stacks/de28a01f-257a-448d-8e1b-00e4e3a41db2");

var page = new StackPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

assertThat(page.stackName()).isEqualTo("local-mongo");

percy.snapshot("Stack Details");
}

@Test
void jobPage_showsJobDetails() throws IOException {
driver.get(testUrl()+"/stacks/de28a01f-257a-448d-8e1b-00e4e3a41db2/jobs/5e856dc7-6bed-465f-abf1-02980206ab2a");

var page = new JobPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

percy.snapshot("Job Details");
}

void takeScreenshot() throws IOException {
var file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
System.out.println(file.getAbsolutePath());
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/io/codeka/gaia/e2e/StackPage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.codeka.gaia.e2e

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy

class StackPage(webDriver: WebDriver) {

init {
if(! webDriver.currentUrl.contains("/stacks/")){
throw IllegalStateException("This is not the stack page. Current page is ${webDriver.currentUrl}")
}
}

@FindBy(id="stack.name")
private lateinit var nameInput: WebElement

fun stackName() : String = nameInput.getAttribute("value")

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void listStacks_shouldReturnLimitedStacks_forStandardUsers() throws Exception {
void listStacks_shouldReturnAllStacks_forAdmin() throws Exception {
mockMvc.perform(get("/api/stacks"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(3)))
.andExpect(jsonPath("$..name", contains("mongo-instance-1", "mongo-instance-2", "mongo-instance-limited")))
.andExpect(jsonPath("$", hasSize(4)))
.andExpect(jsonPath("$..name", contains("mongo-instance-1", "mongo-instance-2", "mongo-instance-limited", "local-mongo")))
.andExpect(jsonPath("$..ownerTeam.id", contains("Ze Team", "Ze Team", "Not Ze Team")));
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/resources/db/30_stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,28 @@ gaia.stack.insert([
"createdAt": new Date(),
"updatedBy": null,
"updatedAt": null
},
{
"_id" : "de28a01f-257a-448d-8e1b-00e4e3a41db2",
"moduleId" : "e01f9925-a559-45a2-8a55-f93dc434c676",
"variableValues" : {
"mongo_container_name" : "local-mongo",
"mongo_exposed_port" : "28017"
},
"name" : "local-mongo",
"description" : "local docker mongo container",
"state" : "RUNNING",
"estimatedRunningCost" : "0",
"createdBy" : {
"$ref" : "user",
"$id" : "admin"
},
"createdAt" : ISODate("2020-02-03T17:57:07.341Z"),
"updatedBy" : {
"$ref" : "user",
"$id" : "admin"
},
"updatedAt" : ISODate("2020-02-05T07:01:29.935Z"),
"_class" : "io.codeka.gaia.stacks.bo.Stack"
}
]);
59 changes: 59 additions & 0 deletions src/test/resources/db/40_job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
gaia = db.getSiblingDB('gaia');
gaia.job.drop();
gaia.job.insert([
{
"_id" : "32e4c316-287a-48ba-9c49-dd1b1a0204c8",
"stackId" : "de28a01f-257a-448d-8e1b-00e4e3a41db2",
"startDateTime" : ISODate("2020-02-03T18:03:12.227Z"),
"endDateTime" : ISODate("2020-02-03T18:03:24.323Z"),
"type" : "RUN",
"status" : "APPLY_FINISHED",
"terraformImage" : {
"repository" : "hashicorp/terraform",
"tag" : "latest"
},
"steps" : [
{
"$ref" : "step",
"$id" : "b3bcea1e-3fb8-4443-bd8b-1caab78e6922"
},
{
"$ref" : "step",
"$id" : "ec9d0334-0055-4727-aa79-731ea79326e3"
}
],
"user" : {
"$ref" : "user",
"$id" : "selmak"
},
"_class" : "io.codeka.gaia.stacks.bo.Job"
},
{
"_id" : "5e856dc7-6bed-465f-abf1-02980206ab2a",
"stackId" : "de28a01f-257a-448d-8e1b-00e4e3a41db2",
"startDateTime" : ISODate("2020-02-05T07:01:30.875Z"),
"endDateTime" : ISODate("2020-02-05T07:02:18.625Z"),
"type" : "RUN",
"status" : "APPLY_FINISHED",
"terraformImage" : {
"repository" : "hashicorp/terraform",
"tag" : "latest"
},
"steps" : [
{
"$ref" : "step",
"$id" : "0ddcb316-8681-4416-bc59-f3e7d47836f1"
},
{
"$ref" : "step",
"$id" : "e294e7a2-abb7-4c0b-9102-5fb72ad42292"
}
],
"user" : {
"$ref" : "user",
"$id" : "selmak"
},
"_class" : "io.codeka.gaia.stacks.bo.Job"
}

]);
48 changes: 48 additions & 0 deletions src/test/resources/db/50_step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
gaia = db.getSiblingDB('gaia');
gaia.step.drop();
gaia.step.insert([
{
"_id" : "b3bcea1e-3fb8-4443-bd8b-1caab78e6922",
"jobId" : "32e4c316-287a-48ba-9c49-dd1b1a0204c8",
"startDateTime" : ISODate("2020-02-03T18:03:12.227Z"),
"endDateTime" : ISODate("2020-02-03T18:03:17.035Z"),
"executionTime" : NumberLong(4807),
"type" : "PLAN",
"status" : "FINISHED",
"logs" : "",
"_class" : "io.codeka.gaia.stacks.bo.Step"
},
{
"_id" : "ec9d0334-0055-4727-aa79-731ea79326e3",
"jobId" : "32e4c316-287a-48ba-9c49-dd1b1a0204c8",
"startDateTime" : ISODate("2020-02-03T18:03:19.301Z"),
"endDateTime" : ISODate("2020-02-03T18:03:24.323Z"),
"executionTime" : NumberLong(5021),
"type" : "APPLY",
"status" : "FINISHED",
"logs" : "using image hashicorp/terraform:latest\ncloning https://oauth2:[MASKED]@github.com/juwit/terraform-docker-mongo\nCloning into 'module'...\ngenerating backend configuration\nTerraform v0.12.20\n\n\u001b[0m\u001b[1mInitializing the backend...\u001b[0m\n\u001b[0m\u001b[32m\nSuccessfully configured the backend \"http\"! Terraform will automatically\nuse this backend unless the backend configuration changes.\u001b[0m\n\n\u001b[0m\u001b[1mInitializing provider plugins...\u001b[0m\n- Checking for available provider plugins...\n- Downloading plugin for provider \"docker\" (terraform-providers/docker) 2.6.0...\n\nThe following providers do not have any version constraints in configuration,\nso the latest version was installed.\n\nTo prevent automatic upgrades to new major versions that may contain breaking\nchanges, it is recommended to add version = \"...\" constraints to the\ncorresponding provider blocks in configuration, with the constraint strings\nsuggested below.\n\n* provider.docker: version = \"~> 2.6\"\n\n\u001b[0m\u001b[1m\u001b[32mTerraform has been successfully initialized!\u001b[0m\u001b[32m\u001b[0m\n\u001b[0m\u001b[1mdocker_image.mongo: Creating...\u001b[0m\u001b[0m\n\u001b[0m\u001b[1mdocker_image.mongo: Creation complete after 0s [id=sha256:5976dac61f4fb85c1a2d1f7c717600f9c78fb02badba6b3c5961a4091ef75905mongo]\u001b[0m\u001b[0m\n\u001b[0m\u001b[1mdocker_container.mongo: Creating...\u001b[0m\u001b[0m\n\u001b[0m\u001b[1mdocker_container.mongo: Creation complete after 1s [id=b247c86c6cee2c3ad6e9565c48cae29877374d07f7c6be5f42489002bdf66b42]\u001b[0m\u001b[0m\n\u001b[0m\u001b[1m\u001b[32m\nApply complete! Resources: 2 added, 0 changed, 0 destroyed.\u001b[0m\n\u001b[0m\u001b[1m\u001b[32m\nOutputs:\n\ndocker_container_name = test\u001b[0m\n",
"_class" : "io.codeka.gaia.stacks.bo.Step"
},
{
"_id" : "0ddcb316-8681-4416-bc59-f3e7d47836f1",
"jobId" : "5e856dc7-6bed-465f-abf1-02980206ab2a",
"startDateTime" : ISODate("2020-02-05T07:01:30.875Z"),
"endDateTime" : ISODate("2020-02-05T07:01:37.393Z"),
"executionTime" : NumberLong(6518),
"type" : "PLAN",
"status" : "FINISHED",
"logs" : "",
"_class" : "io.codeka.gaia.stacks.bo.Step"
},
{
"_id" : "e294e7a2-abb7-4c0b-9102-5fb72ad42292",
"jobId" : "5e856dc7-6bed-465f-abf1-02980206ab2a",
"startDateTime" : ISODate("2020-02-05T07:02:13.086Z"),
"endDateTime" : ISODate("2020-02-05T07:02:18.625Z"),
"executionTime" : NumberLong(5539),
"type" : "APPLY",
"status" : "FINISHED",
"logs" : "using image hashicorp/terraform:latest\ncloning https://oauth2:[MASKED]@github.com/juwit/terraform-docker-mongo\nCloning into 'module'...\ngenerating backend configuration\nTerraform v0.12.20\n\n\u001b[0m\u001b[1mInitializing the backend...\u001b[0m\n\u001b[0m\u001b[32m\nSuccessfully configured the backend \"http\"! Terraform will automatically\nuse this backend unless the backend configuration changes.\u001b[0m\n\n\u001b[0m\u001b[1mInitializing provider plugins...\u001b[0m\n- Checking for available provider plugins...\n- Downloading plugin for provider \"docker\" (terraform-providers/docker) 2.6.0...\n\nThe following providers do not have any version constraints in configuration,\nso the latest version was installed.\n\nTo prevent automatic upgrades to new major versions that may contain breaking\nchanges, it is recommended to add version = \"...\" constraints to the\ncorresponding provider blocks in configuration, with the constraint strings\nsuggested below.\n\n* provider.docker: version = \"~> 2.6\"\n\n\u001b[0m\u001b[1m\u001b[32mTerraform has been successfully initialized!\u001b[0m\u001b[32m\u001b[0m\n\u001b[0m\u001b[1mdocker_image.mongo: Refreshing state... [id=sha256:5976dac61f4fb85c1a2d1f7c717600f9c78fb02badba6b3c5961a4091ef75905mongo]\u001b[0m\n\u001b[0m\u001b[1mdocker_container.mongo: Refreshing state... [id=b247c86c6cee2c3ad6e9565c48cae29877374d07f7c6be5f42489002bdf66b42]\u001b[0m\n\u001b[0m\u001b[1mdocker_container.mongo: Creating...\u001b[0m\u001b[0m\n\u001b[0m\u001b[1mdocker_container.mongo: Creation complete after 0s [id=330b26c77d65e106df926454f9c3c3448f30c4a79062daefe66fe1d4a8f2970e]\u001b[0m\u001b[0m\n\u001b[0m\u001b[1m\u001b[32m\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\u001b[0m\n\u001b[0m\u001b[1m\u001b[32m\nOutputs:\n\ndocker_container_name = local-mongo\u001b[0m\n",
"_class" : "io.codeka.gaia.stacks.bo.Step"
}
]);
132 changes: 132 additions & 0 deletions src/test/resources/db/60_terraformState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
gaia = db.getSiblingDB('gaia');
gaia.terraformState.drop();
gaia.terraformState.insert([
{
"_id" : "de28a01f-257a-448d-8e1b-00e4e3a41db2",
"value" : {
"version" : 4,
"terraform_version" : "0.12.20",
"serial" : 0,
"lineage" : "ea06e653-352b-ec53-90c5-58699c6c9043",
"outputs" : {
"docker_container_name" : {
"value" : "test",
"type" : "string"
}
},
"resources" : [
{
"mode" : "managed",
"type" : "docker_container",
"name" : "mongo",
"provider" : "provider.docker",
"instances" : [
{
"schema_version" : 1,
"attributes" : {
"attach" : false,
"bridge" : "",
"capabilities" : [],
"command" : null,
"container_logs" : null,
"cpu_set" : null,
"cpu_shares" : null,
"destroy_grace_seconds" : null,
"devices" : [],
"dns" : null,
"dns_opts" : null,
"dns_search" : null,
"domainname" : null,
"entrypoint" : null,
"env" : null,
"exit_code" : null,
"gateway" : "172.17.0.1",
"group_add" : null,
"healthcheck" : [],
"host" : [],
"hostname" : null,
"id" : "b247c86c6cee2c3ad6e9565c48cae29877374d07f7c6be5f42489002bdf66b42",
"image" : "sha256:5976dac61f4fb85c1a2d1f7c717600f9c78fb02badba6b3c5961a4091ef75905",
"ip_address" : "172.17.0.3",
"ip_prefix_length" : 16,
"ipc_mode" : null,
"labels" : null,
"links" : null,
"log_driver" : "json-file",
"log_opts" : null,
"logs" : false,
"max_retry_count" : null,
"memory" : null,
"memory_swap" : null,
"mounts" : [],
"must_run" : true,
"name" : "test",
"network_alias" : null,
"network_data" : [
{
"gateway" : "172.17.0.1",
"ip_address" : "172.17.0.3",
"ip_prefix_length" : 16,
"network_name" : "bridge"
}
],
"network_mode" : null,
"networks" : null,
"networks_advanced" : [],
"pid_mode" : null,
"ports" : [
{
"external" : 28017,
"internal" : 27017,
"ip" : "0.0.0.0",
"protocol" : "tcp"
}
],
"privileged" : null,
"publish_all_ports" : null,
"read_only" : false,
"restart" : "no",
"rm" : false,
"shm_size" : null,
"start" : true,
"sysctls" : null,
"tmpfs" : null,
"ulimit" : [],
"upload" : [],
"user" : null,
"userns_mode" : null,
"volumes" : [],
"working_dir" : null
},
"private" : "eyJzY2hlbWFfdmVyc2lvbiI6IjEifQ==",
"dependencies" : [
"docker_image.mongo"
]
}
]
},
{
"mode" : "managed",
"type" : "docker_image",
"name" : "mongo",
"provider" : "provider.docker",
"instances" : [
{
"schema_version" : 0,
"attributes" : {
"id" : "sha256:5976dac61f4fb85c1a2d1f7c717600f9c78fb02badba6b3c5961a4091ef75905mongo",
"keep_locally" : true,
"latest" : "sha256:5976dac61f4fb85c1a2d1f7c717600f9c78fb02badba6b3c5961a4091ef75905",
"name" : "mongo",
"pull_trigger" : null,
"pull_triggers" : null
},
"private" : "bnVsbA=="
}
]
}
]
},
"_class" : "io.codeka.gaia.stacks.bo.TerraformState"
}
]);

0 comments on commit 3c8981a

Please sign in to comment.