test/models/shipit/stacks_test.rb in shipit-engine-0.33.0 vs test/models/shipit/stacks_test.rb in shipit-engine-0.34.0
- old
+ new
@@ -8,16 +8,26 @@
@stack = shipit_stacks(:shipit)
@expected_base_path = Rails.root.join('data', 'stacks', @stack.to_param).to_s
GithubHook.any_instance.stubs(:teardown!)
end
- test "branch defaults to master" do
+ test "branch defaults to default branch name" do
@stack.branch = ""
+ Shipit.github.api.expects(:repo).with("shopify/shipit-engine").returns(
+ Struct.new(:default_branch).new('something')
+ )
assert @stack.save
- assert_equal 'master', @stack.branch
+ assert_equal 'something', @stack.branch
end
+ test "branch is blank when default cannot be determined" do
+ @stack.branch = ""
+ Shipit.github.api.expects(:repo).raises(Octokit::NotFound)
+ assert_not @stack.save
+ assert_nil @stack.branch
+ end
+
test "environment defaults to production" do
@stack.environment = ""
assert @stack.save
assert_equal 'production', @stack.environment
end
@@ -199,11 +209,11 @@
@stack.update_deployed_revision(last_deploy.since_commit.sha)
end
test "#create queues a GithubSyncJob" do
assert_enqueued_with(job: GithubSyncJob) do
- Stack.create!(repository: shipit_repositories(:rails))
+ Stack.create!(repository: shipit_repositories(:rails), branch: 'main')
end
end
test "#destroy also destroy associated GithubHooks" do
assert_difference -> { GithubHook.count }, -2 do
@@ -250,10 +260,11 @@
test ".run_deploy_in_foreground triggers a deploy" do
stack = Stack.create!(
repository: Repository.new(owner: "foo", name: "bar"),
environment: 'production',
+ branch: 'main',
)
commit = shipit_commits(:first)
stack.commits << commit
Stack.any_instance.expects(:trigger_deploy).with(anything, anything, env: {}, force: true, run_now: true)
@@ -360,17 +371,28 @@
@stack.update(lock_reason: nil)
end
end
test "the git cache lock prevent concurrent access to the git cache" do
- @stack.acquire_git_cache_lock do
+ second_stack = Shipit::Stack.find(@stack.id)
+ second_stack.acquire_git_cache_lock do
assert_raises Flock::TimeoutError do
@stack.acquire_git_cache_lock(timeout: 0.1) {}
end
end
end
+ test "the git cache lock is reentrant if called on the same Stack instance" do
+ called = false
+ @stack.acquire_git_cache_lock(timeout: 0.01) do
+ @stack.acquire_git_cache_lock(timeout: 0.01) do
+ called = true
+ end
+ end
+ assert called
+ end
+
test "the git cache lock is scoped to the stack" do
called = false
shipit_stacks(:cyclimse).acquire_git_cache_lock do
@stack.acquire_git_cache_lock do
called = true
@@ -922,9 +944,25 @@
assert_equal(
@stack.env,
expected_environment,
)
+ end
+
+ test "#unarchive! triggers a GithubSync job" do
+ assert_no_enqueued_jobs(only: GithubSyncJob) do
+ @stack.archive!(shipit_users(:codertocat))
+ end
+
+ assert_enqueued_with(job: GithubSyncJob, args: [stack_id: @stack.id]) do
+ @stack.unarchive!
+ end
+ end
+
+ test "#update that changes the branch name triggers a GithubSync job" do
+ assert_enqueued_with(job: GithubSyncJob, args: [stack_id: @stack.id]) do
+ @stack.update!(branch: 'test')
+ end
end
private
def generate_revert_commit(stack:, reverted_commit:, author: reverted_commit.author)