|
| 1 | +defmodule ElixirScript.ContextTest do |
| 2 | + use ExUnit.Case, async: true |
| 3 | + import Mox |
| 4 | + |
| 5 | + alias ElixirScript.Context |
| 6 | + alias Test.Fixtures.GitHubWorkflowRun |
| 7 | + |
| 8 | + setup :verify_on_exit! |
| 9 | + |
| 10 | + describe "from_github_environment/0" do |
| 11 | + test "returns a Context struct with default values when environment variables are not set" do |
| 12 | + stub(SystemEnvBehaviourMock, :get_env, fn varname, default -> |
| 13 | + GitHubWorkflowRun.env()[varname] || default |
| 14 | + end) |
| 15 | + |
| 16 | + assert Context.from_github_environment() == %Context{ |
| 17 | + action: "script", |
| 18 | + actor: "gaggle", |
| 19 | + api_url: "https://api.github.com", |
| 20 | + event_name: "push", |
| 21 | + graphql_url: "https://api.github.com/graphql", |
| 22 | + job: "event-context-is-available", |
| 23 | + payload: %{ |
| 24 | + after: "2ea150fa30b30dec0aeb85eb93469eda2d95c7d7", |
| 25 | + compare: |
| 26 | + "https://github.com/gaggle/elixir_script/compare/5ace270b6afc...2ea150fa30b3", |
| 27 | + ref: "refs/heads/atom-context", |
| 28 | + repository: %{ |
| 29 | + id: 675_841_662, |
| 30 | + contents_url: |
| 31 | + "https://api.github.com/repos/gaggle/elixir_script/contents/{+path}", |
| 32 | + url: "https://github.com/gaggle/elixir_script", |
| 33 | + allow_forking: true, |
| 34 | + pulls_url: "https://api.github.com/repos/gaggle/elixir_script/pulls{/number}", |
| 35 | + collaborators_url: |
| 36 | + "https://api.github.com/repos/gaggle/elixir_script/collaborators{/collaborator}", |
| 37 | + trees_url: "https://api.github.com/repos/gaggle/elixir_script/git/trees{/sha}", |
| 38 | + branches_url: |
| 39 | + "https://api.github.com/repos/gaggle/elixir_script/branches{/branch}", |
| 40 | + deployments_url: |
| 41 | + "https://api.github.com/repos/gaggle/elixir_script/deployments", |
| 42 | + has_projects: false, |
| 43 | + description: "Run simple Elixir scripts, easily", |
| 44 | + size: 105, |
| 45 | + subscription_url: |
| 46 | + "https://api.github.com/repos/gaggle/elixir_script/subscription", |
| 47 | + has_issues: true, |
| 48 | + issue_comment_url: |
| 49 | + "https://api.github.com/repos/gaggle/elixir_script/issues/comments{/number}", |
| 50 | + ssh_url: "[email protected]:gaggle/elixir_script.git", |
| 51 | + default_branch: "main", |
| 52 | + assignees_url: |
| 53 | + "https://api.github.com/repos/gaggle/elixir_script/assignees{/user}", |
| 54 | + git_refs_url: |
| 55 | + "https://api.github.com/repos/gaggle/elixir_script/git/refs{/sha}", |
| 56 | + forks: 0, |
| 57 | + open_issues: 0, |
| 58 | + notifications_url: |
| 59 | + "https://api.github.com/repos/gaggle/elixir_script/notifications{?since,all,participating}", |
| 60 | + created_at: 1_691_443_361, |
| 61 | + pushed_at: 1_700_430_826, |
| 62 | + blobs_url: "https://api.github.com/repos/gaggle/elixir_script/git/blobs{/sha}", |
| 63 | + stargazers: 0, |
| 64 | + node_id: "R_kgDOKEiGfg", |
| 65 | + has_wiki: false, |
| 66 | + labels_url: "https://api.github.com/repos/gaggle/elixir_script/labels{/name}", |
| 67 | + license: nil, |
| 68 | + hooks_url: "https://api.github.com/repos/gaggle/elixir_script/hooks", |
| 69 | + html_url: "https://github.com/gaggle/elixir_script", |
| 70 | + contributors_url: |
| 71 | + "https://api.github.com/repos/gaggle/elixir_script/contributors", |
| 72 | + topics: [], |
| 73 | + language: "Elixir", |
| 74 | + milestones_url: |
| 75 | + "https://api.github.com/repos/gaggle/elixir_script/milestones{/number}", |
| 76 | + keys_url: "https://api.github.com/repos/gaggle/elixir_script/keys{/key_id}", |
| 77 | + releases_url: |
| 78 | + "https://api.github.com/repos/gaggle/elixir_script/releases{/id}", |
| 79 | + disabled: false, |
| 80 | + open_issues_count: 0, |
| 81 | + commits_url: "https://api.github.com/repos/gaggle/elixir_script/commits{/sha}", |
| 82 | + name: "elixir_script", |
| 83 | + updated_at: "2023-11-18T16:35:54Z", |
| 84 | + mirror_url: nil, |
| 85 | + languages_url: "https://api.github.com/repos/gaggle/elixir_script/languages", |
| 86 | + watchers: 0, |
| 87 | + forks_count: 0, |
| 88 | + has_pages: false, |
| 89 | + issue_events_url: |
| 90 | + "https://api.github.com/repos/gaggle/elixir_script/issues/events{/number}", |
| 91 | + forks_url: "https://api.github.com/repos/gaggle/elixir_script/forks", |
| 92 | + private: false, |
| 93 | + merges_url: "https://api.github.com/repos/gaggle/elixir_script/merges", |
| 94 | + git_url: "git://github.com/gaggle/elixir_script.git", |
| 95 | + statuses_url: |
| 96 | + "https://api.github.com/repos/gaggle/elixir_script/statuses/{sha}", |
| 97 | + teams_url: "https://api.github.com/repos/gaggle/elixir_script/teams", |
| 98 | + subscribers_url: |
| 99 | + "https://api.github.com/repos/gaggle/elixir_script/subscribers", |
| 100 | + full_name: "gaggle/elixir_script", |
| 101 | + downloads_url: "https://api.github.com/repos/gaggle/elixir_script/downloads", |
| 102 | + master_branch: "main", |
| 103 | + events_url: "https://api.github.com/repos/gaggle/elixir_script/events", |
| 104 | + fork: false, |
| 105 | + compare_url: |
| 106 | + "https://api.github.com/repos/gaggle/elixir_script/compare/{base}...{head}", |
| 107 | + clone_url: "https://github.com/gaggle/elixir_script.git", |
| 108 | + watchers_count: 0, |
| 109 | + archived: false, |
| 110 | + has_discussions: false, |
| 111 | + svn_url: "https://github.com/gaggle/elixir_script", |
| 112 | + has_downloads: true, |
| 113 | + archive_url: |
| 114 | + "https://api.github.com/repos/gaggle/elixir_script/{archive_format}{/ref}", |
| 115 | + tags_url: "https://api.github.com/repos/gaggle/elixir_script/tags", |
| 116 | + is_template: false, |
| 117 | + issues_url: |
| 118 | + "https://api.github.com/repos/gaggle/elixir_script/issues{/number}", |
| 119 | + homepage: "https://github.com/marketplace/actions/elixir-script", |
| 120 | + git_tags_url: |
| 121 | + "https://api.github.com/repos/gaggle/elixir_script/git/tags{/sha}", |
| 122 | + stargazers_url: "https://api.github.com/repos/gaggle/elixir_script/stargazers", |
| 123 | + web_commit_signoff_required: false, |
| 124 | + comments_url: |
| 125 | + "https://api.github.com/repos/gaggle/elixir_script/comments{/number}", |
| 126 | + stargazers_count: 0, |
| 127 | + owner: %{ |
| 128 | + id: 2_316_447, |
| 129 | + name: "gaggle", |
| 130 | + type: "User", |
| 131 | + url: "https://api.github.com/users/gaggle", |
| 132 | + |
| 133 | + events_url: "https://api.github.com/users/gaggle/events{/privacy}", |
| 134 | + html_url: "https://github.com/gaggle", |
| 135 | + node_id: "MDQ6VXNlcjIzMTY0NDc=", |
| 136 | + avatar_url: "https://avatars.githubusercontent.com/u/2316447?v=4", |
| 137 | + followers_url: "https://api.github.com/users/gaggle/followers", |
| 138 | + following_url: "https://api.github.com/users/gaggle/following{/other_user}", |
| 139 | + gists_url: "https://api.github.com/users/gaggle/gists{/gist_id}", |
| 140 | + gravatar_id: "", |
| 141 | + login: "gaggle", |
| 142 | + organizations_url: "https://api.github.com/users/gaggle/orgs", |
| 143 | + received_events_url: "https://api.github.com/users/gaggle/received_events", |
| 144 | + repos_url: "https://api.github.com/users/gaggle/repos", |
| 145 | + site_admin: false, |
| 146 | + starred_url: "https://api.github.com/users/gaggle/starred{/owner}{/repo}", |
| 147 | + subscriptions_url: "https://api.github.com/users/gaggle/subscriptions" |
| 148 | + }, |
| 149 | + git_commits_url: |
| 150 | + "https://api.github.com/repos/gaggle/elixir_script/git/commits{/sha}", |
| 151 | + visibility: "public" |
| 152 | + }, |
| 153 | + base_ref: nil, |
| 154 | + before: "5ace270b6afc55dd3194d7e4cbf684ed753c2008", |
| 155 | + commits: [ |
| 156 | + %{ |
| 157 | + id: "2ea150fa30b30dec0aeb85eb93469eda2d95c7d7", |
| 158 | + message: "Output GITHUB_EVENT_PATH", |
| 159 | + timestamp: "2023-11-19T22:53:38+01:00", |
| 160 | + author: %{ |
| 161 | + name: "Jon Lauridsen", |
| 162 | + |
| 163 | + username: "gaggle" |
| 164 | + }, |
| 165 | + url: |
| 166 | + "https://github.com/gaggle/elixir_script/commit/2ea150fa30b30dec0aeb85eb93469eda2d95c7d7", |
| 167 | + committer: %{ |
| 168 | + name: "Jon Lauridsen", |
| 169 | + |
| 170 | + username: "gaggle" |
| 171 | + }, |
| 172 | + distinct: true, |
| 173 | + tree_id: "e7fa0dcfd93820a600f21dd33e5e30f3eae6c150" |
| 174 | + } |
| 175 | + ], |
| 176 | + created: false, |
| 177 | + deleted: false, |
| 178 | + forced: true, |
| 179 | + head_commit: %{ |
| 180 | + id: "2ea150fa30b30dec0aeb85eb93469eda2d95c7d7", |
| 181 | + message: "Output GITHUB_EVENT_PATH", |
| 182 | + timestamp: "2023-11-19T22:53:38+01:00", |
| 183 | + author: %{ |
| 184 | + name: "Jon Lauridsen", |
| 185 | + |
| 186 | + username: "gaggle" |
| 187 | + }, |
| 188 | + url: |
| 189 | + "https://github.com/gaggle/elixir_script/commit/2ea150fa30b30dec0aeb85eb93469eda2d95c7d7", |
| 190 | + committer: %{ |
| 191 | + name: "Jon Lauridsen", |
| 192 | + |
| 193 | + username: "gaggle" |
| 194 | + }, |
| 195 | + distinct: true, |
| 196 | + tree_id: "e7fa0dcfd93820a600f21dd33e5e30f3eae6c150" |
| 197 | + }, |
| 198 | + pusher: %{name: "gaggle", email: "[email protected]"}, |
| 199 | + sender: %{ |
| 200 | + id: 2_316_447, |
| 201 | + type: "User", |
| 202 | + url: "https://api.github.com/users/gaggle", |
| 203 | + events_url: "https://api.github.com/users/gaggle/events{/privacy}", |
| 204 | + html_url: "https://github.com/gaggle", |
| 205 | + node_id: "MDQ6VXNlcjIzMTY0NDc=", |
| 206 | + avatar_url: "https://avatars.githubusercontent.com/u/2316447?v=4", |
| 207 | + followers_url: "https://api.github.com/users/gaggle/followers", |
| 208 | + following_url: "https://api.github.com/users/gaggle/following{/other_user}", |
| 209 | + gists_url: "https://api.github.com/users/gaggle/gists{/gist_id}", |
| 210 | + gravatar_id: "", |
| 211 | + login: "gaggle", |
| 212 | + organizations_url: "https://api.github.com/users/gaggle/orgs", |
| 213 | + received_events_url: "https://api.github.com/users/gaggle/received_events", |
| 214 | + repos_url: "https://api.github.com/users/gaggle/repos", |
| 215 | + site_admin: false, |
| 216 | + starred_url: "https://api.github.com/users/gaggle/starred{/owner}{/repo}", |
| 217 | + subscriptions_url: "https://api.github.com/users/gaggle/subscriptions" |
| 218 | + } |
| 219 | + }, |
| 220 | + ref: "refs/heads/main", |
| 221 | + run_id: 6_922_972_178, |
| 222 | + run_number: 15, |
| 223 | + server_url: "https://github.com", |
| 224 | + sha: "77cefc59a7095f6b86508e8e26ff9f866da4b5e5", |
| 225 | + workflow: "Examples" |
| 226 | + } |
| 227 | + end |
| 228 | + end |
| 229 | +end |
0 commit comments