File: ghes_manage_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 (122 lines) | stat: -rw-r--r-- 4,956 bytes parent folder | download
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
# frozen_string_literal: true

describe Octokit::ManageGHESClient::ManageAPI do
  before do
    Octokit.reset!
    @manage_ghes = manage_ghes_client
    @license = 'spec/fixtures/github-enterprise.ghl'
  end

  describe '.maintenance_mode', :vcr do
    it 'get maintenance mode' do
      @manage_ghes.maintenance_mode
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body).to be_kind_of Array
      expect(@manage_ghes.last_response.body.first['status']).to be_kind_of String
      assert_requested :get, github_manage_ghes_url('/manage/v1/maintenance')
    end
  end # .maintenance_mode

  describe '.set_maintenance_mode', :vcr do
    it 'enable maintenance mode' do
      @manage_ghes.set_maintenance_mode(true)
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body.first['message']).to eq('maintenance mode enabled')
      assert_requested :post, github_manage_ghes_url('/manage/v1/maintenance')
    end
    it 'disable maintenance mode' do
      @manage_ghes.set_maintenance_mode(false)
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body.first['message']).to eq('maintenance mode disabled')
      assert_requested :post, github_manage_ghes_url('/manage/v1/maintenance')
    end
  end # .set_maintenance_mode

  describe '.upload_license', :vcr do
    it 'upload a new license' do
      @manage_ghes.upload_license(@license)
      expect(@manage_ghes.last_response.status).to eq(202)
      assert_requested :post, github_manage_ghes_url('/manage/v1/config/init')
    end

    it 'raises an error if the faraday-multipart gem is not installed' do
      middleware_key = :multipart
      middleware = Faraday::Request.unregister_middleware(middleware_key)

      expect { @manage_ghes.upload_license(@license) }.to raise_error Faraday::Error
    ensure
      Faraday::Request.register_middleware(middleware_key => middleware) if middleware
    end
  end # .upload_license

  describe '.start_configuration', :vcr do
    it 'start a ghe-config-apply' do
      @manage_ghes.start_configuration
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body['run_id']).to be_kind_of String
      assert_requested :post, github_manage_ghes_url('/manage/v1/config/apply')
    end
  end # .start_configuration

  describe '.config_status', :vcr do
    it 'get ghe-config-apply status' do
      @manage_ghes.config_status
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body['run_id']).to be_kind_of String
      expect(@manage_ghes.last_response.body['nodes']).to be_kind_of Array
      assert_requested :get, github_manage_ghes_url('/manage/v1/config/apply')
    end
  end # .config_status

  describe '.settings', :vcr do
    it 'get settings' do
      @manage_ghes.settings
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body).to be_kind_of Hash
      expect(@manage_ghes.last_response.body['abuse_rate_limiting']['requests_per_minute']).to be_kind_of Integer
      assert_requested :get, github_manage_ghes_url('/manage/v1/config/settings')
    end
  end # .settings

  describe '.edit_settings', :vcr do
    it 'set settings' do
      @manage_ghes.edit_settings({ 'abuse_rate_limiting' => { 'requests_per_minute' => 901 } })
      expect(@manage_ghes.last_response.status).to eq(204)
      assert_requested :put, github_manage_ghes_url('/manage/v1/config/settings')
    end
  end # .edit_settings

  describe '.authorized_keys', :vcr do
    it 'get authorized keys' do
      @manage_ghes.authorized_keys
      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body).to be_kind_of Array
      expect(@manage_ghes.last_response.body.first['key']).to be_kind_of String
      assert_requested :get, github_manage_ghes_url('/manage/v1/access/ssh')
    end
  end # .authorized_keys

  describe '.add_authorized_key', :vcr do
    it 'adds a new authorized SSH keys (via a file path)' do
      key = 'spec/fixtures/fake_key.pub'
      @manage_ghes.add_authorized_key(key)

      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body.first['message']).to eq('SSH key added successfully')

      assert_requested :post, github_manage_ghes_url('/manage/v1/access/ssh')
    end
  end # .add_authorized_key

  describe '.remove_authorized_key', :vcr do
    it 'delete an authorized SSH key (via a file path)' do
      key = 'spec/fixtures/fake_key.pub'
      @manage_ghes.remove_authorized_key(key)

      expect(@manage_ghes.last_response.status).to eq(200)
      expect(@manage_ghes.last_response.body.first['message']).to eq('SSH key removed successfully')

      assert_requested :delete, github_manage_ghes_url('/manage/v1/access/ssh')
    end
  end # .remove_authorized_key
end