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

Setup test environment inside CI #9

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
dc455d5
Added Test and new_table_migration
FrankUrbach Nov 18, 2020
05f8d39
not realy changed something
FrankUrbach Nov 18, 2020
a44e9bb
changed Project.toml
FrankUrbach Nov 19, 2020
18ac63a
save array of AbstractModels
FrankUrbach Nov 19, 2020
7a1b7a9
begin test for structs with intern variables
FrankUrbach Nov 24, 2020
bf54b29
intermediate state
FrankUrbach Nov 24, 2020
28c332b
begin test saving without interns
FrankUrbach Nov 25, 2020
319764f
change the testfolder to the tests subfolder
FrankUrbach Nov 25, 2020
4910a4b
ended the change to /tests as projectfolder
FrankUrbach Nov 26, 2020
594fb90
created a test scenario for Issue#31 of
FrankUrbach Dec 2, 2020
541e94a
Merge branch 'Issue#31'
FrankUrbach Dec 2, 2020
ecd1f91
fullfilled merge actions
FrankUrbach Dec 2, 2020
91e9172
nothing reali heavy
FrankUrbach Dec 2, 2020
82fef68
CompatHelper: bump compat for "SearchLight" to "0.22"
github-actions[bot] Jun 15, 2021
c34da91
Only the first save after a long time
FrankUrbach Dec 2, 2021
103ea5a
Merge remote-tracking branch 'GenieFramework/compathelper/new_version…
FrankUrbach Dec 4, 2021
2506a2d
Test with DB included
FrankUrbach Dec 13, 2021
c81b6a9
Merge remote-tracking branch 'forkAtGithub/master'
FrankUrbach Dec 13, 2021
962dadd
changed compats
FrankUrbach Dec 13, 2021
c9293be
MySQL tests rausgeworfen
FrankUrbach Dec 13, 2021
ee66d2f
create a database in the CI tests
FrankUrbach Dec 13, 2021
b245dba
creating database changed
FrankUrbach Dec 13, 2021
7b3ba2d
next change
FrankUrbach Dec 13, 2021
5091c33
next round tests
FrankUrbach Dec 14, 2021
5c5c0ac
next
FrankUrbach Dec 14, 2021
3f7e40b
next atempt
FrankUrbach Dec 14, 2021
cbf55bc
next
FrankUrbach Dec 14, 2021
63ff491
next
FrankUrbach Dec 14, 2021
b9e9535
next
FrankUrbach Dec 14, 2021
0df8530
next
FrankUrbach Dec 14, 2021
13b8854
next
FrankUrbach Dec 14, 2021
6a3537d
nextone
FrankUrbach Dec 14, 2021
c75e172
next test
FrankUrbach Dec 14, 2021
39404f5
nextone
FrankUrbach Dec 14, 2021
f51a730
next do it
FrankUrbach Dec 14, 2021
3a3e2d5
test complete?
FrankUrbach Dec 14, 2021
02c58e2
now or never
FrankUrbach Dec 14, 2021
01847eb
add Testextensions
FrankUrbach Dec 14, 2021
f2c68b0
next
FrankUrbach Dec 14, 2021
5f9c55c
test next
FrankUrbach Dec 14, 2021
9f0f17d
test
FrankUrbach Dec 14, 2021
7c24bd8
testr
FrankUrbach Dec 14, 2021
9747bb8
next attempt
FrankUrbach Dec 14, 2021
76bf66d
next
FrankUrbach Dec 14, 2021
06cdc97
next do
FrankUrbach Dec 14, 2021
f06df3a
now?
FrankUrbach Dec 14, 2021
11827ab
maybe now?
FrankUrbach Dec 14, 2021
9584707
made toml readable
FrankUrbach Dec 14, 2021
fcd8337
now?
FrankUrbach Dec 14, 2021
e4bf3a8
now with Pkg
FrankUrbach Dec 14, 2021
4cef381
failure in database now?
FrankUrbach Dec 14, 2021
62457b7
changed for tests
FrankUrbach Dec 14, 2021
7071fcd
removed error
FrankUrbach Dec 14, 2021
d970f20
next step
FrankUrbach Dec 14, 2021
bf8bf00
next step
FrankUrbach Dec 14, 2021
b16713a
typo
FrankUrbach Dec 14, 2021
8839aa7
pkg Dates included
FrankUrbach Dec 14, 2021
8ab9ce9
Merge remote-tracking branch 'GenieFramework/master'
FrankUrbach Dec 21, 2021
439f590
changed_gitignore
FrankUrbach Jan 5, 2022
4f4a9f1
changes requested by review PR#9
FrankUrbach Jan 5, 2022
5679d6a
added Pkg package, Tests should run on 1.7.1
FrankUrbach Jan 5, 2022
3f1fa9a
added the needed packages for tests
FrankUrbach Jan 5, 2022
d569a33
dir change needed for reaching db/migrations folder
FrankUrbach Jan 5, 2022
0937725
changed the Project.toml files to remove
FrankUrbach Jan 15, 2022
c8d0b9a
removed .DS_Store file
FrankUrbach Jan 15, 2022
19e090a
changed .gitignore file
FrankUrbach Jan 15, 2022
c997f8f
Merge remote-tracking branch 'forkAtGithub/master'
FrankUrbach Jan 15, 2022
1c1d4a7
removed .DS_Store file
FrankUrbach Jan 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/Test_DB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: PostgreSQLAdapter test
on: push

