Skip to content

Commit

Permalink
Adjust acceptance test after renamining RemoteEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Dec 17, 2018
1 parent 99509e8 commit d4f4fe6
Show file tree
Hide file tree
Showing 23 changed files with 303 additions and 282 deletions.
2 changes: 1 addition & 1 deletion tests/acceptance/Dockerfile
Expand Up @@ -11,7 +11,7 @@ ADD env-tester.bin /go/bin/env-tester.bin

WORKDIR $SRC_DIR

RUN go test -c ./remote-environment
RUN go test -c ./application
RUN go test -c ./servicecatalog
RUN go test -c ./dex

Expand Down
18 changes: 11 additions & 7 deletions tests/acceptance/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/acceptance/Gopkg.toml
Expand Up @@ -40,7 +40,7 @@ required = [

[[constraint]]
name = "github.com/kyma-project/kyma"
revision = "7400291c88b0dde7d2b674f02a40efc5eb1934e5"
revision = "46be4bf9ea1d63216d644240036909ce0b50c7eb"

[[constraint]]
name = "github.com/kubernetes-incubator/service-catalog"
Expand Down
@@ -1,4 +1,4 @@
# Remote environment binding test
# Application binding test

## Overview

Expand All @@ -7,7 +7,7 @@ This folder contains the test which checks if the BindingUsage resource allows t
## Details

The testing scenario has the following steps:
1. Setup: create RemoteEnvironment, EnvironmentMapping, deployments (`fake-gateway`, `gateway-client`) and set-up Istio Deniers and Rules
1. Setup: create Application, ApplicationMapping, deployments (`fake-gateway`, `gateway-client`) and set-up Istio Deniers and Rules
2. Provision a ServiceClass
3. Perform binding
4. Add a BindingUsage
Expand All @@ -27,19 +27,19 @@ Go to the project root directory.

Build testing Docker image:
```bash
./remote-environment/contrib/build.sh
./application/contrib/build.sh
```

Create service accounts and roles:
```bash
kubectl apply -f remote-environment/contrib/rbac.yaml
kubectl apply -f application/contrib/rbac.yaml
```

### Run the test

Create a testing Pod:
```bash
kubectl apply -f remote-environment/contrib/pod.yaml
kubectl apply -f application/contrib/pod.yaml
```

### Watch resources
Expand All @@ -58,5 +58,5 @@ Clean up all test resources:

```bash
kubectl delete ns acceptance-test
kubectl delete po -n kyma-system re-acceptance-test
kubectl delete po -n kyma-system app-acceptance-test
```
@@ -1,24 +1,24 @@
package remote_environment_test
package application_test

import (
"testing"
"time"

"github.com/kyma-project/kyma/tests/acceptance/remote-environment/suite"
"github.com/kyma-project/kyma/tests/acceptance/application/suite"
"github.com/vrischmann/envconfig"
)

// Config contains all configurations for Remote Environment Acceptance tests
// Config contains all configurations for Application Acceptance tests
type Config struct {
DockerImage string `envconfig:"STUBS_DOCKER_IMAGE"`
LinkingTimeout time.Duration `envconfig:"default=3m,REMOTE_ENVIRONMENT_LINKING_TIMEOUT"`
UnlinkingTimeout time.Duration `envconfig:"default=3m,REMOTE_ENVIRONMENT_UNLINKING_TIMEOUT"`
KeepTestResources bool `envconfig:"REMOTE_ENVIRONMENT_KEEP_RESOURCES"`
Disabled bool `envconfig:"REMOTE_ENVIRONMENT_DISABLED"`
LinkingTimeout time.Duration `envconfig:"default=3m,APPLICATION_LINKING_TIMEOUT"`
UnlinkingTimeout time.Duration `envconfig:"default=3m,APPLICATION_UNLINKING_TIMEOUT"`
KeepTestResources bool `envconfig:"APPLICATION_KEEP_RESOURCES"`
Disabled bool `envconfig:"APPLICATION_DISABLED"`
TearDownTimeoutPerStep time.Duration `envconfig:"default=2m,TEAR_DOWN_TIMEOUT_PER_STEP"`
}

func TestRemoteEnvironmentAPIAccess(t *testing.T) {
func TestApplicationAPIAccess(t *testing.T) {
var cfg Config
if err := envconfig.Init(&cfg); err != nil {
t.Fatalf(err.Error())
Expand All @@ -28,7 +28,7 @@ func TestRemoteEnvironmentAPIAccess(t *testing.T) {
t.Skip("Test skipped due to test configuration.")
}

t.Logf("Running Remote Environment Test with config: %+v", cfg)
t.Logf("Running Application Test with config: %+v", cfg)

// GIVEN
ts := suite.NewTestSuite(t, cfg.DockerImage, "acceptance-test")
Expand Down
Expand Up @@ -16,16 +16,16 @@ import (
)

type Config struct {
// RemoteEnvironmentServerPort is a port used by this gateway to listen on requests incoming from services.
RemoteEnvironmentServerPort int `envconfig:"default=8080"`
// ApplicationServerPort is a port used by this gateway to listen on requests incoming from services.
ApplicationServerPort int `envconfig:"default=8080"`
}

type httpHandler struct {
Cfg Config
}

func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "remote environment gateway, request URL: \"%s\" request headers: %v\n", r.URL, r.Header)
fmt.Fprintf(w, "Application gateway, request URL: \"%s\" request headers: %v\n", r.URL, r.Header)
}

func main() {
Expand All @@ -35,7 +35,7 @@ func main() {
}

l := logrus.New()
l.Infof("Starting server, port: %d", cfg.RemoteEnvironmentServerPort)
l.Infof("Starting server, port: %d", cfg.ApplicationServerPort)

h := &httpHandler{
Cfg: cfg,
Expand All @@ -49,7 +49,7 @@ func main() {
httplog.DefaultReqResConfig(),
)(http.HandlerFunc(mux.ServeHTTP))

listenOn := fmt.Sprintf(":%d", cfg.RemoteEnvironmentServerPort)
listenOn := fmt.Sprintf(":%d", cfg.ApplicationServerPort)
httpServer := http.Server{Addr: listenOn, Handler: loggedHandler}

go func() {
Expand Down
Expand Up @@ -13,16 +13,16 @@ set -e #terminate script immediately in case of errors
eval $(minikube docker-env --shell bash)

echo -e "${GREEN} Building test${NC}"
GOOS=linux GOARCH=amd64 go test -v -c -o re.test ./remote-environment/re_test.go
GOOS=linux GOARCH=amd64 go test -v -c -o re.test ./application/re_test.go

echo -e "${GREEN} Building gw${NC}"
GOOS=linux GOARCH=amd64 go build -o gateway.bin ./remote-environment/cmd/fake-gateway/main.go
GOOS=linux GOARCH=amd64 go build -o gateway.bin ./application/cmd/fake-gateway/main.go

echo -e "${GREEN} Building tester${NC}"
GOOS=linux GOARCH=amd64 go build -o client.bin ./remote-environment/cmd/gateway-client/main.go
GOOS=linux GOARCH=amd64 go build -o client.bin ./application/cmd/gateway-client/main.go

IMAGE_NAME=acceptance-tests-re:${TAG}
docker build -t ${IMAGE_NAME} -f remote-environment/contrib/Dockerfile .
docker build -t ${IMAGE_NAME} -f application/contrib/Dockerfile .
docker tag ${IMAGE_NAME} ${PROJECT}/${IMAGE_NAME}

rm gateway.bin
Expand Down
@@ -1,24 +1,24 @@
apiVersion: v1
kind: Pod
metadata:
name: re-acceptance-test
name: app-acceptance-test
namespace: kyma-system
spec:
serviceAccountName: remoteenv-test
serviceAccountName: app-test
containers:
- name: acceptance-test
imagePullPolicy: Always
image: acceptance-tests-re:0.0.1
env:
- name: REMOTE_ENVIRONMENT_KEEP_RESOURCES
- name: APPLICATION_KEEP_RESOURCES
value: "true"
- name: STUBS_DOCKER_IMAGE
value: acceptance-tests-re:0.0.1
- name: REMOTE_ENVIRONMENT_LINKING_TIMEOUT
- name: APPLICATION_LINKING_TIMEOUT
value: 2m
- name: REMOTE_ENVIRONMENT_UNLINKING_TIMEOUT
- name: APPLICATION_UNLINKING_TIMEOUT
value: 2m
- name: REMOTE_ENVIRONMENT_DISABLED
- name: APPLICATION_DISABLED
value: "false"
restartPolicy: Never

@@ -1,17 +1,17 @@
kind: ServiceAccount
apiVersion: v1
metadata:
name: remoteenv-test
name: app-test
namespace: kyma-system
labels:
app: remoteenv-test
app: app-test
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: remoteenv-test
name: app-test
labels:
app: remoteenv-test
app: app-test
rules:
- apiGroups: ["servicecatalog.k8s.io"]
resources: ["clusterserviceclasses", "serviceclasses"]
Expand All @@ -30,7 +30,7 @@ rules:
verbs: ["get", "delete", "create", "list"]
nonResourceURLs: []
- apiGroups: ["applicationconnector.kyma-project.io"]
resources: ["remoteenvironments", "environmentmappings"]
resources: ["applications", "applicationmappings"]
verbs: ["create", "delete"]
nonResourceURLs: []
- apiGroups: ["apps"]
Expand All @@ -57,25 +57,25 @@ rules:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: remoteenv-test
name: app-test
subjects:
- kind: ServiceAccount
name: remoteenv-test
name: app-test
namespace: kyma-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: remoteenv-test
name: app-test
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: remoteenv-test-acceptance-test
name: app-test-acceptance-test
subjects:
- kind: ServiceAccount
name: remoteenv-test
name: app-test
namespace: acceptance-test
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: remoteenv-test
name: app-test
@@ -1,19 +1,19 @@
package remote_environment
package application

import (
"testing"
"time"

"github.com/kyma-project/kyma/tests/acceptance/remote-environment/suite"
"github.com/kyma-project/kyma/tests/acceptance/application/suite"
"github.com/vrischmann/envconfig"
)

type Config struct {
KeepTestResources bool `envconfig:"REMOTE_ENVIRONMENT_KEEP_RESOURCES"`
Disabled bool `envconfig:"REMOTE_ENVIRONMENT_DISABLED"`
KeepTestResources bool `envconfig:"APPLICATION_KEEP_RESOURCES"`
Disabled bool `envconfig:"APPLICATION_DISABLED"`
}

func TestEnvironmentMapping_EnsureBrokerAndClassesOnlyWhenMappingExist(t *testing.T) {
func TestApplicationMapping_EnsureBrokerAndClassesOnlyWhenMappingExist(t *testing.T) {
var cfg Config
if err := envconfig.Init(&cfg); err != nil {
t.Fatalf(err.Error())
Expand All @@ -28,11 +28,11 @@ func TestEnvironmentMapping_EnsureBrokerAndClassesOnlyWhenMappingExist(t *testin
defer ts.TearDown()
}

// Service Broker and Service Class shouldn't exist without EnvironmentMapping
// Service Broker and Service Class shouldn't exist without ApplicationMapping
ts.EnsureServiceBrokerNotExist(ts.MappedNs)
ts.EnsureServiceClassNotExist(ts.MappedNs)

ts.CreateEnvironmentMapping()
ts.CreateApplicationMapping()

t.Log("Waiting for service broker")
ts.WaitForServiceBrokerWithTimeout(time.Second * 30)
Expand All @@ -45,10 +45,10 @@ func TestEnvironmentMapping_EnsureBrokerAndClassesOnlyWhenMappingExist(t *testin
ts.EnsureServiceBrokerNotExist(ts.EmptyNs)
ts.EnsureServiceClassNotExist(ts.EmptyNs)

ts.DeleteEnvironmentMapping()
ts.DeleteApplicationMapping()

// Service Broker and Service Class shouldn't exist without EnvironmentMapping
t.Log("Waiting until REB will delete service broker")
// Service Broker and Service Class shouldn't exist without ApplicationMapping
t.Log("Waiting until AppBroker will delete service broker")
ts.EnsureServiceBrokerNotExistWithTimeout(time.Second * 30)
ts.EnsureServiceClassNotExist(ts.MappedNs)

Expand Down

0 comments on commit d4f4fe6

Please sign in to comment.