forked from rook/rook
Do not force unit tests to be run while the rook repo is in the GOPATH. Now that Rook uses go modules, this is no longer necessary. Allow this by creating a helper function that unit tests can use that return the on-host path to the `rook` project root. Followup of https://github.com/rook/rook/pull/7119/commits/15a487cd5aa5d4dc59bc15ef610cb182257d9287 Signed-off-by: Sébastien Han <seb@redhat.com>
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
/*
|
|
Copyright 2020 The Rook Authors. All rights reserved.
|
|
|
|
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.
|
|
*/
|
|
|
|
// Package k8sutil for Kubernetes helpers.
|
|
package k8sutil
|
|
|
|
import (
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/rook/rook/pkg/util"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetServiceMonitor(t *testing.T) {
|
|
projectRoot := util.PathToProjectRoot()
|
|
filePath := path.Join(projectRoot, "/cluster/examples/kubernetes/ceph/monitoring/service-monitor.yaml")
|
|
servicemonitor, err := GetServiceMonitor(filePath)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "rook-ceph-mgr", servicemonitor.GetName())
|
|
assert.Equal(t, "rook-ceph", servicemonitor.GetNamespace())
|
|
assert.NotNil(t, servicemonitor.Spec.NamespaceSelector.MatchNames)
|
|
assert.NotNil(t, servicemonitor.Spec.Endpoints)
|
|
}
|
|
|
|
func TestGetPrometheusRule(t *testing.T) {
|
|
projectRoot := util.PathToProjectRoot()
|
|
filePath := path.Join(projectRoot, "/cluster/examples/kubernetes/ceph/monitoring/prometheus-ceph-v14-rules.yaml")
|
|
rules, err := GetPrometheusRule(filePath)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "prometheus-ceph-rules", rules.GetName())
|
|
assert.Equal(t, "rook-ceph", rules.GetNamespace())
|
|
// Labels should be present as they are used by prometheus for identifying rules
|
|
assert.NotNil(t, rules.GetLabels())
|
|
assert.NotNil(t, rules.Spec.Groups)
|
|
}
|