-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validations for project/cluster pr config types (#1769)
- Loading branch information
1 parent
fda0da6
commit 7624820
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,6 +368,37 @@ defmodule Console.Deployments.GitTest do | |
assert_receive {:event, %PubSub.PullRequestCreated{item: ^pr}} | ||
end | ||
|
||
test "it can can create a pull request with a project config" do | ||
user = insert(:user) | ||
conn = insert(:scm_connection, token: "some-pat") | ||
insert(:project, name: "test") | ||
deployment_settings(write_bindings: [%{user_id: user.id}]) | ||
pra = insert(:pr_automation, | ||
identifier: "pluralsh/console", | ||
cluster: build(:cluster), | ||
connection: conn, | ||
updates: %{regexes: ["regex"], match_strategy: :any, files: ["file.yaml"], replace_template: "replace"}, | ||
configuration: [%{name: "first", type: :project}] | ||
) | ||
expect(Plural, :template, fn f, _, _ -> File.read(f) end) | ||
expect(Tentacat.Pulls, :create, fn _, "pluralsh", "console", %{head: "pr-test"} -> | ||
{:ok, %{"html_url" => "https://github.com/pr/url"}, %HTTPoison.Response{}} | ||
end) | ||
expect(Console.Deployments.Pr.Git, :setup, fn conn, "pluralsh/console", "pr-test" -> {:ok, conn} end) | ||
expect(Console.Deployments.Pr.Git, :commit, fn _, _ -> {:ok, ""} end) | ||
expect(Console.Deployments.Pr.Git, :push, fn _, "pr-test" -> {:ok, ""} end) | ||
|
||
{:ok, pr} = Git.create_pull_request(%{ | ||
"first" => "test" | ||
}, pra.id, "pr-test", user) | ||
|
||
assert pr.cluster_id == pra.cluster_id | ||
assert pr.url == "https://github.com/pr/url" | ||
assert pr.title == pra.title | ||
|
||
assert_receive {:event, %PubSub.PullRequestCreated{item: ^pr}} | ||
end | ||
|
||
test "it will reject a pull request w/o valid configuration" do | ||
user = insert(:user) | ||
conn = insert(:scm_connection, token: "some-pat") | ||
|
@@ -439,6 +470,44 @@ defmodule Console.Deployments.GitTest do | |
}, pra.id, "pr-test", user) | ||
end | ||
|
||
test "it will reject a pull request w/ invalid project names" do | ||
user = insert(:user) | ||
conn = insert(:scm_connection, token: "some-pat") | ||
insert(:project, name: "test") | ||
pra = insert(:pr_automation, | ||
identifier: "pluralsh/console", | ||
cluster: build(:cluster), | ||
connection: conn, | ||
updates: %{regexes: ["regex"], match_strategy: :any, files: ["file.yaml"], replace_template: "replace"}, | ||
write_bindings: [%{user_id: user.id}], | ||
create_bindings: [%{user_id: user.id}], | ||
configuration: [%{name: "project", type: :project}] | ||
) | ||
|
||
{:error, _} = Git.create_pull_request(%{ | ||
"first" => "wrong", | ||
}, pra.id, "pr-test", user) | ||
end | ||
|
||
test "it will reject a pull request w/ invalid cluster handles" do | ||
user = insert(:user) | ||
conn = insert(:scm_connection, token: "some-pat") | ||
insert(:cluster, handle: "test") | ||
pra = insert(:pr_automation, | ||
identifier: "pluralsh/console", | ||
cluster: build(:cluster), | ||
connection: conn, | ||
updates: %{regexes: ["regex"], match_strategy: :any, files: ["file.yaml"], replace_template: "replace"}, | ||
write_bindings: [%{user_id: user.id}], | ||
create_bindings: [%{user_id: user.id}], | ||
configuration: [%{name: "cluster", type: :cluster}] | ||
) | ||
|
||
{:error, _} = Git.create_pull_request(%{ | ||
"first" => "wrong", | ||
}, pra.id, "pr-test", user) | ||
end | ||
|
||
test "it can create a pull request with a github app" do | ||
user = insert(:user) | ||
{:ok, pem_string, _} = Console.keypair("[email protected]") | ||
|