Skip to content

Commit

Permalink
Refactor all tests to e2edescribe
Browse files Browse the repository at this point in the history
  • Loading branch information
aensidhe committed Mar 14, 2017
1 parent 70c9896 commit 0943d84
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 256 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ ut: vendor

.PHONY: test-containerized
## Run the tests in a container. Useful for CI, Mac dev.
test-containerized: vendor run-kubernetes-master
test-containerized: vendor run-etcd run-kubernetes-master
-mkdir -p .go-pkg-cache
docker run --rm --privileged --net=host \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-v $(CURDIR)/.go-pkg-cache:/go/pkg/:rw \
-v $(CURDIR):/go/src/github.com/$(PACKAGE_NAME):rw \
$(CALICO_BUILD) sh -c 'cd /go/src/github.com/$(PACKAGE_NAME) && make WHAT=$(WHAT) ut'
$(CALICO_BUILD) sh -c 'cd /go/src/github.com/$(PACKAGE_NAME) && make WHAT=$(WHAT) SKIP=$(SKIP) ut'

## Run etcd as a container
run-etcd: stop-etcd
Expand All @@ -44,7 +44,7 @@ run-etcd: stop-etcd
--advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379,http://$(LOCAL_IP_ENV):4001,http://127.0.0.1:4001" \
--listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001"

run-kubernetes-master: stop-kubernetes-master run-etcd
run-kubernetes-master: stop-kubernetes-master
# Run the kubelet which will launch the master components in a pod.
docker run \
-v /:/rootfs:ro \
Expand Down
3 changes: 2 additions & 1 deletion git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ exec 1>&2

changed_files=$(git diff --cached --name-only)
changed_go_files=$(git diff --cached --name-only | grep -E '.go$' || true)
all_go_files=$(find -name '*.go' | grep -v /vendor/)

all_go_files=$(find . -name '*.go' | grep -v /vendor/)

copyright_check_failed=false
copyright_owner="Tigera, Inc"
Expand Down
91 changes: 42 additions & 49 deletions lib/backend/backend_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Copyright (c) 2016-2017 Tigera, Inc. 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.
Expand All @@ -18,54 +18,49 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/projectcalico/libcalico-go/lib/backend/etcd"
"github.com/projectcalico/libcalico-go/lib/api"
bapi "github.com/projectcalico/libcalico-go/lib/backend/api"
"github.com/projectcalico/libcalico-go/lib/backend/model"
"github.com/projectcalico/libcalico-go/lib/testutils"
)

// Setting localhost as the etcd endpoint location since that's where `make run-etcd` runs it.
var etcdConfig = &etcd.EtcdConfig{
EtcdEndpoints: "http://127.0.0.1:2379",
}

