Skip to content

Commit

Permalink
Remove old integration tests that use fake K8s and Slack APIs #627
Browse files Browse the repository at this point in the history
##### ISSUE TYPE
 - Feature Pull Request

##### SUMMARY

~⚠️ This PR waits for #624 to be merged.~

- Remove old integration tests that use fake K8s and Slack APIs

As now there are new E2E tests (see #624), we can delete old tests and enable `-race` flag to make sure to fix any found race issues (whenever it is in tests or tested code).

There is still a chance that such race conditions exist in the code, however we will fix all found issues during increasing coverage in #589.

Resolves #615
Resolves #592
  • Loading branch information
pkosiec committed Jul 1, 2022
1 parent aebf4b2 commit e683937
Show file tree
Hide file tree
Showing 26 changed files with 42 additions and 2,118 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/branch-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_TESTER_APP_TOKEN: ${{ secrets.SLACK_TESTER_APP_TOKEN }}
run: |
helm repo add infracloudio https://infracloudio.github.io/charts
helm repo update
helm install botkube --namespace botkube infracloudio/botkube --version ${HELM_CHART_VERSION} --wait --create-namespace \
helm install botkube --namespace botkube ./helm/botkube --wait --create-namespace \
-f ./helm/botkube/e2e-test-values.yaml \
--set communications.slack.token="${SLACK_BOT_TOKEN}" \
--set image.registry="${IMAGE_REGISTRY}" \
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ builds:
- id: botkube-test
command: test
binary: botkube-e2e.test
main: ./tests/e2e/
main: ./test/e2e/
no_main_check: true
tags:
- integration
Expand Down
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ lint-fix:
@golangci-lint run --fix "./..."

# test
# TODO: Enable -race flag when https://github.com/infracloudio/botkube/issues/592 is resolved
test: system-check
@echo "Starting unit and integration tests"
@go test -v ./...
@go test -v -race ./...

test-integration: system-check
@go test -v -tags=integration -race -count=1 ./tests/...
@go test -v -tags=integration -race -count=1 ./test/...

# Build the binary
build: pre-build
Expand Down Expand Up @@ -71,10 +69,6 @@ save-images:
load-and-push-images:
@./hack/goreleaser.sh load_and_push_images

# TODO(https://github.com/infracloudio/botkube/pull/627): Backward compatibility; Remove these targets after merge to `develop`
save-pr-image:
@./hack/goreleaser.sh save_pr_image

# system checks
system-check:
@echo "Checking system information"
Expand Down
27 changes: 0 additions & 27 deletions hack/goreleaser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,6 @@ release_snapshot() {
docker manifest push ${IMAGE_REGISTRY}/${IMAGE_REPOSITORY}:${GORELEASER_CURRENT_TAG}
}

# TODO(https://github.com/infracloudio/botkube/pull/627): Backward compatibility; Remove these targets after merge to `develop`
save_pr_image() {
IMAGE_REGISTRY="ghcr.io/infracloudio"
IMAGE_NAME="botkube"

prepare

if [ -z "${PR_NUMBER}" ]
then
echo "Missing PR_NUMBER."
exit 1
fi

export GORELEASER_CURRENT_TAG=${PR_NUMBER}-PR
goreleaser release --rm-dist --snapshot --skip-publish

# Re-tag with 'pr' prefix
docker tag ${IMAGE_REGISTRY}/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-amd64 ${IMAGE_REGISTRY}/pr/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-amd64
docker tag ${IMAGE_REGISTRY}/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-arm64 ${IMAGE_REGISTRY}/pr/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-arm64
docker tag ${IMAGE_REGISTRY}/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-armv7 ${IMAGE_REGISTRY}/pr/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-armv7

# Push images
docker save ${IMAGE_REGISTRY}/pr/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-amd64 > /tmp/${IMAGE_NAME}-amd64.tar
docker save ${IMAGE_REGISTRY}/pr/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-arm64 > /tmp/${IMAGE_NAME}-arm64.tar
docker save ${IMAGE_REGISTRY}/pr/${IMAGE_NAME}:${GORELEASER_CURRENT_TAG}-armv7 > /tmp/${IMAGE_NAME}-armv7.tar
}

save_images() {
prepare

Expand Down
44 changes: 38 additions & 6 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,54 @@ import (
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/infracloudio/botkube/pkg/config"
"github.com/infracloudio/botkube/pkg/utils"
testutils "github.com/infracloudio/botkube/test/e2e/utils"
)

// TODO: Tests moved out straight from E2E test package with minimal changes.
// Refactor them as a part of https://github.com/infracloudio/botkube/issues/589
// TODO: Refactor these tests as a part of https://github.com/infracloudio/botkube/issues/589
// These tests were moved from old E2E package with fake K8s and Slack API
// (deleted in https://github.com/infracloudio/botkube/pull/627) and adjusted to become unit tests.

// ErrorEvent stores specs for throwing an error in case of anomalies
type ErrorEvent struct {
GVR schema.GroupVersionResource
Kind string
Namespace string
Name string
Specs runtime.Object
}

// UpdateObjects stores specs and patch for updating a k8s fake object and expected Slack response
type UpdateObjects struct {
GVR schema.GroupVersionResource
Kind string
Namespace string
Name string
Specs runtime.Object
Patch []byte
Diff string
UpdateSetting config.UpdateSetting
NotifType config.NotifType
}

// DeleteObjects stores specs for deleting a k8s fake object
type DeleteObjects struct {
GVR schema.GroupVersionResource
Kind string
Namespace string
Name string
Specs runtime.Object
}

func TestController_ShouldSendEvent_SkipError(t *testing.T) {
observedEventKindsMap := map[EventKind]bool{
{Resource: "v1/pods", Namespace: "dummy", EventType: "error"}: true,
}

tests := map[string]testutils.ErrorEvent{
tests := map[string]ErrorEvent{
"skip error event for resources not configured": {
// error event not allowed for Pod resources so event should be skipped
GVR: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
Expand Down Expand Up @@ -66,7 +98,7 @@ func TestController_ShouldSendEvent_SkipUpdate(t *testing.T) {
}

// test scenarios
tests := map[string]testutils.UpdateObjects{
tests := map[string]UpdateObjects{
"skip update event for namespaces not configured": {
// update operation not allowed for Pod in test namespace so event should be skipped
GVR: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
Expand Down Expand Up @@ -102,7 +134,7 @@ func TestController_ShouldSendEvent_SkipDelete(t *testing.T) {
}

// test scenarios
tests := map[string]testutils.DeleteObjects{
tests := map[string]DeleteObjects{
"skip delete event for resources not configured": {
// delete operation not allowed for Pod resources so event should be skipped
GVR: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions test/doc.go

This file was deleted.

54 changes: 0 additions & 54 deletions test/e2e/comm_config.yaml

This file was deleted.

0 comments on commit e683937

Please sign in to comment.