Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB Package Unit Tests #361

Closed

Conversation

CarlosOVillanueva
Copy link

@CarlosOVillanueva CarlosOVillanueva commented Nov 10, 2020

Description

Unit tests for testing db package. These tests require the postgres container to be up and running. Failure to include this will result in failed tests.

Why is this needed

The only unit tests in the db package are mock tests that do not validate database schema or functions embedded in database calls. These new tests validate requests against database responses.

How Has This Been Tested?

  • Built docker postgres image
  • Ran go test -v from within the db package.
=== RUN   TestConnect
~/go/src/github.com/tinkerbell/tink/db>go test -v
{"level":"info","ts":1605025139.0087209,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.0093741,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestConnect (0.00s)
=== RUN   TestInsertIntoDB
{"level":"info","ts":1605025139.0115247,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestInsertIntoDB (0.01s)
=== RUN   TestGetByMac
{"level":"info","ts":1605025139.0172408,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.0229852,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetByMac (0.01s)
=== RUN   TestGetByIP
{"level":"info","ts":1605025139.0251362,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.0313911,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetByIP (0.01s)
=== RUN   TestGetByInstanceIP
{"level":"info","ts":1605025139.0334523,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.0390992,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetByInstanceIP (0.01s)
=== RUN   TestConcurrentInsertIntoDb
{"level":"info","ts":1605025139.0414908,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    hardware_test.go:140: PUSHING {"id":"0d971aec-dcdd-5689-b485-735265db8247","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"00-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:140: PUSHING {"id":"fb5a4adc-21d9-2c56-dc8a-d58db7e61794","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"11-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:140: PUSHING {"id":"a05cee79-8fa4-3619-bd41-87e699073639","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"22-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:140: PUSHING {"id":"42ca7955-a0e9-8a49-0edc-74e1cc09325b","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"33-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:140: PUSHING {"id":"891be7fe-7ab9-770d-393b-5f1572f2b406","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"44-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
--- PASS: TestConcurrentInsertIntoDb (0.01s)
=== RUN   TestSerializedInsertIntoDb
{"level":"info","ts":1605025139.0491385,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    hardware_test.go:187: PUSHING {"id":"495fe336-ee26-f49f-598a-22332e66ffc5","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"00-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:187: PUSHING {"id":"afff2569-3e8a-8656-26d8-dd7d043c5a4a","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"11-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:187: PUSHING {"id":"6b742848-7e35-ef68-86c7-cefd6cd68bfb","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"22-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:187: PUSHING {"id":"8467bea4-d701-1c96-de37-69372c36cd4f","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"33-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
    hardware_test.go:187: PUSHING {"id":"214fb166-b708-0df4-d9de-49ee7dc3ef48","metadata":{"facility":{"facility_code":"onprem"},"instance":{"ip_addresses":null},"state":""},"network":{"interfaces":[{"dhcp":{"arch":"x86_64","ip":{"address":"192.168.1.5","gateway":"192.168.1.1","netmask":"255.255.255.248"},"mac":"44-00-00-00-00-00","uefi":false},"netboot":{"allow_pxe":true,"allow_workflow":true}}]}}
--- PASS: TestSerializedInsertIntoDb (0.01s)
=== RUN   TestGetByID
{"level":"info","ts":1605025139.062928,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.0703447,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetByID (0.01s)
=== RUN   TestDeleteFromDb
{"level":"info","ts":1605025139.0723722,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.078004,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestDeleteFromDb (0.01s)
=== RUN   TestCreateTemplate
{"level":"info","ts":1605025139.0812051,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestCreateTemplate (0.00s)
=== RUN   TestConcurrentCreateTemplate
{"level":"info","ts":1605025139.0861146,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    template_test.go:56: PUSHING foo4
    template_test.go:56: PUSHING foo5
    template_test.go:56: PUSHING foo1
    template_test.go:56: PUSHING foo2
    template_test.go:56: PUSHING foo3
--- PASS: TestConcurrentCreateTemplate (0.01s)
=== RUN   TestGetTemplate
{"level":"info","ts":1605025139.0942135,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1025968,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetTemplate (0.01s)
=== RUN   TestDeleteTemplate
{"level":"info","ts":1605025139.104913,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1107957,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestDeleteTemplate (0.01s)
=== RUN   TestUpdateTemplate
{"level":"info","ts":1605025139.1142876,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1200056,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestUpdateTemplate (0.01s)
=== RUN   TestCreateWorkflow
{"level":"info","ts":1605025139.1239328,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1286101,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1354823,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestCreateWorkflow (0.02s)
=== RUN   TestInsertIntoWfDataTable
{"level":"info","ts":1605025139.1453214,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1504803,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1563342,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1654112,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestInsertIntoWfDataTable (0.02s)
=== RUN   TestGetfromWfDataTable
{"level":"info","ts":1605025139.1692672,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1739728,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.1794631,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.191144,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    workflow_test.go:86: 
--- PASS: TestGetfromWfDataTable (0.02s)
=== RUN   TestGetWorkflowMetadata
{"level":"info","ts":1605025139.193556,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.199337,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.207261,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2188663,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    workflow_test.go:105: 
--- PASS: TestGetWorkflowMetadata (0.03s)
=== RUN   TestGetWorkflowDataVersion
{"level":"info","ts":1605025139.2209892,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2252748,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2317948,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2750075,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2785532,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetWorkflowDataVersion (0.06s)
=== RUN   TestGetWorkflowsForWorker
{"level":"info","ts":1605025139.2818756,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2859907,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.2915647,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.300528,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    workflow_test.go:138: []
--- PASS: TestGetWorkflowsForWorker (0.02s)
=== RUN   TestGetWorkflow
{"level":"info","ts":1605025139.3024194,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3109877,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3178945,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3286865,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestGetWorkflow (0.03s)
=== RUN   TestDeleteWorkflow
{"level":"info","ts":1605025139.3313582,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.337011,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.34357,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3524847,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestDeleteWorkflow (0.02s)
=== RUN   TestUpdateWorkflow
{"level":"info","ts":1605025139.3562808,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3628936,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3702433,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3785267,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestUpdateWorkflow (0.03s)
=== RUN   TestUpdateWorkflowState
{"level":"info","ts":1605025139.3823028,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3870876,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.3945692,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.405049,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
--- PASS: TestUpdateWorkflowState (0.03s)
=== RUN   TestGetWorkflowContexts
{"level":"info","ts":1605025139.4081707,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.4128814,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.4190562,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
{"level":"info","ts":1605025139.4281046,"caller":"db/common_test.go:38","msg":"host=localhost port=5432 user=tinkerbell password=tinkerbell dbname=tinkerbell sslmode=disable","service":"github.com/tinkerbell/tink"}
    workflow_test.go:231: workflow_id:"da013837-a30c-237a-adfc-2d9ad69d5011" total_number_of_actions:1
--- PASS: TestGetWorkflowContexts (0.02s)
PASS
ok      github.com/tinkerbell/tink/db   0.426s

How are existing users impacted? What migration steps/scripts do we need?

  • Existing users should not be impacted, but CI pipeline will need to be updated to spawn postgres instance.

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@CarlosOVillanueva CarlosOVillanueva force-pushed the cv-db-unit-tests branch 5 times, most recently from cdd06a9 to 6356905 Compare November 10, 2020 17:50
@CarlosOVillanueva CarlosOVillanueva changed the title [CV] DB package Unit Tests DB Package Unit Tests Nov 10, 2020
Copy link
Contributor

@mmlb mmlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @CarlosOVillanueva overall a great start! I'd like to see some more parameterized/randomised data instead of so many hard coded values. Removal of some test setup dupe by using parameterized sub tests would be good too.

db/common_test.go Outdated Show resolved Hide resolved
db/common_test.go Outdated Show resolved Hide resolved
db/common_test.go Outdated Show resolved Hide resolved
db/common_test.go Outdated Show resolved Hide resolved
db/common_test.go Outdated Show resolved Hide resolved
db/hardware_test.go Outdated Show resolved Hide resolved
deploy/docker-compose.yml Outdated Show resolved Hide resolved
deploy/db/docker-compose.yml Outdated Show resolved Hide resolved
deploy/vagrant/scripts/tinkerbell.sh Outdated Show resolved Hide resolved
deploy/vagrant/scripts/tinkerbell.sh Outdated Show resolved Hide resolved
@CarlosOVillanueva CarlosOVillanueva force-pushed the cv-db-unit-tests branch 4 times, most recently from 5d4b900 to 7813e2d Compare November 10, 2020 21:56
db/common_test.go Outdated Show resolved Hide resolved
db/common_test.go Show resolved Hide resolved
db/common_test.go Outdated Show resolved Hide resolved
db/hardware_test.go Outdated Show resolved Hide resolved
db/hardware_test.go Show resolved Hide resolved
db/model_test.go Outdated Show resolved Hide resolved
db/template_test.go Show resolved Hide resolved
db/workflow_test.go Show resolved Hide resolved
db/workflow_test.go Show resolved Hide resolved
deploy/docker-compose.yml Outdated Show resolved Hide resolved
@mmlb
Copy link
Contributor

mmlb commented Nov 13, 2020

@CarlosOVillanueva please rebase on top of master so golangci-lint action doesn't have errors

db/hardware_test.go Show resolved Hide resolved
db/common_test.go Outdated Show resolved Hide resolved
@CarlosOVillanueva CarlosOVillanueva force-pushed the cv-db-unit-tests branch 3 times, most recently from c7247ff to 45f070d Compare November 19, 2020 21:47
@DavidHwu
Copy link

DavidHwu commented Dec 2, 2020

@mmlb I've been following on the discussion with both @CarlosOVillanueva and yourself.

Believe all the asks you've discussed have been addressed.
As this is critical to moving the unit tests forward and adding new unit tests to support and unblock Central.
I am going to approve this PR.
If you have any concerns, please let me know.

DavidHwu
DavidHwu previously approved these changes Dec 3, 2020
Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2020-12-03 at 11 45 46

We can't merge code that do not pass CI @DavidHwu

Copy link
Contributor

@mmlb mmlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides the CI not passing, there's still a couple of tests that should verify that the intended updated was actually persisted and not that the function didn't error (trust, but verify :D )

if err = a.tinkDb.UpdateWorkflowState(a.ctx, wfContext); err != nil {
a.logger.Error(err)
t.Error(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test isn't actually verifying that the state was updated right?

Comment on lines +96 to +99
if err = a.tinkDb.CreateTemplate(a.ctx, "bar", a.templateData, id); err != nil {
a.logger.Error(err)
t.Fail()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should verify that template was in fact updated and not just that there was no error right?

@CarlosOVillanueva CarlosOVillanueva force-pushed the cv-db-unit-tests branch 2 times, most recently from 7f56fb6 to b5822e2 Compare December 3, 2020 17:27
@gianarb
Copy link
Contributor

gianarb commented Jan 5, 2021

@gauravgahlot do you mind having a look at which tests we can rewrite using the new framework? If all of them are already in you can close this PR.

Thanks

@gauravgahlot
Copy link
Contributor

gauravgahlot commented Jan 6, 2021

@gauravgahlot do you mind having a look at which tests we can rewrite using the new framework? If all of them are already in you can close this PR.

Thanks

Most of the setup code will be gone with the new framework in place. We can rewrite the Get tests for all three resource types. Create and Delete are already covered.

I will update the branch and use the new framework to rewrite the tests.

mergify bot added a commit that referenced this pull request Jan 11, 2021
## Description

The PR adds unit tests for `Get` requests to resources (template, hardware, workflow).
Restructures the tests in #361 as per the new framework.

## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [x] added unit or e2e tests
- [ ] provided instructions on how to upgrade
@gauravgahlot
Copy link
Contributor

@gianarb Can we close this in favor of #412?

@gianarb
Copy link
Contributor

gianarb commented Jan 12, 2021

Sure thanks

@gianarb gianarb closed this Jan 12, 2021
@mmlb mmlb deleted the cv-db-unit-tests branch January 20, 2021 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants