Skip to content

Commit

Permalink
Test enhancement (fluid-cloudnative#164)
Browse files Browse the repository at this point in the history
* use different test flags in CI and local enviroment

* move namespace_test to controller folder
  • Loading branch information
ZhongWeichang001 authored Sep 14, 2020
1 parent d37ffbd commit 9871887
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ GIT_VERSION=v0.3.0-${GIT_SHA}
all: manager

# Run tests
test: generate fmt vet
test: generate fmt vet manifests
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go list ./... | grep -v controller | xargs go test ${CI_TEST_FLAGS} ${LOCAL_FLAGS}


# used in CI and simply ignore controller tests which need k8s now.
# maybe incompatible if more end to end tests are added.
unit-test: generate fmt vet
unit-test: generate fmt vet manifests
go list ./... | grep -v controller | xargs go test ${CI_TEST_FLAGS} ${LOCAL_FLAGS}

# Build manager binary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kubeclient
package controllers

import (
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -52,7 +53,7 @@ var _ = BeforeSuite(func(done Done) {

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
}

var err error
Expand Down Expand Up @@ -81,28 +82,20 @@ var _ = AfterSuite(func() {
var _ = Describe("Test namespace", func() {
Context("check if given ns exist", func() {
It("this ns exists,and err should be nil", func() {
err := EnsureNamespace(k8sClient, "default")
err := kubeclient.EnsureNamespace(k8sClient, "default")
Expect(err).NotTo(HaveOccurred())
})

It("try to get a non-existed ns,should fail", func() {
err := EnsureNamespace(k8sClient, time.Now().String())
err := kubeclient.EnsureNamespace(k8sClient, time.Now().String())
Expect(err).Should(HaveOccurred())
})
})
Context("test createnamespace", func() {
namespace := "woohoo"
It("create a new ns,err should be nil", func() {
err := createNamespace(k8sClient, namespace)
Expect(err).NotTo(HaveOccurred())
})
It("check if create ns successfully,err should nil", func() {
err := EnsureNamespace(k8sClient, namespace)
err := kubeclient.EnsureNamespace(k8sClient, namespace)
Expect(err).NotTo(HaveOccurred())
})
It("try to create ns with a conflicted name ,should fail", func() {
err := createNamespace(k8sClient, namespace)
Expect(err).Should(HaveOccurred())
})
})
})

0 comments on commit 9871887

Please sign in to comment.