Commit 9d7def72 authored by Kerri Miller's avatar Kerri Miller

Improve testing & expand sectional examples

Doing this in one big gulp because I wanted to reuse tests in order to
insure that sectional and non-sectional codeowners files are processed
similarly
parent cdbe83ac
ee/ @gl-admin
# This is an example code owners file, lines starting with a `#` will
# be ignored.
# app/ @commented-rule
# We can specify a default match using wildcards:
* @default-codeowner
# Rules defined later in the file take precedence over the rules
# defined before.
# This will match all files for which the file name ends in `.rb`
*.rb @ruby-owner
# Files with a `#` can still be accesssed by escaping the pound sign
\#file_with_pound.rb @owner-file-with-pound
# Multiple codeowners can be specified, separated by whitespace
CODEOWNERS @multiple @owners @tab-separated
# Both usernames or email addresses can be used to match
# users. Everything else will be ignored. For example this will
# specify `@legal` and a user with email `janedoe@gitlab.com` as the
# owner for the LICENSE file
LICENSE @legal this does not match janedoe@gitlab.com
# Ending a path in a `/` will specify the code owners for every file
# nested in that directory, on any level
/docs/ @all-docs
# Ending a path in `/*` will specify code owners for every file in
# that directory, but not nested deeper. This will match
# `docs/index.md` but not `docs/projects/index.md`
/docs/* @root-docs
# This will make a `lib` directory nested anywhere in the repository
# match
lib/ @lib-owner
# This will only match a `config` directory in the root of the
# repository
/config/ @config-owner
# If the path contains spaces, these need to be escaped like this:
path\ with\ spaces/ @space-owner
[Documentation]
ee/docs @gl-docs
......
ee/ @gl-admin
# This is an example code owners file, lines starting with a `#` will
# be ignored.
# app/ @commented-rule
# We can specify a default match using wildcards:
* @default-codeowner
# Rules defined later in the file take precedence over the rules
# defined before.
# This will match all files for which the file name ends in `.rb`
*.rb @ruby-owner
# Files with a `#` can still be accesssed by escaping the pound sign
\#file_with_pound.rb @owner-file-with-pound
# Multiple codeowners can be specified, separated by whitespace
CODEOWNERS @multiple @owners @tab-separated
# Both usernames or email addresses can be used to match
# users. Everything else will be ignored. For example this will
# specify `@legal` and a user with email `janedoe@gitlab.com` as the
# owner for the LICENSE file
LICENSE @legal this does not match janedoe@gitlab.com
# Ending a path in a `/` will specify the code owners for every file
# nested in that directory, on any level
/docs/ @all-docs
# Ending a path in `/*` will specify code owners for every file in
# that directory, but not nested deeper. This will match
# `docs/index.md` but not `docs/projects/index.md`
/docs/* @root-docs
# This will make a `lib` directory nested anywhere in the repository
# match
lib/ @lib-owner
# This will only match a `config` directory in the root of the
# repository
/config/ @config-owner
# If the path contains spaces, these need to be escaped like this:
path\ with\ spaces/ @space-owner
[Documentation]
ee/docs @gl-docs
......
......@@ -52,8 +52,21 @@ describe Gitlab::CodeOwners::File do
expect(data.keys).to contain_exactly("codeowners", "Documentation", "Database")
end
codeowners_section_paths = [
"/**/#file_with_pound.rb", "/**/*", "/**/*.rb", "/**/CODEOWNERS",
"/**/LICENSE", "/**/lib/**/*", "/**/path with spaces/**/*",
"/config/**/*", "/docs/*", "/docs/**/*"
]
codeowners_section_owners = [
"@all-docs", "@config-owner", "@default-codeowner",
"@legal this does not match janedoe@gitlab.com", "@lib-owner",
"@multiple @owners\t@tab-separated", "@owner-file-with-pound",
"@root-docs", "@ruby-owner", "@space-owner"
]
where(:section, :patterns, :owners) do
"codeowners" | ["/**/ee/**/*"] | ["@gl-admin"]
"codeowners" | codeowners_section_paths | codeowners_section_owners
"Documentation" | ["/**/README.md", "/**/ee/docs", "/**/docs"] | ["@gl-docs"]
"Database" | ["/**/README.md", "/**/model/db"] | ["@gl-database"]
end
......@@ -226,7 +239,7 @@ describe Gitlab::CodeOwners::File do
end
it 'correctly matches paths with spaces' do
entry = file.entry_for_path('path with spaces/README.md').first
entry = file.entry_for_path('path with spaces/docs.md').first
expect(entry.owner_line).to eq('@space-owner')
end
......@@ -285,15 +298,35 @@ describe Gitlab::CodeOwners::File do
stub_feature_flags(sectional_codeowners: true)
end
context "when CODEOWNERS file contains no sections" do
it_behaves_like "returns expected matches"
end
context "when CODEOWNERS file contains multiple sections" do
let(:file_content) do
File.read(Rails.root.join("ee", "spec", "fixtures", "sectional_codeowners_example"))
end
it_behaves_like "returns expected matches"
end
end
context "when feature flag `:sectional_codeowners` is disabled" do
before do
stub_feature_flags(sectional_codeowners: false)
end
context "when CODEOWNERS file contains no sections" do
it_behaves_like "returns expected matches"
end
context "when CODEOWNERS file contains multiple sections" do
let(:file_content) do
File.read(Rails.root.join("ee", "spec", "fixtures", "sectional_codeowners_example"))
end
it_behaves_like "returns expected matches"
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment