diff --git a/release-notifier/internal/k8s/k8snotifier_test.go b/release-notifier/internal/k8s/k8snotifier_test.go new file mode 100644 index 00000000..2fba7aa4 --- /dev/null +++ b/release-notifier/internal/k8s/k8snotifier_test.go @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + ******************************************************************************/ + +package k8s + +import ( + "regexp" + "testing" +) + +func TestShouldPassIfNewReleaseIsSemVer(t *testing.T) { + // Semantic Versioning schema regex + const regexPattern = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` + + newRelease := GetLatestRel() + if match, _ := regexp.MatchString(regexPattern, newRelease); !match { + t.Errorf("Test should pass, it returns semver string.") + } + +} diff --git a/release-notifier/internal/psql/psqnotifier_test.go b/release-notifier/internal/psql/psqnotifier_test.go new file mode 100644 index 00000000..9ef64c5d --- /dev/null +++ b/release-notifier/internal/psql/psqnotifier_test.go @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://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. + * + * SPDX-License-Identifier: Apache-2.0 + ******************************************************************************/ + +package psql + +import ( + "regexp" + "testing" +) + +func TestShouldPassIfNewReleaseIsSemVer(t *testing.T) { + // Semantic Versioning schema regex + const regexPattern = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` + + newRelease := GetLatestRel() + if match, _ := regexp.MatchString(regexPattern, newRelease); !match { + t.Errorf("Test should pass, it returns semver string.") + } + +}