Sha256: cc1e1eec180fa73edac1cf19736ae4aebede4afc135a985301b175a82c305c50

Contents?: true

Size: 1.89 KB

Versions: 9

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require 'test_helper'

module Shipit
  class StackProvisioningHandlerTest < ActiveSupport::TestCase
    teardown do
      Shipit::ProvisioningHandler.reset_registry!
    end

    test "uses the no-op handler as default when no default handler is registered" do
      assert_equal Shipit::ProvisioningHandler::Base, Shipit::ProvisioningHandler.default
    end

    test "allows registration of a default handler" do
      mock_handler = mock("Mock Provisioning Handler")

      Shipit::ProvisioningHandler.default = mock_handler

      assert_equal mock_handler, Shipit::ProvisioningHandler.default
    end

    test "UnregisteredProvisioningHandler is returned when an attempt to fetch an unregistered handler is made" do
      unregistered_handler = mock("Mock Provisioning Handler")

      assert_equal(
        Shipit::ProvisioningHandler::UnregisteredProvisioningHandler,
        Shipit::ProvisioningHandler.fetch(unregistered_handler)
      )
    end

    test "registers handlers so they become fetchable" do
      mock_handler = mock("Mock Provisioning Handler")

      Shipit::ProvisioningHandler.register(mock_handler)

      assert_equal mock_handler, Shipit::ProvisioningHandler.fetch(mock_handler.to_s)
    end

    test "handlers are called during provisioning" do
      stack = shipit_stacks(:review_stack)
      stack.update(
        provision_status: :deprovisioned
      )
      handler = Shipit::ProvisioningHandler.default

      handler.any_instance.expects(:up)

      assert stack.provision!, "stack should have provisioned."
    end

    test "handlers are called during deprovisioning" do
      stack = shipit_stacks(:review_stack)
      stack.update(
        provision_status: :provisioned
      )
      handler = Shipit::ProvisioningHandler.default

      handler.any_instance.expects(:down)

      assert stack.deprovision!, "stack should have deprovisioned."
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
shipit-engine-0.39.0 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.38.0 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.37.0 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.36.1 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.36.0 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.35.1 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.35.0 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.34.0 test/models/shipit/provisioning_handler_test.rb
shipit-engine-0.33.0 test/models/shipit/provisioning_handler_test.rb