Hi Support,
Following does not work:
terraspace@4141debbc4e0:~/example$ cat test/spec/main_spec.rb
describe "main" do
before(:all) do
mod_path = File.expand_path("../..", __dir__) # the source of the module to test is 2 levels up
# Build terraspace project to use as a test harness
# Will be located at: /tmp/terraspace/test-harnesses/example-harness
terraspace.build_test_harness(
name: "example-harness",
modules: {example: mod_path},
# See: https://terraspace.cloud/docs/testing/test-harness/
# config: "spec/fixtures/config",
tfvars: {example: "spec/fixtures/tfvars/test.tfvars"},
)
terraspace.up("example")
end
after(:all) do
terraspace.down("example")
end
it "successful deploy" do
# Replace with your own test
expect(true).to be true
# Example
# pp terraspace.outputs
# output_value = terraspace.output("example", "name")
# expect(output_value).to include("some-value")
end
end
terraspace@4141debbc4e0:~/example$ ls
main.tf outputs.tf test variables.tf
####
And it throws error
terraspace@4141debbc4e0:~/example$ terraspace test
=> cd test && bundle exec rspec
main
Building test harness at: /tmp/terraspace/test-harnesses/example-harness
successful deploy (FAILED - 1)
=> TS_ENV=test terraspace down example -y
ERROR: Unable to find example. Searched paths:
app/stacks/example, app/modules/example, vendor/stacks/example, vendor/modules/example
To see available stacks, try running:
terraspace list
Failures:
1) main successful deploy
Failure/Error:
terraspace.build_test_harness(
name: "example-harness",
modules: {example: mod_path},
# See: https://terraspace.cloud/docs/testing/test-harness/
# config: "spec/fixtures/config",
tfvars: {example: "spec/fixtures/tfvars/test.tfvars"},
)
NoMethodError:
undefined method `[]' for nil:NilClass
md[1]
^^^
# /home/terraspace/.ruby/gems/rspec-terraspace-0.3.1/lib/rspec/terraspace/project.rb:137:in `detected_type'
# /home/terraspace/.ruby/gems/rspec-terraspace-0.3.1/lib/rspec/terraspace/project.rb:118:in `block in build_tfvars'
# /home/terraspace/.ruby/gems/rspec-terraspace-0.3.1/lib/rspec/terraspace/project.rb:117:in `each'
# /home/terraspace/.ruby/gems/rspec-terraspace-0.3.1/lib/rspec/terraspace/project.rb:117:in `build_tfvars'
# /home/terraspace/.ruby/gems/rspec-terraspace-0.3.1/lib/rspec/terraspace/project.rb:26:in `create'
# /home/terraspace/.ruby/gems/rspec-terraspace-0.3.1/lib/rspec/terraspace/ts.rb:13:in `build_test_harness'
# ./spec/main_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 1.62 seconds (files took 0.29204 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/main_spec.rb:19 # main successful deploy
terraspace@4141debbc4e0:~/example$
Following works
terraspace@4141debbc4e0:~/example$ cat test/spec/main_spec.rb
describe "main" do
before(:all) do
mod_path = File.expand_path("../..", __dir__) # the source of the module to test is 2 levels up
# Build terraspace project to use as a test harness
# Will be located at: /tmp/terraspace/test-harnesses/example-harness
terraspace.build_test_harness(
name: "example-harness",
modules: {example: mod_path},
# See: https://terraspace.cloud/docs/testing/test-harness/
# config: "spec/fixtures/config",
# tfvars: {example: "spec/fixtures/tfvars/test.tfvars"},
)
terraspace.up("example")
end
after(:all) do
terraspace.down("example")
end
it "successful deploy" do
# Replace with your own test
expect(true).to be true
# Example
# pp terraspace.outputs
# output_value = terraspace.output("example", "name")
# expect(output_value).to include("some-value")
end
end
terraspace@4141debbc4e0:~/example$ ls
main.tf outputs.tf test variables.tf
terraspace@4141debbc4e0:~/example$
So the question is if we really test purely terraform code only without make app/module structure