Skip to content

Commit

Permalink
feat: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom committed Jun 14, 2024
1 parent 08962f8 commit c9f97fd
Show file tree
Hide file tree
Showing 5 changed files with 413 additions and 24 deletions.
57 changes: 56 additions & 1 deletion packages/plugin-terraform/test/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ it.each([{ graphqlFile: "base" }])(
// Normally we can deal with this by configuring "prettier" in the codegen config.
// But in this unittest we test the raw result.
// Therefore the expected output is also formatted ugly.

expect(terraformResult.toString().replace(/\r/g, "")).toEqual(
expected.replace(/\r/g, "") + "\n",
);
Expand Down Expand Up @@ -168,3 +167,59 @@ it.each([{ graphqlFile: "base" }])(
);
},
);

it.each([{ graphqlFile: "base" }])(
"correct Terraform file for $graphqlFile WITH managed variable",
async ({ graphqlFile }) => {
const schema = buildSchema(
addToSchema +
fs.readFileSync(`./test/testdata/${graphqlFile}.graphql`, "utf8"),
);
const expected = fs.readFileSync(
`./test/testdata/expected/${graphqlFile}_add_amplience_is_managed_switch.tf`,
"utf8",
);

const terraformResult = await plugin(schema, [], {
hostname: "https://schema-examples.com",
add_amplience_is_managed_switch: true,
visualization: [
{
for_each: 'var.variables["VISUALIZATION_HOST"]',
label: "visualization.key",
templated_uri:
"${visualization.value}/preview/with-layout?vse={{vse.domain}}&content={{content.sys.id}}",
default: false,
},
{
label: "Localhost with layout",
templated_uri:
"http://localhost:3000/preview/with-layout?vse={{vse.domain}}&content={{content.sys.id}}",
default: false,
},
{
label: "Localhost without layout",
templated_uri:
"http://localhost:3000/preview/without-layout?vse={{vse.domain}}&content={{content.sys.id}}",
default: false,
},
],
content_repositories: {
website1: 'var.variables["CONTENT_REPO1_ID"]',
website2: 'var.variables["CONTENT_REPO2_ID"]',
},
slot_repositories: {
slot1: 'var.variables["SLOT_REPO1_ID"]',
slot2: 'var.variables["SLOT_REPO2_ID"]',
},
});

// Note: the terraform generator does output the terraform code with ugly formatting.
// Normally we can deal with this by configuring "prettier" in the codegen config.
// But in this unittest we test the raw result.
// Therefore the expected output is also formatted ugly.
expect(terraformResult.toString().replace(/\r/g, "")).toEqual(
expected.replace(/\r/g, "") + "\n",
);
},
);
40 changes: 32 additions & 8 deletions packages/plugin-terraform/test/testdata/expected/base.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ auto_sync = true
}

resource "amplience_content_type" "test"{
content_type_uri = amplience_content_type_schema.test.schema_id
content_type_uri = "https://schema-examples.com/test"
label = "Test"
status = "ACTIVE"
depends_on = [
amplience_content_type_schema.test
]
}

resource "amplience_content_type_assignment" "test"{
Expand All @@ -48,9 +51,12 @@ auto_sync = true
}

resource "amplience_content_type" "test_other_repository"{
content_type_uri = amplience_content_type_schema.test_other_repository.schema_id
content_type_uri = "https://schema-examples.com/test-other-repository"
label = "Test Other Repository"
status = "ACTIVE"
depends_on = [
amplience_content_type_schema.test_other_repository
]
}

resource "amplience_content_type_assignment" "test_other_repository"{
Expand All @@ -66,9 +72,12 @@ auto_sync = true
}

resource "amplience_content_type" "test_slot"{
content_type_uri = amplience_content_type_schema.test_slot.schema_id
content_type_uri = "https://schema-examples.com/test-slot"
label = "Test Slot"
status = "ACTIVE"
depends_on = [
amplience_content_type_schema.test_slot
]
}

resource "amplience_content_type_assignment" "test_slot"{
Expand All @@ -84,7 +93,7 @@ auto_sync = true
}

resource "amplience_content_type" "test_visualizations"{
content_type_uri = amplience_content_type_schema.test_visualizations.schema_id
content_type_uri = "https://schema-examples.com/test-visualizations"
label = "Test Visualizations"
status = "ACTIVE"
dynamic"visualization" {
Expand All @@ -105,6 +114,9 @@ label = "Localhost without layout"
templated_uri = "http://localhost:3000/preview/without-layout?vse={{vse.domain}}&content={{content.sys.id}}"
default = false
}
depends_on = [
amplience_content_type_schema.test_visualizations
]
}

resource "amplience_content_type_assignment" "test_visualizations"{
Expand All @@ -120,7 +132,7 @@ auto_sync = true
}

resource "amplience_content_type" "test_icon"{
content_type_uri = amplience_content_type_schema.test_icon.schema_id
content_type_uri = "https://schema-examples.com/test-icon"
label = "Test Icon"
icon {
size = 256
Expand All @@ -145,6 +157,9 @@ label = "Localhost without layout"
templated_uri = "http://localhost:3000/preview/without-layout?vse={{vse.domain}}&content={{content.sys.id}}"
default = false
}
depends_on = [
amplience_content_type_schema.test_icon
]
}

resource "amplience_content_type_assignment" "test_icon"{
Expand All @@ -160,9 +175,12 @@ auto_sync = true
}

resource "amplience_content_type" "test_auto_sync_true"{
content_type_uri = amplience_content_type_schema.test_auto_sync_true.schema_id
content_type_uri = "https://schema-examples.com/test-auto-sync-true"
label = "Test Auto Sync True"
status = "ACTIVE"
depends_on = [
amplience_content_type_schema.test_auto_sync_true
]
}

resource "amplience_content_type_assignment" "test_auto_sync_true"{
Expand All @@ -178,9 +196,12 @@ auto_sync = false
}

resource "amplience_content_type" "test_auto_sync_false"{
content_type_uri = amplience_content_type_schema.test_auto_sync_false.schema_id
content_type_uri = "https://schema-examples.com/test-auto-sync-false"
label = "Test Auto Sync False"
status = "ACTIVE"
depends_on = [
amplience_content_type_schema.test_auto_sync_false
]
}

resource "amplience_content_type_assignment" "test_auto_sync_false"{
Expand All @@ -196,9 +217,12 @@ auto_sync = true
}

resource "amplience_content_type" "test_no_auto_sync"{
content_type_uri = amplience_content_type_schema.test_no_auto_sync.schema_id
content_type_uri = "https://schema-examples.com/test-no-auto-sync"
label = "Test No Auto Sync"
status = "ACTIVE"
depends_on = [
amplience_content_type_schema.test_no_auto_sync
]
}

resource "amplience_content_type_assignment" "test_no_auto_sync"{
Expand Down
Loading

0 comments on commit c9f97fd

Please sign in to comment.