jobs:
# Label of the container job
container-job:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest
# Docker Hub image that `container-job` executes in
container: node:10.18-jessie

# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432

steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.7.1'
arch: 'x64'
- uses: julia-actions/julia-buildpkg@master
- name: Install SearchLight and SearchLightPostgreSQL
run: |
pwd
julia -e 'using Pkg; Pkg.add(url="https://github.com/GenieFramework/SearchLight.jl.git")'
julia -e 'using Pkg; Pkg.add(url="https://github.com/GenieFramework/SearchLightPostgreSQL.jl.git")'
julia -e 'import Pkg; Pkg.add("SafeTestsets")'
julia -e 'using Pkg; Pkg.activate(".")'
julia -e 'using Pkg; Pkg.resolve()'
shell: bash
- uses: julia-actions/julia-runtest@master
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Manifest.toml
Manifest.toml
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove Manifest.toml from .gitignore?

Copy link
Author

Choose a reason for hiding this comment

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

uups. Added again.

tests/db/migrations/*
**/.DS_Store*
Copy link
Member

Choose a reason for hiding this comment

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

Can you also delete the .DS_Store files that were added?

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.configureOnOpen": false
}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ version = "2.0.1"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
LibPQ = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
SearchLight = "340e8cb6-72eb-11e8-37ce-c97ebeb32050"

[compat]
DataFrames = "1"
Copy link
Member

Choose a reason for hiding this comment

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

@FrankUrbach You removed the compat entry for DataFrames - pls put it back

