Skip to content

Commit

Permalink
🌱 Initial Hub API Tests (#268)
Browse files Browse the repository at this point in the history
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 #262

---------

Signed-off-by: Marek Aufart <[email protected]>
  • Loading branch information
aufi authored May 4, 2023
1 parent 46f53a9 commit 122ec48
Show file tree
Hide file tree
Showing 49 changed files with 2,765 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ jobs:
- uses: actions/checkout@v3
- run: make podman-build

test-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
- run: make test

#test-api:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-go@v3
# with:
# go-version: '1.19'
# - run: |
# make vet
# make run &
# sleep 15 # probably a dirty solution
# HUB_BASE_URL=http://localhost:8080 make test-api

test-e2e:
runs-on: ubuntu-latest
steps:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test nightly

on:
schedule:
- cron: '13 0,12 * * *' # Regulary every 12 hours

jobs:
test-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Start minikube
uses: konveyor/tackle2-operator/.github/actions/start-minikube@main
- name: Build image in minikube
run: |
export SHELL=/bin/bash
eval $(minikube -p minikube docker-env)
make docker-build
- name: Install Tackle
uses: konveyor/tackle2-operator/.github/actions/install-tackle@main
with:
tackle-hub-image: tackle2-hub:latest
tackle-image-pull-policy: IfNotPresent
- name: Set host and namespace
run: |
echo "host=$(minikube ip)/hub" >> $GITHUB_ENV
echo "namespace=$(kubectl get tackles.tackle.konveyor.io --all-namespaces --no-headers | awk '{print $1}')" >> $GITHUB_ENV
- name: Test execution
run: |
HUB_BASE_URL="http://$(minikube ip)/hub" make test-integration
with:
host: ${{ env.host }}
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GOBIN ?= ${GOPATH}/bin
IMG ?= tackle2-hub:latest
HUB_BASE_URL ?= http://localhost:8080

PKG = ./addon/... \
./api/... \
Expand Down Expand Up @@ -116,3 +117,21 @@ ifeq (,$(wildcard $(INSTALL_TACKLE_SH)))
}
endif
$(INSTALL_TACKLE_SH);

# Run test targets always (not producing test dirs there).
.PHONY: test test-api test-integration

# Run unit tests.
test:
go test -v ./auth/

# Run Hub REST API tests.
test-api:
HUB_BASE_URL=${HUB_BASE_URL} go test -v ./test/api/...

# Run Hub API integration tests.
test-integration:
HUB_BASE_URL=${HUB_BASE_URL} go test -v ./test/integration/...

# Run Hub test suite.
test-all: test-unit test-api test-integration
51 changes: 51 additions & 0 deletions binding/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package binding

import (
"github.com/konveyor/tackle2-hub/api"
)

//
// Application API.
type Application struct {
// hub API client.
client *Client
}

//
// Create an Application.
func (h *Application) Create(r *api.Application) (err error) {
err = h.client.Post(api.ApplicationsRoot, &r)
return
}

//
// Get an Application by ID.
func (h *Application) Get(id uint) (r *api.Application, err error) {
r = &api.Application{}
path := Path(api.ApplicationRoot).Inject(Params{api.ID: id})
err = h.client.Get(path, r)
return
}

//
// List Applications.
func (h *Application) List() (list []api.Application, err error) {
list = []api.Application{}
err = h.client.Get(api.ApplicationsRoot, &list)
return
}

//
// Update an Application.
func (h *Application) Update(r *api.Application) (err error) {
path := Path(api.ApplicationRoot).Inject(Params{api.ID: r.ID})
err = h.client.Put(path, r)
return
}

//
// Delete an Application.
func (h *Application) Delete(id uint) (err error) {
err = h.client.Delete(Path(api.ApplicationRoot).Inject(Params{api.ID: id}))
return
}
51 changes: 51 additions & 0 deletions binding/businessservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package binding

import (
"github.com/konveyor/tackle2-hub/api"
)

//
// BusinessService API.
type BusinessService struct {
// hub API client.
client *Client
}

//
// Create a BusinessService.
func (h *BusinessService) Create(r *api.BusinessService) (err error) {
err = h.client.Post(api.BusinessServicesRoot, &r)
return
}

//
// Get a BusinessService by ID.
func (h *BusinessService) Get(id uint) (r *api.BusinessService, err error) {
r = &api.BusinessService{}
path := Path(api.BusinessServiceRoot).Inject(Params{api.ID: id})
err = h.client.Get(path, r)
return
}

//
// List BusinessServices.
func (h *BusinessService) List() (list []api.BusinessService, err error) {
list = []api.BusinessService{}
err = h.client.Get(api.BusinessServicesRoot, &list)
return
}

//
// Update a BusinessService.
func (h *BusinessService) Update(r *api.BusinessService) (err error) {
path := Path(api.BusinessServiceRoot).Inject(Params{api.ID: r.ID})
err = h.client.Put(path, r)
return
}

//
// Delete a BusinessService.
func (h *BusinessService) Delete(id uint) (err error) {
err = h.client.Delete(Path(api.BusinessServiceRoot).Inject(Params{api.ID: id}))
return
}
Loading

0 comments on commit 122ec48

Please sign in to comment.