Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
goruha committed Jan 6, 2025
1 parent 80b9140 commit 77c931e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/atmos/aws-component-helper/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,64 @@ import (
"github.com/stretchr/testify/require"
)

// TestAcceptance is an end-to-end acceptance test for AWS component helper functionality.
func TestAcceptance(t *testing.T) {
// Mock AWS account ID retrieval callback
getAwsAaccountIdCallback = func() (string, error) {
return "123456789012", nil
}

// Copy the test folder to a temporary location for isolation
testFolder, err := files.CopyFolderToTemp("../../../", t.Name(), func(path string) bool { return true })
require.NoError(t, err)
defer func() {
// Clean up the temporary test folder
if err := os.RemoveAll(testFolder); err != nil {
t.Errorf("failed to cleanup test folder: %v", err)
}
}()

fmt.Printf("running in %s\n", testFolder)

// Initialize a new test fixture for the acceptance test
fixture := NewFixture(t, testFolder, "us-west-2", "test/fixtures/aws-component-helper")

// Set up and tear down the test environment
fixture.SetUp(&atmos.Options{})
defer fixture.TearDown()

// Run a suite of tests within the "default" group
fixture.Suite("default", func(t *testing.T, suite *Suite) {
// Test case: "basic"
suite.Test(t, "basic", func(t *testing.T, atm *Atmos) {
inputs := map[string]interface{}{
"cnt": 2,
"cnt": 2, // Input variable for the Terraform configuration
}
// Ensure proper cleanup by destroying resources after the test
defer atm.GetAndDestroy("terraform-basic-configuration", "default-test", inputs)
// Deploy the Terraform component
atm.GetAndDeploy("terraform-basic-configuration", "default-test", inputs)

})

// Test case: "no-error"
suite.Test(t, "no-error", func(t *testing.T, atm *Atmos) {
// Ensure proper cleanup by destroying resources after the test
defer atm.GetAndDestroy("terraform-no-error", "default-test", nil)
// Deploy the Terraform component
component := atm.GetAndDeploy("terraform-no-error", "default-test", nil)

// Expected outputs from the Terraform component
mapOfObjects := map[string]interface{}{
"a": map[string]interface{}{"b": "c"},
"d": map[string]interface{}{"e": "f"},
}

// Assert outputs against expected values
assert.Equal(t, "Hello, World", atm.Output(component, "test"))
assert.Equal(t, []string{"a", "b", "c"}, atm.OutputList(component, "test_list"))
assert.Equal(t, mapOfObjects, atm.OutputMapOfObjects(component, "test_map_of_objects"))

// Struct definitions for complex outputs
type structValue1 struct {
B string
}
Expand All @@ -67,12 +82,14 @@ func TestAcceptance(t *testing.T) {
D structValue2
}

// Parse and validate structured output
structResult := structValue{}
structExpected := structValue{
A: structValue1{B: "c"},
D: structValue2{E: "f"},
}

// Assert that the parsed struct matches the expected structure
atm.OutputStruct(component, "test_map_of_objects", &structResult)
assert.Equal(t, structExpected, structResult)
})
Expand Down

0 comments on commit 77c931e

Please sign in to comment.