Skip to content

Commit

Permalink
Fixed Issue 80: Modified the test framework for tink repo
Browse files Browse the repository at this point in the history
This framework was written a while ago but is commented and there have been a lot of changes since then.
1. Remove the target concepts completely
2. Changed the way of writting templates
3. Changed the way of creating workflows
4. Generating certs are not the part of docker-compose anymore

TODO:
This framework works well for single worker. There are few changes required in the framework to make it work for multiple workers
  • Loading branch information
parauliya committed Jun 18, 2020
1 parent db1c9c2 commit b3dfd6f
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 346 deletions.
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ steps:
- name: test
image: golang:1.13-alpine3.11
commands:
- CGO_ENABLED=0 go test -v ./...
- apk add --update make
- CGO_ENABLED=0 make test

- name: ci-checks
image: nixos/nix:2.3.4
Expand Down
158 changes: 0 additions & 158 deletions test-docker-compose.yml

This file was deleted.

5 changes: 1 addition & 4 deletions test/actions/update_data/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
FROM bash
ADD hello_world.sh /bin/hello_world.sh
RUN chmod +x /bin/hello_world.sh
#CMD echo '{"action_01": "data_01"}' > /workflow/data
ENTRYPOINT [ "/bin/hello_world.sh" ]
CMD echo '{"action_01": "data_01"}' > /workflow/data
2 changes: 1 addition & 1 deletion test/data/hardware/hardware_1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d1",
"allow_pxe": true,
"arch": "x86_64",
"bonding_mode": 4,
"efi_boot": true,
"facility_code": "ewr1",
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d1",
"instance": {
"allow_pxe": true,
"always_pxe": true,
Expand Down
2 changes: 1 addition & 1 deletion test/data/hardware/hardware_2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d2",
"allow_pxe": true,
"arch": "x86_64",
"bonding_mode": 4,
"efi_boot": true,
"facility_code": "ewr1",
"id": "f9f56dff-098a-4c5f-a51c-19ad35de85d2",
"instance": {
"allow_pxe": true,
"always_pxe": true,
Expand Down
2 changes: 1 addition & 1 deletion test/data/template/sample_1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks:
environment:
NGINX_HOST: 192.168.1.2
- name: "update_db"
image: update-data
image: overwrite-data
timeout: 50
environment:
MIRROR_HOST: 192.168.1.3
141 changes: 71 additions & 70 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
package e2e

//import (
// "os"
// "time"
// "testing"
//
// "github.com/tinkerbell/tink/client"
// "github.com/tinkerbell/tink/protos/workflow"
// "github.com/tinkerbell/tink/test/framework"
// "github.com/sirupsen/logrus"
//)
//
//var log *logrus.Logger = framework.Log
//
//func TestMain(m *testing.M) {
// log.Infoln("########Creating Setup########")
// time.Sleep(10 * time.Second)
// err := framework.StartStack()
// if err != nil {
// os.Exit(1)
// }
// os.Setenv("TINKERBELL_GRPC_AUTHORITY", "127.0.0.1:42113")
// os.Setenv("TINKERBELL_CERT_URL", "http://127.0.0.1:42114/cert")
// client.Setup()
// log.Infoln("########Setup Created########")
//
// log.Infoln("Creating hardware inventory")
// //push hardware data into hardware table
// hwData := []string{"hardware_1.json", "hardware_2.json"}
// err = framework.PushHardwareData(hwData)
// if err != nil {
// log.Errorln("Failed to push hardware inventory : ", err)
// os.Exit(2)
// }
// log.Infoln("Hardware inventory created")
//
// log.Infoln("########Starting Tests########")
// status := m.Run()
// log.Infoln("########Finished Tests########")
// log.Infoln("########Removing setup########")
// //err = framework.TearDown()
// if err != nil {
// os.Exit(3)
// }
// log.Infoln("########Setup removed########")
// os.Exit(status)
//}
//
//var testCases = map[string]struct {
// hardware string
// template string
// workers int64
// expected workflow.ActionState
// ephData string
//}{
// "testWfWithWorker": {"hardware_1.json", "sample_1", 1, workflow.ActionState_ACTION_SUCCESS, `{"action_02": "data_02"}`},
// "testWfTimeout": {"hardware_1.json", "sample_2", 1, workflow.ActionState_ACTION_TIMEOUT, `{"action_01": "data_01"}`},
// //"testWfWithMultiWorkers": {"hardware_1.json", "sample_3", 2, workflow.ActionState_ACTION_SUCCESS, `{"action_01": "data_01"}`},
//}
//
//var runTestMap = map[string]func(t *testing.T){
// "testWfWithWorker": TestWfWithWorker,
// "testWfTimeout": TestWfTimeout,
// //"testWfWithMultiWorkers": TestWfWithMultiWorkers,
//}
//
//func TestE2E(t *testing.T) {
// for key, val := range runTestMap {
// t.Run(key, val)
// }
//}
import (
"os"
"testing"
"time"

"github.com/sirupsen/logrus"
"github.com/tinkerbell/tink/client"
"github.com/tinkerbell/tink/protos/workflow"
"github.com/tinkerbell/tink/test/framework"
)

var log *logrus.Logger = framework.Log

func TestMain(m *testing.M) {
log.Infoln("########Creating Setup########")
time.Sleep(10 * time.Second)
err := framework.StartStack()
if err != nil {
os.Exit(1)
}
os.Setenv("TINKERBELL_GRPC_AUTHORITY", "127.0.0.1:42113")
os.Setenv("TINKERBELL_CERT_URL", "http://127.0.0.1:42114/cert")
client.Setup()
log.Infoln("########Setup Created########")

log.Infoln("Creating hardware inventory")
//push hardware data into hardware table
hwData := []string{"hardware_1.json", "hardware_2.json"}
err = framework.PushHardwareData(hwData)
if err != nil {
log.Errorln("Failed to push hardware inventory : ", err)
os.Exit(2)
}
log.Infoln("Hardware inventory created")

log.Infoln("########Starting Tests########")
status := m.Run()
log.Infoln("########Finished Tests########")
log.Infoln("########Removing setup########")
//err = framework.TearDown()
if err != nil {
os.Exit(3)
}
log.Infoln("########Setup removed########")
os.Exit(status)
}

var testCases = map[string]struct {
hardware string
hMAC string
template string
workers int64
expected workflow.ActionState
ephData string
}{
"testWfWithWorker": {"hardware_1.json", "98:03:9b:89:d7:ba", "sample_1", 1, workflow.ActionState_ACTION_SUCCESS, `{"action_02": "data_02"}`},
"testWfTimeout": {"hardware_1.json", "98:03:9b:89:d7:ba", "sample_2", 1, workflow.ActionState_ACTION_TIMEOUT, `{"action_01": "data_01"}`},
//"testWfWithMultiWorkers": {"hardware_1.json", "sample_3", 2, workflow.ActionState_ACTION_SUCCESS, `{"action_01": "data_01"}`},
}

var runTestMap = map[string]func(t *testing.T){
"testWfWithWorker": TestWfWithWorker,
"testWfTimeout": TestWfTimeout,
//"testWfWithMultiWorkers": TestWfWithMultiWorkers,
}

func TestE2E(t *testing.T) {
for key, val := range runTestMap {
t.Run(key, val)
}
}
Loading

0 comments on commit b3dfd6f

Please sign in to comment.