var _ = Describe("Backend tests", func() {
etcdClient, _ := etcd.NewEtcdClient(etcdConfig)

var _ = testutils.E2eDatastoreDescribe("Backend tests", testutils.DatastoreEtcdV2, func(config api.CalicoAPIConfig) {
var (
block model.KVPair
err error
block model.KVPair
client bapi.Client
err error
)

BeforeEach(func() {
testutils.CleanEtcd()

c := testutils.CreateCleanClient(config)
client = c.Backend
block = model.KVPair{
Key: model.BlockKey{
CIDR: testutils.MustParseNetwork("10.0.0.0/26"),
},
Value: model.AllocationBlock{
Value: &model.AllocationBlock{
CIDR: testutils.MustParseNetwork("10.0.0.0/26"),
},
}

_, err = etcdClient.Create(&block)
_, err = client.Create(&block)
Expect(err).NotTo(HaveOccurred())
})

Describe("Create", func() {

It("persists a new kv pair", func() {
kv, err := etcdClient.Get(block.Key)
kv, err := client.Get(block.Key)
Expect(err).NotTo(HaveOccurred())

expectedCIDR := kv.Value.(*model.AllocationBlock).CIDR
persitedCIRD := block.Value.(model.AllocationBlock).CIDR
persitedCIDR := block.Value.(*model.AllocationBlock).CIDR

Expect(expectedCIDR).To(Equal(persitedCIRD))
Expect(expectedCIDR).To(Equal(persitedCIDR))
})

It("sets revision field", func() {
kv, err := etcdClient.Get(block.Key)
kv, err := client.Get(block.Key)

Expect(err).NotTo(HaveOccurred())
Expect(kv.Revision).NotTo(BeNil())
Expand All @@ -76,29 +71,29 @@ var _ = Describe("Backend tests", func() {
Describe("Update", func() {

It("updates a kv pair", func() {
block.Value = model.AllocationBlock{
block.Value = &model.AllocationBlock{
CIDR: testutils.MustParseNetwork("192.168.0.0/26"),
}

kv, err := etcdClient.Update(&block)
kv, err := client.Update(&block)
Expect(err).NotTo(HaveOccurred())

expectedCIDR := kv.Value.(model.AllocationBlock).CIDR
persitedCIRD := block.Value.(model.AllocationBlock).CIDR
expectedCIDR := kv.Value.(*model.AllocationBlock).CIDR
persitedCIDR := block.Value.(*model.AllocationBlock).CIDR

Expect(expectedCIDR).To(Equal(persitedCIRD))
Expect(expectedCIDR).To(Equal(persitedCIDR))
})

It("sets revision field", func() {
kv, err := etcdClient.Update(&block)
kv, err := client.Update(&block)

Expect(err).NotTo(HaveOccurred())
Expect(kv.Revision).NotTo(BeNil())
})

It("validates revision field", func() {
block.Revision = uint64(1000)
_, err := etcdClient.Update(&block)
_, err := client.Update(&block)
Expect(err).To(HaveOccurred())
})

Expand All @@ -107,47 +102,47 @@ var _ = Describe("Backend tests", func() {
Describe("Apply", func() {

It("updates a kv pair", func() {
block.Value = model.AllocationBlock{
block.Value = &model.AllocationBlock{
CIDR: testutils.MustParseNetwork("192.168.0.0/26"),
}

kv, err := etcdClient.Apply(&block)
kv, err := client.Apply(&block)
Expect(err).NotTo(HaveOccurred())

expectedCIDR := kv.Value.(model.AllocationBlock).CIDR
persitedCIRD := block.Value.(model.AllocationBlock).CIDR
expectedCIDR := kv.Value.(*model.AllocationBlock).CIDR
persitedCIDR := block.Value.(*model.AllocationBlock).CIDR

Expect(expectedCIDR).To(Equal(persitedCIRD))
Expect(expectedCIDR).To(Equal(persitedCIDR))
})

It("creates a kv pair", func() {
block.Key = model.BlockKey{
CIDR: testutils.MustParseNetwork("192.168.0.0/26"),
}

kv, err := etcdClient.Apply(&block)
kv, err := client.Apply(&block)
Expect(err).NotTo(HaveOccurred())

expectedCIDR := kv.Value.(model.AllocationBlock).CIDR
persitedCIRD := block.Value.(model.AllocationBlock).CIDR
expectedCIDR := kv.Value.(*model.AllocationBlock).CIDR
persitedCIDR := block.Value.(*model.AllocationBlock).CIDR

Expect(expectedCIDR).To(Equal(persitedCIRD))
Expect(expectedCIDR).To(Equal(persitedCIDR))
})

It("sets revision field", func() {
block.Value = model.AllocationBlock{
block.Value = &model.AllocationBlock{
CIDR: testutils.MustParseNetwork("192.168.0.0/26"),
}

kv, err := etcdClient.Apply(&block)
kv, err := client.Apply(&block)

Expect(err).NotTo(HaveOccurred())
Expect(kv.Revision).NotTo(BeNil())
})

It("validates revision field", func() {
block.Revision = uint64(1000)
_, err := etcdClient.Apply(&block)
_, err := client.Apply(&block)
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -156,10 +151,10 @@ var _ = Describe("Backend tests", func() {
Describe("Delete", func() {

It("deletes the kv pair", func() {
err := etcdClient.Delete(&block)
err := client.Delete(&block)
Expect(err).NotTo(HaveOccurred())

_, err = etcdClient.Get(block.Key)
_, err = client.Get(block.Key)
Expect(err).To(HaveOccurred())
})

Expand All @@ -170,15 +165,13 @@ var _ = Describe("Backend tests", func() {
IPVersion: 4,
}

bl, err := etcdClient.List(blockListOpt)
It("List", func() {
bl, err := client.List(blockListOpt)
Expect(err).NotTo(HaveOccurred())

for _, blv := range bl {
It("sets revision field", func() {
Expect(err).NotTo(HaveOccurred())
for _, blv := range bl {
Expect(blv.Revision).NotTo(BeNil())
})
}

}
})
})

})
14 changes: 3 additions & 11 deletions lib/client/bgppeer_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Copyright (c) 2016-2017 Tigera, Inc. 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.
Expand Down Expand Up @@ -46,19 +46,11 @@ import (
"github.com/projectcalico/libcalico-go/lib/testutils"
)

var _ = Describe("BGPPeer tests", func() {
var _ = testutils.E2eDatastoreDescribe("BGPPeer tests", testutils.DatastoreEtcdV2, func(config api.CalicoAPIConfig) {

DescribeTable("BGPPeer e2e tests",
func(meta1, meta2 api.BGPPeerMetadata, spec1, spec2 api.BGPPeerSpec) {

// Erase etcd clean.
testutils.CleanEtcd()

// Create a new client.
c, err := testutils.NewClient("")
if err != nil {
log.Println("Error creating client:", err)
}
c := testutils.CreateCleanClient(config)
By("Updating the BGPPeer before it is created")
_, outError := c.BGPPeers().Update(&api.BGPPeer{Metadata: meta1, Spec: spec1})

Expand Down
11 changes: 4 additions & 7 deletions lib/client/config_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Copyright (c) 2016-2017 Tigera, Inc. 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.
Expand All @@ -22,22 +22,19 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/projectcalico/libcalico-go/lib/api"
"github.com/projectcalico/libcalico-go/lib/client"
"github.com/projectcalico/libcalico-go/lib/net"
"github.com/projectcalico/libcalico-go/lib/numorstring"
"github.com/projectcalico/libcalico-go/lib/testutils"
)

var _ = Describe("with config option API tests", func() {
var _ = testutils.E2eDatastoreDescribe("with config option API tests", testutils.DatastoreEtcdV2, func(calicoConfig api.CalicoAPIConfig) {

var config client.ConfigInterface

BeforeEach(func() {
// Erase etcd clean
testutils.CleanEtcd()

c, err := testutils.NewClient("")
Expect(err).NotTo(HaveOccurred())
c := testutils.CreateCleanClient(calicoConfig)
config = c.Config()
})

Expand Down
13 changes: 3 additions & 10 deletions lib/client/hostendpoint_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016 Tigera, Inc. All rights reserved.
// Copyright (c) 2016-2017 Tigera, Inc. 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.
Expand Down Expand Up @@ -48,19 +48,12 @@ import (
cnet "github.com/projectcalico/libcalico-go/lib/net"
)

var _ = Describe("HostEndpoint tests", func() {
var _ = testutils.E2eDatastoreDescribe("HostEndpoint tests", testutils.DatastoreEtcdV2, func(config api.CalicoAPIConfig) {

DescribeTable("HostEndpoint e2e tests",
func(meta1, meta2 api.HostEndpointMetadata, spec1, spec2 api.HostEndpointSpec) {

// Erase etcd clean.
testutils.CleanEtcd()

// Create a new client.
c, err := testutils.NewClient("")
if err != nil {
log.Println("Error creating client:", err)
}
c := testutils.CreateCleanClient(config)
By("Updating the HostEndpoint before it is created")
_, outError := c.HostEndpoints().Update(&api.HostEndpoint{Metadata: meta1, Spec: spec1})

Expand Down
Loading

0 comments on commit 0943d84

Please sign in to comment.