-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): exposed testing matchers for other languages properly (#1935)
* fix(lib): exposed testing matchers for other languages properly * added documentation for increased support of unit testing * updated templates to add testing and various small changes to integration tests * fixed docs formating * Update website/docs/cdktf/test/unit-tests.mdx Co-authored-by: Laura Pacilio <83350965+laurapacilio@users.noreply.github.com> * Update website/docs/cdktf/test/unit-tests.mdx Co-authored-by: Laura Pacilio <83350965+laurapacilio@users.noreply.github.com> * Update website/docs/cdktf/test/unit-tests.mdx Co-authored-by: Laura Pacilio <83350965+laurapacilio@users.noreply.github.com> * Update website/docs/cdktf/test/unit-tests.mdx Co-authored-by: Laura Pacilio <83350965+laurapacilio@users.noreply.github.com> * Revert "Update website/docs/cdktf/test/unit-tests.mdx" This reverts commit 1258245. * Revert "Update website/docs/cdktf/test/unit-tests.mdx" This reverts commit a9cc009. * fixed templates that caused build errors in tests * update to testing docs * fixed async tests for java dotnet * chore: fix wording Co-authored-by: Jon Steinich <jsteinich@gmail.com> * chore: improve wording Co-authored-by: Jon Steinich <jsteinich@gmail.com> * chore: fix wording Co-authored-by: Jon Steinich <jsteinich@gmail.com> * chore: use default test path in java * chore: only expose boolean instead of AssertionReturn for now Co-authored-by: Laura Pacilio <83350965+laurapacilio@users.noreply.github.com> Co-authored-by: Daniel Schmidt <danielmschmidt92@gmail.com> Co-authored-by: Jon Steinich <jsteinich@gmail.com>
- Loading branch information
1 parent
129b1a9
commit abc1596
Showing
31 changed files
with
1,319 additions
and
104 deletions.
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,38 @@ | ||
using Xunit; | ||
using HashiCorp.Cdktf; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MyCompany.MyApp{ | ||
// The tests below are example tests, you can find more information at | ||
// https://cdk.tf/testing | ||
public class TestProgram{ | ||
|
||
[Fact] | ||
public void myAppTest(){ | ||
Assert.True(true); | ||
} | ||
|
||
//private static TerraformStack stack = new TerraformStack(Testing.app(), "stack"); | ||
//private static MyApplicationsAbstraction appAbstraction = new MyApplicationsAbstraction(stack, "construct"); | ||
//private static string synthesized = Testing.synth(stack); | ||
|
||
//[Fact] | ||
//public void CheckValidity(){ | ||
// Assert.True(Testing.ToBeValidTerraform(Testing.FullSynth(stack)) ); | ||
//} | ||
|
||
//[Fact] | ||
//public void shouldContainContainer(){ | ||
// Assert.True(Testing.ToHaveResource(synthesized, Container.TfResourceType) ); | ||
//} | ||
|
||
//[Fact] | ||
//public void shouldUseUbuntuImage(){ | ||
// Assert.True(Testing.ToHaveResourceWithProperties(synthesized, Image.TfResourceType, new Dictionary<String, Object>() { | ||
// {"name", "ubuntu:latest"} | ||
// }) ); | ||
//} | ||
} | ||
|
||
} |
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 main | ||
|
||
import ( | ||
"testing" | ||
"github.com/hashicorp/terraform-cdk-go/cdktf" | ||
"github.com/aws/jsii-runtime-go" | ||
) | ||
|
||
// The tests below are example tests, you can find more information at | ||
// https://cdk.tf/testing | ||
|
||
/* | ||
var stack = NewMyApplicationsAbstraction(cdktf.Assertions_App(nil), "stack") | ||
var synth = cdktf.Assertions_Synth(stack) | ||
func TestShouldContainContainer(t *testing.T){ | ||
assertion := cdktf.Assertions_ToHaveResource(synth, docker.Container_TfResourceType()) | ||
if !*assertion { | ||
t.Error(assertion.Message()) | ||
} | ||
} | ||
func TestShouldUseUbuntuImage(t *testing.T){ | ||
properties := map[string]interface{}{ | ||
"name": "ubuntu:latest", | ||
} | ||
assertion := cdktf.Assertions_ToHaveResourceWithProperties(synth, docker.Image_TfResourceType(), &properties) | ||
if !*assertion { | ||
t.Error(assertion.Message()) | ||
} | ||
} | ||
func TestCheckValidity(t *testing.T){ | ||
assertion := cdktf.Testing_ToBeValidTerraform(cdktf.Testing_FullSynth(stack)) | ||
if !*assertion { | ||
t.Error(assertion.Message()) | ||
} | ||
} | ||
*/ |
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
38 changes: 38 additions & 0 deletions
38
packages/cdktf-cli/templates/java/src/test/java/com/company/app/MainTest.java
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,38 @@ | ||
import com.hashicorp.cdktf.Testing; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
// The tests below are example tests, you can find more information at | ||
// https://cdk.tf/testing | ||
public class MainTest { | ||
|
||
@Test | ||
void myAppTest() { | ||
assertTrue(true); | ||
} | ||
//private final TerraformStack stack = new TerraformStack(Testing.app(), "stack"); | ||
|
||
//private final MyApplicationsAbstraction appAbstraction = new MyApplicationsAbstraction(stack, "resource"); | ||
//private final String synthesized = Testing.synth(stack); | ||
|
||
//@Test | ||
//void shouldContainContainer() { | ||
// assertTrue(Testing.toHaveResource(synthesized, Container.TF_RESOURCE_TYPE) ); | ||
//} | ||
|
||
//@Test | ||
//void shouldUseUbuntuImage() { | ||
// assertTrue(Testing | ||
// .toHaveResourceWithProperties(synthesized, Image.TF_RESOURCE_TYPE, new HashMap<String, Object>() { | ||
// { | ||
// put("name", "ubuntu:latest"); | ||
// } | ||
// }) ); | ||
//} | ||
|
||
//@Test | ||
//void checkValidity() { | ||
// assertTrue(Testing.toBeValidTerraform(Testing.fullSynth(stack)) ); | ||
//} | ||
|
||
} |
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,21 @@ | ||
import pytest | ||
from cdktf import Testing, TerraformStack | ||
|
||
# The tests below are example tests, you can find more information at | ||
# https://cdk.tf/testing | ||
class TestMain: | ||
|
||
stack = TerraformStack(Testing.app(), "stack") | ||
#app_abstraction = MyApplicationsAbstraction(stack, "app-abstraction") | ||
#synthesized = Testing.synth(stack) | ||
|
||
#def test_should_contain_container(self): | ||
# assert Testing.to_have_resource(self.synthesized, Container.TF_RESOURCE_TYPE) | ||
|
||
#def test_should_use_an_ubuntu_image(self): | ||
# assert Testing.to_have_resource_with_properties(self.synthesized, Image.TF_RESOURCE_TYPE, { | ||
# "name": "ubuntu:latest", | ||
# }) | ||
|
||
#def test_check_validity(self): | ||
# assert Testing.to_be_valid_terraform(Testing.full_synth(stack)) |
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,25 @@ | ||
import pytest | ||
from cdktf import Testing | ||
|
||
# The tests below are example tests, you can find more information at | ||
# https://cdk.tf/testing | ||
|
||
class TestMain: | ||
|
||
def test_my_app(self): | ||
assert True | ||
|
||
#stack = TerraformStack(Testing.app(), "stack") | ||
#app_abstraction = MyApplicationsAbstraction(stack, "app-abstraction") | ||
#synthesized = Testing.synth(stack) | ||
|
||
#def test_should_contain_container(self): | ||
# assert Testing.to_have_resource(self.synthesized, Container.TF_RESOURCE_TYPE) | ||
|
||
#def test_should_use_an_ubuntu_image(self): | ||
# assert Testing.to_have_resource_with_properties(self.synthesized, Image.TF_RESOURCE_TYPE, { | ||
# "name": "ubuntu:latest", | ||
# }) | ||
|
||
#def test_check_validity(self): | ||
# assert Testing.to_be_valid_terraform(Testing.full_synth(stack)) |
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
Oops, something went wrong.