Skip to content

Commit 122ec48

Browse files
authored
🌱 Initial Hub API Tests (konveyor#268)
First part of Hub REST API test suite. Steps - the simplest CRUD for all resource types - simple seeds tests - connecting resources with refs (update tests above) - clarify non-trivial fixtures definition and tear up&down - basic integration scenarios (addons&analysis) Related to konveyor#262 --------- Signed-off-by: Marek Aufart <[email protected]>
1 parent 46f53a9 commit 122ec48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2765
-0
lines changed

.github/workflows/main.yml

+22
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ jobs:
3737
- uses: actions/checkout@v3
3838
- run: make podman-build
3939

40+
test-unit:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v3
44+
- uses: actions/setup-go@v3
45+
with:
46+
go-version: '1.19'
47+
- run: make test
48+
49+
#test-api:
50+
# runs-on: ubuntu-latest
51+
# steps:
52+
# - uses: actions/checkout@v3
53+
# - uses: actions/setup-go@v3
54+
# with:
55+
# go-version: '1.19'
56+
# - run: |
57+
# make vet
58+
# make run &
59+
# sleep 15 # probably a dirty solution
60+
# HUB_BASE_URL=http://localhost:8080 make test-api
61+
4062
test-e2e:
4163
runs-on: ubuntu-latest
4264
steps:

.github/workflows/test-nightly.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test nightly
2+
3+
on:
4+
schedule:
5+
- cron: '13 0,12 * * *' # Regulary every 12 hours
6+
7+
jobs:
8+
test-integration:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Start minikube
13+
uses: konveyor/tackle2-operator/.github/actions/start-minikube@main
14+
- name: Build image in minikube
15+
run: |
16+
export SHELL=/bin/bash
17+
eval $(minikube -p minikube docker-env)
18+
make docker-build
19+
- name: Install Tackle
20+
uses: konveyor/tackle2-operator/.github/actions/install-tackle@main
21+
with:
22+
tackle-hub-image: tackle2-hub:latest
23+
tackle-image-pull-policy: IfNotPresent
24+
- name: Set host and namespace
25+
run: |
26+
echo "host=$(minikube ip)/hub" >> $GITHUB_ENV
27+
echo "namespace=$(kubectl get tackles.tackle.konveyor.io --all-namespaces --no-headers | awk '{print $1}')" >> $GITHUB_ENV
28+
- name: Test execution
29+
run: |
30+
HUB_BASE_URL="http://$(minikube ip)/hub" make test-integration
31+
with:
32+
host: ${{ env.host }}

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
GOBIN ?= ${GOPATH}/bin
22
IMG ?= tackle2-hub:latest
3+
HUB_BASE_URL ?= http://localhost:8080
34

45
PKG = ./addon/... \
56
./api/... \
@@ -116,3 +117,21 @@ ifeq (,$(wildcard $(INSTALL_TACKLE_SH)))
116117
}
117118
endif
118119
$(INSTALL_TACKLE_SH);
120+
121+
# Run test targets always (not producing test dirs there).
122+
.PHONY: test test-api test-integration
123+
124+
# Run unit tests.
125+
test:
126+
go test -v ./auth/
127+
128+
# Run Hub REST API tests.
129+
test-api:
130+
HUB_BASE_URL=${HUB_BASE_URL} go test -v ./test/api/...
131+
132+
# Run Hub API integration tests.
133+
test-integration:
134+
HUB_BASE_URL=${HUB_BASE_URL} go test -v ./test/integration/...
135+
136+
# Run Hub test suite.
137+
test-all: test-unit test-api test-integration

binding/application.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package binding
2+
3+
import (
4+
"github.com/konveyor/tackle2-hub/api"
5+
)
6+
7+
//
8+
// Application API.
9+
type Application struct {
10+
// hub API client.
11+
client *Client
12+
}
13+
14+
//
15+
// Create an Application.
16+
func (h *Application) Create(r *api.Application) (err error) {
17+
err = h.client.Post(api.ApplicationsRoot, &r)
18+
return
19+
}
20+
21+
//
22+
// Get an Application by ID.
23+
func (h *Application) Get(id uint) (r *api.Application, err error) {
24+
r = &api.Application{}
25+
path := Path(api.ApplicationRoot).Inject(Params{api.ID: id})
26+
err = h.client.Get(path, r)
27+
return
28+
}
29+
30+
//
31+
// List Applications.
32+
func (h *Application) List() (list []api.Application, err error) {
33+
list = []api.Application{}
34+
err = h.client.Get(api.ApplicationsRoot, &list)
35+
return
36+
}
37+
38+
//
39+
// Update an Application.
40+
func (h *Application) Update(r *api.Application) (err error) {
41+
path := Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID})
42+
err = h.client.Put(path, r)
43+
return
44+
}
45+
46+
//
47+
// Delete an Application.
48+
func (h *Application) Delete(id uint) (err error) {
49+
err = h.client.Delete(Path(api.ApplicationRoot).Inject(Params{api.ID: id}))
50+
return
51+
}

binding/businessservice.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package binding
2+
3+
import (
4+
"github.com/konveyor/tackle2-hub/api"
5+
)
6+
7+
//
8+
// BusinessService API.
9+
type BusinessService struct {
10+
// hub API client.
11+
client *Client
12+
}
13+
14+
//
15+
// Create a BusinessService.
16+
func (h *BusinessService) Create(r *api.BusinessService) (err error) {
17+
err = h.client.Post(api.BusinessServicesRoot, &r)
18+
return
19+
}
20+
21+
//
22+
// Get a BusinessService by ID.
23+
func (h *BusinessService) Get(id uint) (r *api.BusinessService, err error) {
24+
r = &api.BusinessService{}
25+
path := Path(api.BusinessServiceRoot).Inject(Params{api.ID: id})
26+
err = h.client.Get(path, r)
27+
return
28+
}
29+
30+
//
31+
// List BusinessServices.
32+
func (h *BusinessService) List() (list []api.BusinessService, err error) {
33+
list = []api.BusinessService{}
34+
err = h.client.Get(api.BusinessServicesRoot, &list)
35+
return
36+
}
37+
38+
//
39+
// Update a BusinessService.
40+
func (h *BusinessService) Update(r *api.BusinessService) (err error) {
41+
path := Path(api.BusinessServiceRoot).Inject(Params{api.ID: r.ID})
42+
err = h.client.Put(path, r)
43+
return
44+
}
45+
46+
//
47+
// Delete a BusinessService.
48+
func (h *BusinessService) Delete(id uint) (err error) {
49+
err = h.client.Delete(Path(api.BusinessServiceRoot).Inject(Params{api.ID: id}))
50+
return
51+
}

0 commit comments

Comments
 (0)