From cb3648afbbd3da90f3f4f2a25f67e81e0eed0472 Mon Sep 17 00:00:00 2001 From: Nikita Korolev Date: Thu, 20 Jun 2024 00:05:27 +0300 Subject: [PATCH 1/5] chore: fix regexp for path .github and add tests Signed-off-by: Nikita Korolev --- tools/addlicense/addlicense_test.go | 82 +++++++++++++++++++++++++++++ tools/addlicense/utils.go | 2 +- tools/addlicense/variables.go | 2 +- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/tools/addlicense/addlicense_test.go b/tools/addlicense/addlicense_test.go index a8d52ee85..4c7aaa6e4 100644 --- a/tools/addlicense/addlicense_test.go +++ b/tools/addlicense/addlicense_test.go @@ -19,6 +19,7 @@ package main import ( "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -222,3 +223,84 @@ print("Hello") }) } } + +func Test_FilesPathWithExtentionRe(t *testing.T) { + filePathCases := []struct { + title string + filePath string + expectedFileToCheckRe bool + }{ + { + title: "Path .github with yaml extention", + filePath: "./.github/workflows/build.yaml", + expectedFileToCheckRe: true, + }, + { + title: "Path with /some/folder/.github yaml extention", + filePath: "/some/folder/.github/workflows/build.yaml", + expectedFileToCheckRe: true, + }, + { + title: "Path with ./.github yml extention", + filePath: "./.github/workflows/build.yml", + expectedFileToCheckRe: true, + }, + { + title: "Path with sh extention", + filePath: "./run.sh", + expectedFileToCheckRe: true, + }, + { + title: "Path with py extention", + filePath: "./scripts/run.py", + expectedFileToCheckRe: true, + }, + { + title: "Path with go extention", + filePath: "./cmds/run.go", + expectedFileToCheckRe: true, + }, + } + + for _, c := range filePathCases { + t.Run(c.title, func(t *testing.T) { + resFilePathMatch := fileToCheckRe.MatchString(c.filePath) + require.Equal(t, c.expectedFileToCheckRe, resFilePathMatch) + + license := getLicenseForFile(c.filePath) + require.NotEmpty(t, license) + assert.Equal(t, CELicenseRe.MatchString(license), true) + }) + } + +} + +func Test_FilesPathNoExtentionRe(t *testing.T) { + filePathCases := []struct { + title string + filePath string + expectedFileToCheckRe bool + }{ + { + title: "Path with no extention", + filePath: "./cmds/enable", + expectedFileToCheckRe: true, + }, + { + title: "Path with no extention root dir", + filePath: "/enable", + expectedFileToCheckRe: true, + }, + } + + for _, c := range filePathCases { + t.Run(c.title, func(t *testing.T) { + resFilePathMatch := fileToCheckRe.MatchString(c.filePath) + require.Equal(t, c.expectedFileToCheckRe, resFilePathMatch) + + license := getLicenseForFile(c.filePath) + require.Empty(t, license) + assert.NotEqual(t, CELicenseRe.MatchString(license), true) + }) + } +} diff --git a/tools/addlicense/utils.go b/tools/addlicense/utils.go index ddbc75629..4929122bd 100644 --- a/tools/addlicense/utils.go +++ b/tools/addlicense/utils.go @@ -42,7 +42,7 @@ func getLicenseForFile(filePath string) string { switch filepath.Ext(filePath) { case ".go": return goLicense - case ".py", ".sh", ".bash", ".zsh": + case ".py", ".sh", ".bash", ".zsh", ".yaml", ".yml": return bashPythonLicense default: return "" diff --git a/tools/addlicense/variables.go b/tools/addlicense/variables.go index 1f261251a..ba8109f80 100644 --- a/tools/addlicense/variables.go +++ b/tools/addlicense/variables.go @@ -47,7 +47,7 @@ var ( // - Ends with .go, .sh, .py // - Is inside a .github directory: scripts, workflows, or workflow_templates subdirectories, // and ends with .js, .yml, .yaml, or .sh -var fileToCheckRe = regexp.MustCompile(`\.go$|/[^/.]+$|\.sh$|\.py$|^\.github/(scripts|workflows|workflow_templates)/.+\.(js|yml|yaml|sh)$`) +var fileToCheckRe = regexp.MustCompile(`\.go$|/[^/.]+$|\.sh$|\.py$|\.github/(scripts|workflows|workflow_templates)/.+\.(js|yml|yaml|sh)$`) // fileToSkipRe matches filenames that will be skipped for adding license, meet the following conditions: // - Directories .github/CODEOWNERS, /docs/ From 73ba02d520164cc2d40e2717744957fc7a8ba898 Mon Sep 17 00:00:00 2001 From: Nikita Korolev Date: Thu, 20 Jun 2024 00:07:02 +0300 Subject: [PATCH 2/5] chore(ci): add licence for github/workflows Signed-off-by: Nikita Korolev --- .github/workflows/dev_auto-pr-author-assign.yml | 14 ++++++++++++++ .github/workflows/dev_build_precache.yml | 14 ++++++++++++++ .../dev_module_build-and-registration.yml | 14 ++++++++++++++ .../dev_module_build-on-self-hosted-runner.yml | 14 ++++++++++++++ .github/workflows/dev_module_build.yml | 14 ++++++++++++++ .github/workflows/dev_registry-cleanup.yml | 14 ++++++++++++++ .../release_module_build-and-registration.yml | 14 ++++++++++++++ .../workflows/release_module_release-channels.yml | 14 ++++++++++++++ .github/workflows/release_release-please.yml | 14 ++++++++++++++ 9 files changed, 126 insertions(+) diff --git a/.github/workflows/dev_auto-pr-author-assign.yml b/.github/workflows/dev_auto-pr-author-assign.yml index a37b1ef4b..f0c1210e0 100644 --- a/.github/workflows/dev_auto-pr-author-assign.yml +++ b/.github/workflows/dev_auto-pr-author-assign.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # .github/workflows/auto-author-assign.yml name: Auto Author Assign diff --git a/.github/workflows/dev_build_precache.yml b/.github/workflows/dev_build_precache.yml index 14bfbff51..8d7f91672 100644 --- a/.github/workflows/dev_build_precache.yml +++ b/.github/workflows/dev_build_precache.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Build main, pre-alpha every 8 hours for dev env: MODULES_REGISTRY: ${{ vars.DEV_REGISTRY }} diff --git a/.github/workflows/dev_module_build-and-registration.yml b/.github/workflows/dev_module_build-and-registration.yml index 6387a501a..ca1daeebc 100644 --- a/.github/workflows/dev_module_build-and-registration.yml +++ b/.github/workflows/dev_module_build-and-registration.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Deploy Dev env: diff --git a/.github/workflows/dev_module_build-on-self-hosted-runner.yml b/.github/workflows/dev_module_build-on-self-hosted-runner.yml index 9829dff4e..277c8fa8a 100644 --- a/.github/workflows/dev_module_build-on-self-hosted-runner.yml +++ b/.github/workflows/dev_module_build-on-self-hosted-runner.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Build and push for dev (Self-hosted) env: diff --git a/.github/workflows/dev_module_build.yml b/.github/workflows/dev_module_build.yml index e7c3276fd..96fcc2623 100644 --- a/.github/workflows/dev_module_build.yml +++ b/.github/workflows/dev_module_build.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Build and push for dev env: diff --git a/.github/workflows/dev_registry-cleanup.yml b/.github/workflows/dev_registry-cleanup.yml index ab46c32d1..09e3fa71f 100644 --- a/.github/workflows/dev_registry-cleanup.yml +++ b/.github/workflows/dev_registry-cleanup.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Cleanup dev registries env: diff --git a/.github/workflows/release_module_build-and-registration.yml b/.github/workflows/release_module_build-and-registration.yml index fdb96f196..ffe21b0ac 100644 --- a/.github/workflows/release_module_build-and-registration.yml +++ b/.github/workflows/release_module_build-and-registration.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Build and push for prod env: diff --git a/.github/workflows/release_module_release-channels.yml b/.github/workflows/release_module_release-channels.yml index 3096e81c9..21f8e5473 100644 --- a/.github/workflows/release_module_release-channels.yml +++ b/.github/workflows/release_module_release-channels.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Deploy Prod env: diff --git a/.github/workflows/release_release-please.yml b/.github/workflows/release_release-please.yml index 91dee5f72..202f22bd5 100644 --- a/.github/workflows/release_release-please.yml +++ b/.github/workflows/release_release-please.yml @@ -1,3 +1,17 @@ +# Copyright 2024 Flant JSC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: Release please on: From a029d62474f808df1c88e8e352d833276b112a04 Mon Sep 17 00:00:00 2001 From: Nikita Korolev Date: Thu, 20 Jun 2024 00:17:05 +0300 Subject: [PATCH 3/5] chore: fix yaml formatting Signed-off-by: Nikita Korolev --- .github/workflows/dev_auto-pr-author-assign.yml | 6 +++--- .github/workflows/dev_build_precache.yml | 6 +++--- .../dev_module_build-and-registration.yml | 6 +++--- .../dev_module_build-on-self-hosted-runner.yml | 6 +++--- .github/workflows/dev_module_build.yml | 6 +++--- .github/workflows/dev_registry-cleanup.yml | 6 +++--- .../release_module_build-and-registration.yml | 6 +++--- .../release_module_release-channels.yml | 6 +++--- .github/workflows/release_release-please.yml | 6 +++--- tools/addlicense/addlicense_test.go | 17 ++++++++--------- 10 files changed, 35 insertions(+), 36 deletions(-) diff --git a/.github/workflows/dev_auto-pr-author-assign.yml b/.github/workflows/dev_auto-pr-author-assign.yml index f0c1210e0..6a44efe56 100644 --- a/.github/workflows/dev_auto-pr-author-assign.yml +++ b/.github/workflows/dev_auto-pr-author-assign.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/dev_build_precache.yml b/.github/workflows/dev_build_precache.yml index 8d7f91672..4a4ec2540 100644 --- a/.github/workflows/dev_build_precache.yml +++ b/.github/workflows/dev_build_precache.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/dev_module_build-and-registration.yml b/.github/workflows/dev_module_build-and-registration.yml index ca1daeebc..76c706fc6 100644 --- a/.github/workflows/dev_module_build-and-registration.yml +++ b/.github/workflows/dev_module_build-and-registration.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/dev_module_build-on-self-hosted-runner.yml b/.github/workflows/dev_module_build-on-self-hosted-runner.yml index 277c8fa8a..61cb6cdd7 100644 --- a/.github/workflows/dev_module_build-on-self-hosted-runner.yml +++ b/.github/workflows/dev_module_build-on-self-hosted-runner.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/dev_module_build.yml b/.github/workflows/dev_module_build.yml index 96fcc2623..4c709083f 100644 --- a/.github/workflows/dev_module_build.yml +++ b/.github/workflows/dev_module_build.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/dev_registry-cleanup.yml b/.github/workflows/dev_registry-cleanup.yml index 09e3fa71f..b5c150f65 100644 --- a/.github/workflows/dev_registry-cleanup.yml +++ b/.github/workflows/dev_registry-cleanup.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/release_module_build-and-registration.yml b/.github/workflows/release_module_build-and-registration.yml index ffe21b0ac..353cfe228 100644 --- a/.github/workflows/release_module_build-and-registration.yml +++ b/.github/workflows/release_module_build-and-registration.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/release_module_release-channels.yml b/.github/workflows/release_module_release-channels.yml index 21f8e5473..381248767 100644 --- a/.github/workflows/release_module_release-channels.yml +++ b/.github/workflows/release_module_release-channels.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/.github/workflows/release_release-please.yml b/.github/workflows/release_release-please.yml index 202f22bd5..f45e94b1d 100644 --- a/.github/workflows/release_release-please.yml +++ b/.github/workflows/release_release-please.yml @@ -1,11 +1,11 @@ # Copyright 2024 Flant JSC -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/tools/addlicense/addlicense_test.go b/tools/addlicense/addlicense_test.go index 4c7aaa6e4..5d3750d02 100644 --- a/tools/addlicense/addlicense_test.go +++ b/tools/addlicense/addlicense_test.go @@ -231,32 +231,32 @@ func Test_FilesPathWithExtentionRe(t *testing.T) { expectedFileToCheckRe bool }{ { - title: "Path .github with yaml extention", + title: "Path .github with yaml extension", filePath: "./.github/workflows/build.yaml", expectedFileToCheckRe: true, }, { - title: "Path with /some/folder/.github yaml extention", + title: "Path with /some/folder/.github yaml extension", filePath: "/some/folder/.github/workflows/build.yaml", expectedFileToCheckRe: true, }, { - title: "Path with ./.github yml extention", + title: "Path with ./.github yml extension", filePath: "./.github/workflows/build.yml", expectedFileToCheckRe: true, }, { - title: "Path with sh extention", + title: "Path with sh extension", filePath: "./run.sh", expectedFileToCheckRe: true, }, { - title: "Path with py extention", + title: "Path with py extension", filePath: "./scripts/run.py", expectedFileToCheckRe: true, }, { - title: "Path with go extention", + title: "Path with go extension", filePath: "./cmds/run.go", expectedFileToCheckRe: true, }, @@ -272,7 +272,6 @@ func Test_FilesPathWithExtentionRe(t *testing.T) { assert.Equal(t, CELicenseRe.MatchString(license), true) }) } - } func Test_FilesPathNoExtentionRe(t *testing.T) { @@ -282,12 +281,12 @@ func Test_FilesPathNoExtentionRe(t *testing.T) { expectedFileToCheckRe bool }{ { - title: "Path with no extention", + title: "Path with no extension", filePath: "./cmds/enable", expectedFileToCheckRe: true, }, { - title: "Path with no extention root dir", + title: "Path with no extension root dir", filePath: "/enable", expectedFileToCheckRe: true, }, From c4713fc89835d1573bf1d09ef569a12c70db0406 Mon Sep 17 00:00:00 2001 From: Nikita Korolev Date: Thu, 20 Jun 2024 00:22:38 +0300 Subject: [PATCH 4/5] chore: resolve comments Signed-off-by: Nikita Korolev --- tools/addlicense/addlicense_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/addlicense/addlicense_test.go b/tools/addlicense/addlicense_test.go index 5d3750d02..42bd30ac9 100644 --- a/tools/addlicense/addlicense_test.go +++ b/tools/addlicense/addlicense_test.go @@ -19,7 +19,6 @@ package main import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -269,7 +268,7 @@ func Test_FilesPathWithExtentionRe(t *testing.T) { license := getLicenseForFile(c.filePath) require.NotEmpty(t, license) - assert.Equal(t, CELicenseRe.MatchString(license), true) + require.Equal(t, CELicenseRe.MatchString(license), true) }) } } @@ -299,7 +298,7 @@ func Test_FilesPathNoExtentionRe(t *testing.T) { license := getLicenseForFile(c.filePath) require.Empty(t, license) - assert.NotEqual(t, CELicenseRe.MatchString(license), true) + require.NotEqual(t, CELicenseRe.MatchString(license), true) }) } } From b91f7be4be5cb9e4bbd8f8a6a9eb2e3c1d38e9a4 Mon Sep 17 00:00:00 2001 From: Nikita Korolev Date: Thu, 20 Jun 2024 12:55:30 +0300 Subject: [PATCH 5/5] chore: resolve comments Signed-off-by: Nikita Korolev --- tools/addlicense/addlicense_test.go | 64 +++++++++++++---------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/tools/addlicense/addlicense_test.go b/tools/addlicense/addlicense_test.go index 42bd30ac9..8a29c8eb0 100644 --- a/tools/addlicense/addlicense_test.go +++ b/tools/addlicense/addlicense_test.go @@ -223,82 +223,74 @@ print("Hello") } } -func Test_FilesPathWithExtentionRe(t *testing.T) { +func Test_FilesPathWithExtensionRe(t *testing.T) { filePathCases := []struct { - title string - filePath string - expectedFileToCheckRe bool + title string + filePath string }{ { - title: "Path .github with yaml extension", - filePath: "./.github/workflows/build.yaml", - expectedFileToCheckRe: true, + title: "Path .github with yaml extension", + filePath: "./.github/workflows/build.yaml", }, { - title: "Path with /some/folder/.github yaml extension", - filePath: "/some/folder/.github/workflows/build.yaml", - expectedFileToCheckRe: true, + title: "Path with /some/folder/.github yaml extension", + filePath: "/some/folder/.github/workflows/build.yaml", }, { - title: "Path with ./.github yml extension", - filePath: "./.github/workflows/build.yml", - expectedFileToCheckRe: true, + title: "Path with ./.github yml extension", + filePath: "./.github/workflows/build.yml", }, { - title: "Path with sh extension", - filePath: "./run.sh", - expectedFileToCheckRe: true, + title: "Path with sh extension", + filePath: "./run.sh", }, { - title: "Path with py extension", - filePath: "./scripts/run.py", - expectedFileToCheckRe: true, + title: "Path with py extension", + filePath: "./scripts/run.py", }, { - title: "Path with go extension", - filePath: "./cmds/run.go", - expectedFileToCheckRe: true, + title: "Path with go extension", + filePath: "./cmds/run.go", }, } for _, c := range filePathCases { t.Run(c.title, func(t *testing.T) { resFilePathMatch := fileToCheckRe.MatchString(c.filePath) - require.Equal(t, c.expectedFileToCheckRe, resFilePathMatch) + require.True(t, resFilePathMatch) + // Copyright is maintained for files with an extension license := getLicenseForFile(c.filePath) require.NotEmpty(t, license) - require.Equal(t, CELicenseRe.MatchString(license), true) + require.True(t, CELicenseRe.MatchString(license)) }) } } -func Test_FilesPathNoExtentionRe(t *testing.T) { +func Test_FilesPathNoExtensionRe(t *testing.T) { filePathCases := []struct { - title string - filePath string - expectedFileToCheckRe bool + title string + filePath string }{ { - title: "Path with no extension", - filePath: "./cmds/enable", - expectedFileToCheckRe: true, + title: "Path with no extension", + filePath: "./cmds/enable", }, { - title: "Path with no extension root dir", - filePath: "/enable", - expectedFileToCheckRe: true, + title: "Path with no extension root dir", + filePath: "/enable", }, } for _, c := range filePathCases { t.Run(c.title, func(t *testing.T) { resFilePathMatch := fileToCheckRe.MatchString(c.filePath) - require.Equal(t, c.expectedFileToCheckRe, resFilePathMatch) + require.True(t, resFilePathMatch) + // Copyright is not maintained for files without an extension license := getLicenseForFile(c.filePath) require.Empty(t, license) - require.NotEqual(t, CELicenseRe.MatchString(license), true) + require.False(t, CELicenseRe.MatchString(license)) }) } }