Unit testing dynamics

69 views
Skip to first unread message

jesse...@cloverhealth.com

unread,
Oct 19, 2016, 3:38:04 PM10/19/16
to SparkleFormation
Hi all,

I have some dynamics which manifest some level of smarts. I want to unit test them using rspec. How do I even get started here? In the end I want either an AttributeStruct I can test the contents of, or a JSON blob I can do the same to.

I've tried creating a new SparkleFormation::Sparkle pack, which I can create and I have no idea how to proceed with.
I've also tried instantiating a SparkleFormation, but same thing.
Same thing also with setting SparkleFormation.sparkle_path, explicitly calling SparkleFormation.load_dynamics!, and trying to SparkleFormation.compile a simple fixture stack definition.

Is anybody else doing this?

Thanks,
-Jesse

Chris Roberts

unread,
Oct 20, 2016, 10:08:52 AM10/20/16
to sparklef...@googlegroups.com
Hi Jesse,

I use minitest, so just adjust to your testing framework as you see
fit. You can see examples of template testing within the
sparkle_formation tests. A good place to start would be here:

https://github.com/sparkleformation/sparkle_formation/blob/master/test/specs/template_spec.rb

This generates the template instance, then dumps it to a Smash (which
is a Hash with some extra helps) and tests the contents for the
expected values.

Cheers!

- Chris
> --
> You received this message because you are subscribed to the Google Groups
> "SparkleFormation" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sparkleformati...@googlegroups.com.
> To post to this group, send email to sparklef...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sparkleformation.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sparkleformation/ba6fbc5c-ef24-4d99-8a68-edfaca52a710%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jesse Kempf

unread,
Oct 20, 2016, 4:57:06 PM10/20/16
to sparklef...@googlegroups.com
Here’s what I’m getting when I crib from that:

(v) ✘-1 13:45 ~/workspace/genesis [tests L|✚ 3…3126⚑ 1] $ bundle exec rspec
.F

Failures:

  1) SparkleFormation compiles
     Failure/Error: dynamic!(:vpc_subnet, 'foo')

     

     RuntimeError:
       Failed to locate requested dynamic block for insertion: vpc_subnet (valid: )
       Builtin dynamics pattern `AWS::OpsWorks::App` -> `:aws_ops_works_app`
     # ./spec/fixtures/sfn/vpc_subnet_foo.rb:2:in `block in compile'
     # ./spec/unit/sparkleformation/dynamics/vpc_spec.rb:11:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # SparkleFormation::Error::NotFound::Dynamic:
     #   Failed to locate item named: `vpc_subnet`
     #   ./spec/fixtures/sfn/vpc_subnet_foo.rb:2:in `block in compile'

Finished in 0.04821 seconds (files took 0.10017 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/unit/sparkleformation/dynamics/vpc_spec.rb:10 # SparkleFormation compiles

(v) ✘-1 13:45 ~/workspace/genesis [tests L|✚ 3…3126⚑ 1] $ 

My directory layout looks like:

(v) 13:47 ~/workspace/genesis [tests L|✚ 3…3125⚑ 1] $ find spec -type f -follow
spec/fixtures/sfn/dynamics/vpc.rb
spec/fixtures/sfn/vpc_subnet_foo.rb
spec/spec_helper.rb
spec/unit/sparkleformation/dynamics/vpc_spec.rb
(v) 13:47 ~/workspace/genesis [tests L|✚ 3…3124⚑ 1] $ 

Tests look like:

(v) ✘-1 13:48 ~/workspace/genesis [tests L|✚ 3…3125⚑ 1] $ cat spec/unit/sparkleformation/dynamics/vpc_spec.rb 
require 'sparkle_formation'

describe SparkleFormation do
  before do
    SparkleFormation.sparkle_path = File.join(File.dirname(__FILE__), '../../../fixtures/sfn')
  end

  it { expect(1).to eq 1}

  it 'compiles' do
    SparkleFormation.compile('vpc_subnet_foo.rb')
  end
end
(v) 13:49 ~/workspace/genesis [tests L|✚ 3…3125⚑ 1] $ 

It’s definite that the sparkle_path is set to the correct directory.

And finally the fixture template looks like this:

(v) 13:52 ~/workspace/genesis [tests L|✚ 3…3125⚑ 1] $ cat spec/fixtures/sfn/vpc_subnet_foo.rb 
SparkleFormation.new(:vpc_subnet_foo, provider: :aws) do
  dynamic!(:vpc_subnet, 'foo')
end
(v) 13:53 ~/workspace/genesis [tests L|✚ 3…3125⚑ 1] $ 


Is there something else I need to do to get loading the dynamics working?

Thanks,
-Jesse

Reply all
Reply to author
Forward
0 new messages