Skip to content

Commit

Permalink
Hide integration tests behind the integration build tag. (#361)
Browse files Browse the repository at this point in the history
* Hide integration tests behind the integration build tag.

* Re-add the kubernetes_integration_test.go.

* Fix kubernetes_integration_test.go imports.
  • Loading branch information
jbarrick-mesosphere committed Jun 20, 2019
1 parent 75ac0c6 commit b6c233c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 65 deletions.
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ When updating the structs under [APIs](https://github.com/kudobuilder/kudo/blob/

After updating CRD manifests, use `make deploy` to apply the new CRDs to your cluster.

#### Testing

You can run the unit tests:

```
make test
```

Or the integration tests:

```
make integration-test
```

See [the testing documentation](https://kudo.dev/docs/testing) for more details.

### Build and run tests using Docker
If you don't want to install kubebuilder and other dependencies of KUDO locally, you can build KUDO and run the tests inside a Docker container.

Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ all: test manager
test:
go test ./pkg/... ./cmd/... -v -mod=readonly -coverprofile cover.out

.PHONY: integration-test
# Run integration tests
integration-test:
go test -tags integration ./pkg/... ./cmd/... -v -mod=readonly -coverprofile cover-integration.out

.PHONY: test-clean
# Clean test reports
test-clean:
rm -f cover.out
rm -f cover.out cover-integration.out

.PHONY: check-formatting
check-formatting: vet lint staticcheck
Expand Down
12 changes: 0 additions & 12 deletions pkg/test/case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,3 @@ func TestCollectTestStepFiles(t *testing.T) {
})
}
}

func TestRunWithKudo(t *testing.T) {
harness := Harness{
T: t,
CRDDir: "../../config/crds/",
ManifestsDir: "../../config/samples/test-framework/",
TestDirs: []string{"./test_data/"},
StartControlPlane: true,
}

harness.Run()
}
19 changes: 19 additions & 0 deletions pkg/test/harness_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// +build integration

package test

import (
"testing"
)

func TestRunWithKudo(t *testing.T) {
harness := Harness{
T: t,
CRDDir: "../../config/crds/",
ManifestsDir: "../../config/samples/test-framework/",
TestDirs: []string{"./test_data/"},
StartControlPlane: true,
}

harness.Run()
}
60 changes: 60 additions & 0 deletions pkg/test/utils/kubernetes_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// +build integration

package utils

import (
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)

func TestCreateOrUpdate(t *testing.T) {
env := &envtest.Environment{}

config, err := env.Start()
assert.Nil(t, err)

defer env.Stop()

client, err := client.New(config, client.Options{})
assert.Nil(t, err)

// Run the test a bunch of times to try to trigger a conflict and ensure that it handles conflicts properly.
for i := 0; i < 10; i++ {
depToUpdate := WithSpec(NewPod("update-me", fmt.Sprintf("default-%d", i)), map[string]interface{}{
"containers": []map[string]interface{}{
{
"image": "nginx",
"name": "nginx",
},
},
})

assert.Nil(t, CreateOrUpdate(context.TODO(), client, SetAnnotation(depToUpdate, "test", "hi"), true))

quit := make(chan bool)

go func() {
for {
select {
case <-quit:
return
default:
CreateOrUpdate(context.TODO(), client, SetAnnotation(depToUpdate, "test", fmt.Sprintf("%d", i)), false)
time.Sleep(time.Millisecond * 75)
}
}
}()

time.Sleep(time.Millisecond * 50)

assert.Nil(t, CreateOrUpdate(context.TODO(), client, SetAnnotation(depToUpdate, "test", "hello"), true))

quit <- true
}
}
51 changes: 0 additions & 51 deletions pkg/test/utils/kubernetes_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package utils

import (
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)

func TestNamespaced(t *testing.T) {
Expand Down Expand Up @@ -51,49 +46,3 @@ func TestNamespaced(t *testing.T) {
})
}
}

func TestCreateOrUpdate(t *testing.T) {
env := &envtest.Environment{}

config, err := env.Start()
assert.Nil(t, err)

defer env.Stop()

client, err := client.New(config, client.Options{})
assert.Nil(t, err)

// Run the test a bunch of times to try to trigger a conflict and ensure that it handles conflicts properly.
for i := 0; i < 10; i++ {
depToUpdate := WithSpec(NewPod("update-me", fmt.Sprintf("default-%d", i)), map[string]interface{}{
"containers": []map[string]interface{}{
{
"image": "nginx",
"name": "nginx",
},
},
})

assert.Nil(t, CreateOrUpdate(context.TODO(), client, SetAnnotation(depToUpdate, "test", "hi"), true))

quit := make(chan bool)

go func() {
for {
select {
case <-quit:
return
default:
CreateOrUpdate(context.TODO(), client, SetAnnotation(depToUpdate, "test", fmt.Sprintf("%d", i)), false)
time.Sleep(time.Millisecond * 75)
}
}
}()

time.Sleep(time.Millisecond * 50)

assert.Nil(t, CreateOrUpdate(context.TODO(), client, SetAnnotation(depToUpdate, "test", "hello"), true))

quit <- true
}
}
2 changes: 1 addition & 1 deletion test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ COPY config/ config/
COPY pkg/ pkg/
COPY cmd/ cmd/

ENTRYPOINT make test
ENTRYPOINT make integration-test

0 comments on commit b6c233c

Please sign in to comment.