Skip to content

Setting up test environment #6

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

Merged
merged 36 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a0efce
changed for tests inside CI
FrankUrbach Dec 14, 2021
5868342
test
FrankUrbach Dec 14, 2021
837b71b
test
FrankUrbach Dec 14, 2021
7adf59b
test
FrankUrbach Dec 14, 2021
3ef94e6
next test
FrankUrbach Dec 14, 2021
2cef8ff
test next
FrankUrbach Dec 14, 2021
7153425
next step
FrankUrbach Dec 14, 2021
3bc0a8f
next test
FrankUrbach Dec 14, 2021
0116a5a
try to solve it easy
FrankUrbach Dec 14, 2021
3edaaf4
next
FrankUrbach Dec 14, 2021
2141ccb
next test
FrankUrbach Dec 14, 2021
c55fa6a
next
FrankUrbach Dec 14, 2021
c8616f6
next attempt
FrankUrbach Dec 14, 2021
bd1a961
corrected test
FrankUrbach Dec 14, 2021
b5e1a99
next
FrankUrbach Dec 14, 2021
47ec1c2
next try
FrankUrbach Dec 14, 2021
6299bb1
next try
FrankUrbach Dec 14, 2021
b8f9b5a
maybe now
FrankUrbach Dec 14, 2021
330a98b
test
FrankUrbach Dec 14, 2021
9123d1f
test
FrankUrbach Dec 14, 2021
8ba021a
next run
FrankUrbach Dec 14, 2021
ec25cd0
next
FrankUrbach Dec 14, 2021
e4f687e
next test
FrankUrbach Dec 14, 2021
06ac263
maybe now
FrankUrbach Dec 14, 2021
6cae7d1
next try
FrankUrbach Dec 14, 2021
00c8829
to next
FrankUrbach Dec 14, 2021
d6f8408
to next
FrankUrbach Dec 14, 2021
484bc87
next
FrankUrbach Dec 14, 2021
0388f73
next first
FrankUrbach Dec 14, 2021
5cfb730
next try
FrankUrbach Dec 14, 2021
0b0b78a
next test right port
FrankUrbach Dec 14, 2021
ac40a67
changed according requests in PR#6
FrankUrbach Jan 5, 2022
2e3aa8a
missing package Pkg added
FrankUrbach Jan 5, 2022
a7a2edb
Changed the tests and the project according
FrankUrbach Jan 14, 2022
fa4f578
Pkg added to test Project.toml
FrankUrbach Jan 14, 2022
5042dbc
added Dates
FrankUrbach Jan 14, 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
39 changes: 39 additions & 0 deletions .github/workflows/Test_DB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: MySQLAdapter test
on: push

jobs:
# Label of the container job
container-job:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest

services:
mysql:
image: mysql:latest
env:
MYSQL_DATABASE: searchlight_tests
MYSQL_HOST: 127.0.0.1
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: rootpass
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

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 SearchLightMySQL
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/SearchLightMySQL.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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "2.0.0"
[deps]
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MySQL = "39abe10b-433b-5dbd-92d4-e302a9df00cd"
SearchLight = "340e8cb6-72eb-11e8-37ce-c97ebeb32050"
Expand Down
7 changes: 7 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
Copy link
Member

Choose a reason for hiding this comment

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

What happened to this file? Why so many dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

file is deleted

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"
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
160 changes: 160 additions & 0 deletions test/models.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
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
Copy link
Member

Choose a reason for hiding this comment

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

This could use the newer syntax based on @kwdef - but the this one should work equally well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The @kwdef phrase is only needed if you want to specify default values by creating instances of a struct. If this isn't needed because you set the values of the fields later you can use it in the form used here. But I know what you mean.


### 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

### 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/mysql_connection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
env: dev

dev:
adapter: MySQL
host: 127.0.0.1
port: 3306
database: searchlight_tests
username: mysql
password: mysql

config:
log_queries: true
log_level: :debug
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cd(@__DIR__)

using Pkg

using Test, TestSetExtensions, SafeTestsets
using SearchLight
using SearchLightMySQL
using Dates

# @testset ExtendedTestSet "SearchLight PostgreSQL adapter tests" begin
# @includetests ARGS
# end

# run a simple connect test for the first time

@testset ExtendedTestSet "SearchLight tests" begin
@includetests ARGS
end
Loading