File: actions_workflow_runs_spec.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (175 lines) | stat: -rw-r--r-- 4,902 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# frozen_string_literal: true

describe Octokit::Client::ActionsWorkflowRuns, :vcr do
  before do
    Octokit.reset!
    @client = oauth_client
    @run_id = 96_922_843
  end

  after do
    Octokit.reset!
  end

  describe '.workflow_runs' do
    workflow_name = 'workflow.yml'

    it 'returns runs for a workflow' do
      request = stub_get("repos/#{@test_repo}/actions/workflows/#{workflow_name}/runs")

      @client.workflow_runs(@test_repo, workflow_name)

      assert_requested request
    end

    it 'paginates the results' do
      @client.per_page = 1
      allow(@client).to receive(:paginate).and_call_original
      result = @client.workflow_runs(
        @test_repo,
        workflow_name
      )

      expect(@client).to have_received(:paginate)
      expect(result.total_count).to eq(3)
      expect(result.workflow_runs.count).to eq(1)
    end

    it 'auto-paginates the results' do
      @client.auto_paginate = true
      @client.per_page = 1
      allow(@client).to receive(:paginate).and_call_original
      result = @client.workflow_runs(
        @test_repo,
        workflow_name
      )

      expect(@client).to have_received(:paginate)
      expect(result.total_count).to eq(3)
      expect(result.workflow_runs.count).to eq(3)
    end
  end

  describe '.repository_workflow_runs' do
    it 'returns all workflow runs for repository' do
      @client.repository_workflow_runs(@test_repo)

      assert_requested :get, github_url("repos/#{@test_repo}/actions/runs")
    end

    it 'paginates the results' do
      @client.per_page = 1
      allow(@client).to receive(:paginate).and_call_original
      result = @client.repository_workflow_runs(
        @test_repo
      )

      expect(@client).to have_received(:paginate)
      expect(result.total_count).to eq(3)
      expect(result.workflow_runs.count).to eq(1)
    end

    it 'auto-paginates the results' do
      @client.auto_paginate = true
      @client.per_page = 1
      allow(@client).to receive(:paginate).and_call_original
      result = @client.repository_workflow_runs(
        @test_repo
      )

      expect(@client).to have_received(:paginate)
      expect(result.total_count).to eq(3)
      expect(result.workflow_runs.count).to eq(3)
    end
  end

  describe '.workflow_run' do
    it 'returns the requested workflow run' do
      request = stub_get("repos/#{@test_repo}/actions/runs/#{@run_id}")

      @client.workflow_run(@test_repo, @run_id)

      assert_requested request
    end
  end

  describe '.rerun_workflow_run' do
    it 'returns true if rerun request was enqueued successfully' do
      request = stub_post("repos/#{@test_repo}/actions/runs/#{@run_id}/rerun").to_return(status: 201)

      result = @client.rerun_workflow_run(@test_repo, @run_id)

      expect(result).to be true
      assert_requested request
    end

    it 'returns false if request returns unexpected status' do
      request = stub_post("repos/#{@test_repo}/actions/runs/#{@run_id}/rerun").to_return(status: 205)

      response = @client.rerun_workflow_run(@test_repo, @run_id)

      expect(response).to be false
      assert_requested request
    end
  end

  describe '.cancel_workflow_run' do
    it 'returns true if cancellation fo the workflow was successful' do
      request = stub_post("repos/#{@test_repo}/actions/runs/#{@run_id}/cancel").to_return(status: 202)

      response = @client.cancel_workflow_run(@test_repo, @run_id)

      expect(response).to be true
      assert_requested request
    end

    it 'returns false if the request returns unexpected status' do
      request = stub_post("repos/#{@test_repo}/actions/runs/#{@run_id}/cancel").to_return(status: 205)

      response = @client.cancel_workflow_run(@test_repo, @run_id)

      expect(response).to be false
      assert_requested request
    end
  end

  describe '.delete_workflow_run' do
    it 'deletes the workflow run' do
      request = stub_delete("repos/#{@test_repo}/actions/runs/#{@run_id}")

      @client.delete_workflow_run(@test_repo, @run_id)

      assert_requested request
    end
  end

  describe '.workflow_run_logs' do
    it 'returns the location of the workflow run logs' do
      request = stub_head("repos/#{@test_repo}/actions/runs/#{@run_id}/logs")

      @client.workflow_run_logs(@test_repo, @run_id)

      assert_requested request
    end
  end

  describe '.delete_workflow_run_logs' do
    it 'deletes the logs for a workflow run' do
      request = stub_delete("repos/#{@test_repo}/actions/runs/#{@run_id}/logs")

      @client.delete_workflow_run_logs(@test_repo, @run_id)

      assert_requested request
    end
  end

  describe '.workflow_run_usage' do
    it 'returns the requested workflow run usage' do
      request = stub_get("repos/#{@test_repo}/actions/runs/#{@run_id}/timing")

      @client.workflow_run_usage(@test_repo, @run_id)

      assert_requested request
    end
  end
end