forked from mongodb/atlas-cli-plugin-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
name: Code Health | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
pull-requests: write # For PR-specific operations | ||
issues: write # For commenting functionality | ||
jobs: | ||
golangci: | ||
name: lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: GitHubSecurityLab/actions-permissions/monitor@v1 | ||
with: | ||
config: ${{ vars.PERMISSIONS_CONFIG }} | ||
- uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache: false # see https://github.com/golangci/golangci-lint-action/issues/807 | ||
- name: golangci-lint | ||
uses: golangci/[email protected] | ||
with: | ||
version: v1.61.0 | ||
unit-tests: | ||
env: | ||
COVERAGE: coverage.out | ||
TEST_CMD: gotestsum --junitfile unit-tests.xml --format standard-verbose -- | ||
UNIT_TAGS: unit | ||
INTEGRATION_TAGS: integration | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: GitHubSecurityLab/actions-permissions/monitor@v1 | ||
if: ${{ matrix.os=='ubuntu-latest' }} | ||
with: | ||
config: ${{ vars.PERMISSIONS_CONFIG }} | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
- run: go install gotest.tools/gotestsum@latest | ||
- run: make unit-test | ||
- name: Test Summary | ||
id: test_summary | ||
uses: test-summary/[email protected] | ||
with: | ||
paths: unit-tests.xml | ||
if: always() && matrix.os == 'ubuntu-latest' | ||
- name: Upload coverage file | ||
if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-file | ||
path: coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2024 MongoDB Inc | ||
# | ||
# 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. | ||
|
||
set -Eeou pipefail | ||
|
||
find_files() { | ||
find . -not \( \ | ||
\( \ | ||
-wholename '*mock*' \ | ||
-o -wholename '*third_party*' \ | ||
\) -prune \ | ||
\) \ | ||
\( -name '*.go' -o -name '*.sh' \) | ||
} | ||
|
||
for FILE in $(find_files); do | ||
addlicense -c "MongoDB Inc" -check "${FILE}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 MongoDB Inc | ||
// | ||
// 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. | ||
|
||
//go:build unit | ||
|
||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetOperatorMajorVersion(t *testing.T) { | ||
t.Run("should return major when version has minor different of 0", func(t *testing.T) { | ||
assert.Equal(t, "1.7.0", getOperatorMajorVersion("mongodb/mongodb-atlas-kubernetes-operator:1.7.1")) | ||
}) | ||
|
||
t.Run("should return same major version when minor is 0", func(t *testing.T) { | ||
assert.Equal(t, "1.7.0", getOperatorMajorVersion("mongodb/mongodb-atlas-kubernetes-operator:1.7.0")) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2022 MongoDB Inc | ||
// | ||
// 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. | ||
|
||
//go:build unit | ||
|
||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidNamespace(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
targetNamespace string | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "Valid Namespace", | ||
targetNamespace: "valid-namespace", | ||
expectedErr: "", | ||
}, | ||
{ | ||
name: "Valid Empty Namespace", | ||
targetNamespace: "", | ||
expectedErr: "", | ||
}, | ||
{ | ||
name: "Invalid Namespace with special characters", | ||
targetNamespace: "invalid_namespace!", | ||
expectedErr: "targetNamespace parameter is invalid: [a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]", | ||
}, | ||
{ | ||
name: "Invalid Namespace starting with non-alphanumeric", | ||
targetNamespace: "-invalidnamespace", | ||
expectedErr: "targetNamespace parameter is invalid: [a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]", | ||
}, | ||
{ | ||
name: "Invalid Namespace ending with non-alphanumeric", | ||
targetNamespace: "invalidnamespace-", | ||
expectedErr: "targetNamespace parameter is invalid: [a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]", | ||
}, | ||
{ | ||
name: "Invalid Namespace with uppercase letters", | ||
targetNamespace: "InvalidNamespace", | ||
expectedErr: "targetNamespace parameter is invalid: [a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')]", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
opts := &GenerateOpts{ | ||
targetNamespace: tt.targetNamespace, | ||
} | ||
err := opts.ValidateTargetNamespace() | ||
|
||
if tt.expectedErr == "" { | ||
assert.NoError(t, err) | ||
} else { | ||
assert.EqualError(t, err, tt.expectedErr) | ||
} | ||
}) | ||
} | ||
} |