Sha256: 86b5002eb4b44d5d1511e4194dbceb6ff8369a22a2902586fc0e60993cfd3d13

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require "json"

module RSpec::Terraspace
  class Ts
    extend Memoist

    CLI = ::Terraspace::CLI

    def build_test_harness(options={})
      puts "Building test harness..."
      project = Project.new(options)
      root = project.create
      Terraspace.root = root # switch root to the generated test harness
    end

    def up(args)
      run("up #{args} -y")
      mod = args.split(' ').first
      @mod = ::Terraspace::Mod.new(mod)
      save_output
    end

    def down(args)
      run("down #{args} -y")
    end

    def run(command)
      puts "=> terraspace #{command}".color(:green)
      args = command.split(' ')
      CLI.start(args)
    end

    # Note: a terraspace.down will remove the output.json since it does a clean
    def save_output
      FileUtils.mkdir_p(File.dirname(out_path))
      run("output #{@mod.name} --format json --out #{out_path}")
    end

    def output(mod, name)
      data = JSON.load(IO.read(out_path))
      data.dig(name, "value")
    end

    def out_path
      "#{Terraspace.tmp_root}/rspec/output.json"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-terraspace-0.1.0 lib/rspec/terraspace/ts.rb