-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gateway): add gateway e2e test (#343)
* feat(gateway): add gateway e2e test * feat(gateway): add test readme * feat(gateway): opt test
- Loading branch information
Showing
14 changed files
with
709 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Gateway tests | ||
|
||
## How to use | ||
|
||
TODO: Install apisix in test code | ||
|
||
### install apisix and forward port | ||
|
||
```shell | ||
helm repo add apisix https://charts.apiseven.com | ||
helm repo update | ||
helm install apisix apisix/apisix --create-namespace --namespace apisix | ||
kubectl port-forward service/apisix-gateway 19180:9180 -n apisix | ||
``` | ||
|
||
### install crds and run controller | ||
|
||
```shell | ||
cd controllers/oss && make install | ||
cd controllers/gateway && make install | ||
go main.go | ||
``` | ||
|
||
### run test | ||
|
||
```shell | ||
cd controllers/gateway | ||
go test tests/e2e/gateway_test.go | ||
|
||
``` | ||
|
||
### uninstall apisix | ||
|
||
``` | ||
helm uninstall apisix -n apisix | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package api | ||
|
||
import ( | ||
testapi "github.com/labring/laf/tests/api" | ||
"github.com/labring/laf/tests/util" | ||
) | ||
|
||
const appDomainYaml = ` | ||
apiVersion: gateway.laf.dev/v1 | ||
kind: Domain | ||
metadata: | ||
name: {{ .name }} | ||
namespace: {{ .namespace }} | ||
spec: | ||
backendType: app | ||
cluster: | ||
key: edd1c9f034335f136f87ad84b625c8f1 | ||
url: http://localhost:19180/apisix/admin | ||
domain: app.laf.win | ||
region: default | ||
` | ||
|
||
func createAppDomain(name, namespace string) { | ||
template, err := util.RenderTemplate(appDomainYaml, map[string]string{ | ||
"name": name, | ||
"namespace": namespace, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = testapi.KubeApply(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
} | ||
|
||
const bucketDomainYaml = ` | ||
apiVersion: gateway.laf.dev/v1 | ||
kind: Domain | ||
metadata: | ||
name: {{ .name }} | ||
namespace: {{ .namespace }} | ||
spec: | ||
backendType: bucket | ||
cluster: | ||
key: edd1c9f034335f136f87ad84b625c8f1 | ||
url: http://localhost:19180/apisix/admin | ||
domain: oss.laf.win | ||
region: default | ||
` | ||
|
||
func createBucketDomain(name, namespace string) { | ||
template, err := util.RenderTemplate(bucketDomainYaml, map[string]string{ | ||
"name": name, | ||
"namespace": namespace, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = testapi.KubeApply(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func CreateDomain(name, namespace string) { | ||
createAppDomain(name+"-app", namespace) | ||
createBucketDomain(name+"-bucket", namespace) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
testapi "github.com/labring/laf/tests/api" | ||
"github.com/labring/laf/tests/util" | ||
) | ||
|
||
const systemNamespace = "testing-system" | ||
const testNamespace = "testing" | ||
|
||
const gatewayYaml = ` | ||
apiVersion: gateway.laf.dev/v1 | ||
kind: Gateway | ||
metadata: | ||
name: {{ .name }} | ||
namespace: {{ .namespace }} | ||
spec: | ||
appid: {{ .appId }} | ||
` | ||
|
||
// CreateGateway create a gateway | ||
func CreateGateway(name, namespace, appId string) { | ||
template, err := util.RenderTemplate(gatewayYaml, map[string]string{ | ||
"name": name, | ||
"namespace": namespace, | ||
"appId": appId, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = testapi.KubeApply(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
const gatewayBucketYaml = ` | ||
apiVersion: gateway.laf.dev/v1 | ||
kind: Gateway | ||
metadata: | ||
name: {{ .name }} | ||
namespace: {{ .namespace }} | ||
spec: | ||
appid: testing | ||
buckets: ["{{ .bucketName }}"] | ||
` | ||
|
||
// AddGatewayBucket add gateway bucket | ||
func AddGatewayBucket(name, namespace, appId, bucketName string) { | ||
template, err := util.RenderTemplate(gatewayBucketYaml, map[string]string{ | ||
"name": name, | ||
"namespace": namespace, | ||
"appId": appId, | ||
"bucketName": bucketName, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = testapi.KubeApply(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// DeleteGatewayBucket delete gateway bucket | ||
func DeleteGatewayBucket(name, namespace, appId string) { | ||
template, err := util.RenderTemplate(gatewayYaml, map[string]string{ | ||
"name": name, | ||
"namespace": namespace, | ||
"appId": appId, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = testapi.KubeApply(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// DeleteGateway delete gateway | ||
func DeleteGateway(name, namespace, appId string) { | ||
template, err := util.RenderTemplate(gatewayYaml, map[string]string{ | ||
"name": name, | ||
"namespace": namespace, | ||
"appId": appId, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = testapi.KubeDelete(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func WaitForGatewayReady(name string, namespace string) { | ||
cmd := fmt.Sprintf("kubectl wait --for=condition=ready --timeout=60s gateways.gateway.laf.dev/%s -n %s", name, namespace) | ||
_, err := testapi.Exec(cmd) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package api |
Oops, something went wrong.