LibPQ = "1"
SearchLight = "2"
julia = "1"
9 changes: 7 additions & 2 deletions src/SearchLightPostgreSQL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,14 @@ Runs a SQL DB query that creates the table `table_name` with the structure neede
The table should contain one column, `version`, unique, as a string of maximum 30 chars long.
"""
function SearchLight.Migration.create_migrations_table(table_name::String = SearchLight.config.db_migrations_table_name) :: Nothing
SearchLight.query("CREATE TABLE $table_name (version varchar(30))")

@info "Created table $table_name"
queryString = "SELECT table_name FROM information_schema.tables WHERE table_name = '$table_name'"
Copy link
Member

Choose a reason for hiding this comment

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

Please use naming consistent with the rest of the code base. In SearchLight (and Julia in general) we use query_string not queryString.

if isempty(SearchLight.query(queryString))
SearchLight.query("CREATE TABLE $table_name (version varchar(30))")
@info "Created table $table_name"
else
@info "Migration table exists."
end

nothing
end
Expand Down
Binary file added test/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SearchLight = "340e8cb6-72eb-11e8-37ce-c97ebeb32050"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestSetExtensions = "98d24dd4-01ad-11ea-1b02-c9a08f80db04"
Binary file added test/db/.DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions test/db/migrations/2019052410085235_create_table_users.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module CreateTableUsers

import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table

function up()
create_table(:users) do
[
primary_key()
column(:username, :string, limit = 100)
column(:password, :string, limit = 100)
column(:name, :string, limit = 100)
column(:email, :string, limit = 100)
]
end

add_index(:users, :username)
end

function down()
drop_table(:users)
end

end
20 changes: 20 additions & 0 deletions test/db/migrations/2021061519495560_create_table_roles.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module CreateTableRoles

import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table

function up()
create_table(:roles) do
[
primary_key()
column(:name, :string, limit = 100)
]
end

add_index(:roles, :name)
end

function down()
drop_table(:roles)
end

end
20 changes: 20 additions & 0 deletions test/db/migrations/2021061519503270_create_table_abilities.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module CreateTableAbilities

import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table

function up()
create_table(:abilities) do
[
primary_key()
column(:name, :string, limit = 100)
]
end

add_index(:abilities, :name)
end

function down()
drop_table(:abilities)
end

end
22 changes: 22 additions & 0 deletions test/db/migrations/2021061519532446_create_table_roles_users.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module CreateTableRolesUsers

import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table

function up()
create_table(:rolesusers) do
[
primary_key()
column(:roles_id, :int)
column(:users_id, :int)
]
end

add_index(:rolesusers, :roles_id)
add_index(:rolesusers, :users_id)
end

function down()
drop_table(:rolesusers)
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module CreateTableAbilitiesRoles

import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table

function up()
create_table(:abilitiesroles) do
[
primary_key()
column(:abilities_id, :int)
column(:roles_id, :int)
]
end

add_index(:abilitiesroles, :abilities_id)
add_index(:abilitiesroles, :roles_id)
end

function down()
drop_table(:abilitiesroles)
end

end
159 changes: 159 additions & 0 deletions test/models.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
module TestModels

using SearchLight

######## Model from Genie-Searchligth-example-app extracted ############
export Book, BookWithInterns
using SearchLight, Dates

######## Model from Genie-Searchligth-example-app extracted ############
export Callback
export seed, fields_to_store

mutable struct Book <: AbstractModel

### FIELDS
id::DbId
title::String
author::String
cover::String

### VALIDATION
# validator::ModelValidator

### CALLBACKS
# before_save::Function
# after_save::Function
# on_save::Function
# on_find::Function
# after_find::Function

### SCOPES
# scopes::Dict{Symbol,Vector{SearchLight.SQLWhereEntity}}

### constructor
Book(;
### FIELDS
id = DbId(),
title = "",
author = "",
cover = "",

### VALIDATION
# validator = ModelValidator([
# ValidationRule(:title, BooksValidator.not_empty)
# ]),

### CALLBACKS
# before_save = (m::Todo) -> begin
# @info "Before save"
# end,
# after_save = (m::Todo) -> begin
# @info "After save"
# end,
# on_save = (m::Todo, field::Symbol, value::Any) -> begin
# @info "On save"
# end,
# on_find = (m::Todo, field::Symbol, value::Any) -> begin
# @info "On find"
# end,
# after_find = (m::Todo) -> begin
# @info "After find"
# end,

### SCOPES
# scopes = Dict{Symbol,Vector{SearchLight.SQLWhereEntity}}()

) = new(id, title, author, cover ### FIELDS
# validator, ### VALIDATION
# before_save, after_save, on_save, on_find, after_find ### CALLBACKS
# scopes ### SCOPES
)
end

mutable struct BookWithInterns <: AbstractModel
Copy link
Member

Choose a reason for hiding this comment

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

Can you please update/cleanup the model to the latest API? We no longer use the _table_name, _id, _serializable fields. Just so that it's not confusing for the users looking at the tests to learn.

### FIELDS
id::DbId
title::String
author::String
cover::String

### VALIDATION
# validator::ModelValidator

### CALLBACKS
# before_save::Function
# after_save::Function
# on_save::Function
# on_find::Function
# after_find::Function

### SCOPES
# scopes::Dict{Symbol,Vector{SearchLight.SQLWhereEntity}}

### constructor
BookWithInterns(;
### FIELDS
id = DbId(),
title = "",
author = "",
cover = "",

### VALIDATION
# validator = ModelValidator([
# ValidationRule(:title, BooksValidator.not_empty)
# ]),

### CALLBACKS
# before_save = (m::Todo) -> begin
# @info "Before save"
# end,
# after_save = (m::Todo) -> begin
# @info "After save"
# end,
# on_save = (m::Todo, field::Symbol, value::Any) -> begin
# @info "On save"
# end,
# on_find = (m::Todo, field::Symbol, value::Any) -> begin
# @info "On find"
# end,
# after_find = (m::Todo) -> begin
# @info "After find"
# end,

### SCOPES
# scopes = Dict{Symbol,Vector{SearchLight.SQLWhereEntity}}()

) = new("bookwithinterns", "id", Symbol[], ### INTERNALS
id, title, author, cover ### FIELDS
# validator, ### VALIDATION
# before_save, after_save, on_save, on_find, after_find ### CALLBACKS
# scopes ### SCOPES
)
end

Base.@kwdef mutable struct Callback <: AbstractModel
id::DbId = DbId()
title::String = ""
indicator::Bool = true
created_at::String = string(Dates.now())
# callbacks
before_save::Function = (m::Callback) -> begin
@info "Do something before saving"
end
after_save::Function = (m::Callback) -> begin
@info "Do something after saving"
end
end

function seed()
BillGatesBooks = [
("The Best We Could Do", "Thi Bui"),
("Evicted: Poverty and Profit in the American City", "Matthew Desmond"),
("Believe Me: A Memoir of Love, Death, and Jazz Chickens", "Eddie Izzard"),
("The Sympathizer!", "Viet Thanh Nguyen"),
("Energy and Civilization, A History", "Vaclav Smil")
]
end

end ### End Module
13 changes: 13 additions & 0 deletions test/postgres_connection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
env: dev

dev:
adapter: PostgreSQL
host: postgres
port: 5432
database: postgres
username: postgres
password: postgres

config:
log_queries: true
log_level: :debug
Loading