Skip to content

Commit

Permalink
[yegor256#312] add test for gitlab client
Browse files Browse the repository at this point in the history
  • Loading branch information
mbao01 committed Jun 1, 2022
1 parent f323ef8 commit 6513f32
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 0 deletions.
134 changes: 134 additions & 0 deletions test/fake_gitlab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Copyright (c) 2016-2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

class FakeGitlab
attr_reader :name, :repo

def initialize(options = {})
@name = 'GITLAB'
@repositories = options[:repositories] || []
@repo = options[:repo]
end

def repositories(user = nil, _options = {})
return @repositories unless user
end

def issue(_)
{
state: 'open',
author: {
id: '1',
username: 'yegor256'
},
milestone: {
number: 1,
title: 'v0.1'
}
}
end

def close_issue(_); end

def create_issue(_)
{
number: 1,
html_url: 'url'
}
end

def update_issue(_, _); end

def labels
[
{
id: ``,
name: 'Dev',
color: '#ff00ff'
}
]
end

def add_label(_, _); end

def add_labels_to_an_issue(_, _); end

def add_comment(_, _); end

def create_commit_comment(_, _)
{
html_url: 'url'
}
end

def list_commits
[
{
sha: '123456',
html_url: 'url'
}
]
end

def user(_)
{
name: 'foobar',
email: '[email protected]'
}
end

def star; end

def repository(_ = nil)
{
private: false
}
rescue Gitlab::Error::NotFound => e
raise "Repository #{name} is not available: #{e.message}"
end

def repository_link
"https://gitlab.com/#{@repo.name}"
end

def collaborators_link
"https://gitlab.com/#{@repo.name}/project_members"
end

def file_link(file)
"https://gitlab.com/#{@repo.name}/blob/#{@repo.master}/#{file})"
end

def puzzle_link_for_commit(sha, file, start, stop)
"https://gitlab.com/#{@repo.name}/blob/#{sha}/#{file}#L#{start}-L#{stop}"
end

def issue_link(issue_id)
"https://gitlab.com/#{@repo.name}/issues/#{issue_id}"
end

private

def git_repo
# Output:
# repo -> GitRepo
raise NotImplementedError, 'You must implement this method'
end
end
36 changes: 36 additions & 0 deletions test/test_gitlab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2016-2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'test/unit'
require_relative 'test__helper'
require_relative '../objects/clients/gitlab'

# Github test.
# Author:: Yegor Bugayenko ([email protected])
# Copyright:: Copyright (c) 2016-2022 Yegor Bugayenko
# License:: MIT
class TestGitlab < Test::Unit::TestCase
def test_configures_everything_right
gitlab = GitlabClient.new.client
assert_raises Gitlab::Error::MissingCredentials do
gitlab.user('0pdd')['username']
end
end
end

0 comments on commit 6513f32

Please sign in to comment.