Skip to content

test: handle everything with go test #137

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 4 additions & 32 deletions .github/workflows/reusable_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,8 @@ jobs:
with:
go-version: 1.13

- name: Run base tests
run: |
mkdir snap xlog
TNT_PID=$(tarantool ./config.lua > tarantool.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID

- name: Run queue tests
working-directory: ./queue
run: |
mkdir snap xlog
tarantoolctl rocks install queue 1.1.0
TNT_PID=$(tarantool ./config.lua > tarantool.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID
- name: Install test dependencies
run: make deps

- name: Run uuid tests
working-directory: ./uuid
run: |
mkdir snap xlog
TNT_PID=$(tarantool ./config.lua > tarantool.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID
if: ${{ !startsWith(env.TNT_VERSION, 'Tarantool 1.10') }}

- name: Run multi tests
working-directory: ./multi
run: |
mkdir -p m1/{snap,xlog} m2/{snap,xlog}
TNT_PID_1=$(tarantool ./config_m1.lua > tarantool_m1.log 2>&1 & echo $!)
TNT_PID_2=$(tarantool ./config_m2.lua > tarantool_m2.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID_1 $TNT_PID_2
- name: Run tests
run: make test
38 changes: 4 additions & 34 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,8 @@ jobs:
with:
go-version: 1.13

- name: Run base tests
run: |
mkdir snap xlog
TNT_PID=$(tarantool ./config.lua > tarantool.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID
- name: Install test dependencies
run: make deps

- name: Run queue tests
working-directory: ./queue
run: |
rm -rf snap
rm -rf xlog
mkdir snap xlog
tarantoolctl rocks install queue 1.1.0
TNT_PID=$(tarantool ./config.lua > tarantool.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID

- name: Run uuid tests
working-directory: ./uuid
run: |
mkdir snap xlog
TNT_PID=$(tarantool ./config.lua > tarantool.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID
if: ${{ matrix.tarantool != 1.10 }}

- name: Run multi tests
working-directory: ./multi
run: |
mkdir -p m1/{snap,xlog} m2/{snap,xlog}
TNT_PID_1=$(tarantool ./config_m1.lua > tarantool_m1.log 2>&1 & echo $!)
TNT_PID_2=$(tarantool ./config_m2.lua > tarantool_m2.log 2>&1 & echo $!)
go clean -testcache && go test -v
kill $TNT_PID_1 $TNT_PID_2
- name: Run tests
run: make test
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.DS_Store
*.swp
.idea/
snap
xlog
work_dir*
.rocks
28 changes: 28 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
redefined = false

globals = {
'box',
'utf8',
'checkers',
'_TARANTOOL'
}

include_files = {
'**/*.lua',
'*.luacheckrc',
'*.rockspec'
}

exclude_files = {
'**/*.rocks/'
}

max_line_length = 120

ignore = {
"212/self", -- Unused argument <self>.
"411", -- Redefining a local variable.
"421", -- Shadowing a local variable.
"431", -- Shadowing an upvalue.
"432", -- Shadowing an upvalue argument.
}
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SHELL := /bin/bash

.PHONY: clean
clean:
( cd ./queue; rm -rf .rocks )

.PHONY: deps
deps: clean
( cd ./queue; tarantoolctl rocks install queue 1.1.0 )

.PHONY: test
test:
go clean -testcache
go test ./... -v -p 1
106 changes: 55 additions & 51 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
-- Do not set listen for now so connector won't be
-- able to send requests until everything is configured.
box.cfg{
listen = 3013,
wal_dir='xlog',
snap_dir='snap',
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}

box.once("init", function()
local s = box.schema.space.create('test', {
id = 512,
if_not_exists = true,
})
s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})

local st = box.schema.space.create('schematest', {
id = 514,
temporary = true,
if_not_exists = true,
field_count = 7,
format = {
{name = "name0", type = "unsigned"},
{name = "name1", type = "unsigned"},
{name = "name2", type = "string"},
{name = "name3", type = "unsigned"},
{name = "name4", type = "unsigned"},
{name = "name5", type = "string"},
},
})
st:create_index('primary', {
type = 'hash',
parts = {1, 'uint'},
unique = true,
if_not_exists = true,
})
st:create_index('secondary', {
id = 3,
type = 'tree',
unique = false,
parts = { 2, 'uint', 3, 'string' },
if_not_exists = true,
})
st:truncate()

--box.schema.user.grant('guest', 'read,write,execute', 'universe')
box.schema.func.create('box.info')
box.schema.func.create('simple_incr')

-- auth testing: access control
box.schema.user.create('test', {password = 'test'})
box.schema.user.grant('test', 'execute', 'universe')
box.schema.user.grant('test', 'read,write', 'space', 'test')
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
local s = box.schema.space.create('test', {
id = 512,
if_not_exists = true,
})
s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})

local st = box.schema.space.create('schematest', {
id = 514,
temporary = true,
if_not_exists = true,
field_count = 7,
format = {
{name = "name0", type = "unsigned"},
{name = "name1", type = "unsigned"},
{name = "name2", type = "string"},
{name = "name3", type = "unsigned"},
{name = "name4", type = "unsigned"},
{name = "name5", type = "string"},
},
})
st:create_index('primary', {
type = 'hash',
parts = {1, 'uint'},
unique = true,
if_not_exists = true,
})
st:create_index('secondary', {
id = 3,
type = 'tree',
unique = false,
parts = { 2, 'uint', 3, 'string' },
if_not_exists = true,
})
st:truncate()

--box.schema.user.grant('guest', 'read,write,execute', 'universe')
box.schema.func.create('box.info')
box.schema.func.create('simple_incr')

-- auth testing: access control
box.schema.user.create('test', {password = 'test'})
box.schema.user.grant('test', 'execute', 'universe')
box.schema.user.grant('test', 'read,write', 'space', 'test')
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
end)

function simple_incr(a)
return a+1
local function simple_incr(a)
return a + 1
end
rawset(_G, 'simple_incr', simple_incr)

box.space.test:truncate()
local console = require 'console'
console.listen '0.0.0.0:33015'

--box.schema.user.revoke('guest', 'read,write,execute', 'universe')

-- Set listen only when every other thing is configured.
box.cfg{
listen = os.getenv("TEST_TNT_LISTEN"),
}
21 changes: 21 additions & 0 deletions multi/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
local nodes_load = require("config_load_nodes")

-- Do not set listen for now so connector won't be
-- able to send requests until everything is configured.
box.cfg{
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}

-- Function to call for getting address list, part of tarantool/multi API.
local get_cluster_nodes = nodes_load.get_cluster_nodes
rawset(_G, 'get_cluster_nodes', get_cluster_nodes)

box.once("init", function()
box.schema.user.create('test', { password = 'test' })
box.schema.user.grant('test', 'read,write,execute', 'universe')
end)

-- Set listen only when every other thing is configured.
box.cfg{
listen = os.getenv("TEST_TNT_LISTEN"),
}
14 changes: 0 additions & 14 deletions multi/config_m1.lua

This file was deleted.

14 changes: 0 additions & 14 deletions multi/config_m2.lua

This file was deleted.

54 changes: 54 additions & 0 deletions multi/multi_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package multi

import (
"log"
"os"
"testing"
"time"

"github.com/tarantool/go-tarantool"
"github.com/tarantool/go-tarantool/test_helpers"
)

var server1 = "127.0.0.1:3013"
Expand Down Expand Up @@ -204,3 +207,54 @@ func TestRefresh(t *testing.T) {
t.Error("Expect to get data after reconnect")
}
}

// runTestMain is a body of TestMain function
// (see https://pkg.go.dev/testing#hdr-Main).
// Using defer + os.Exit is not works so TestMain body
// is a separate function, see
// https://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls
func runTestMain(m *testing.M) int {
initScript := "config.lua"
waitStart := 100 * time.Millisecond
var connectRetry uint = 3
retryTimeout := 500 * time.Millisecond

inst1, err := test_helpers.StartTarantool(test_helpers.StartOpts{
InitScript: initScript,
Listen: server1,
WorkDir: "work_dir1",
User: connOpts.User,
Pass: connOpts.Pass,
WaitStart: waitStart,
ConnectRetry: connectRetry,
RetryTimeout: retryTimeout,
})
defer test_helpers.StopTarantoolWithCleanup(inst1)

if err != nil {
log.Fatalf("Failed to prepare test tarantool: %s", err)
}

inst2, err := test_helpers.StartTarantool(test_helpers.StartOpts{
InitScript: initScript,
Listen: server2,
WorkDir: "work_dir2",
User: connOpts.User,
Pass: connOpts.Pass,
WaitStart: waitStart,
ConnectRetry: connectRetry,
RetryTimeout: retryTimeout,
})
defer test_helpers.StopTarantoolWithCleanup(inst2)

if err != nil {
log.Fatalf("Failed to prepare test tarantool: %s", err)
}

return m.Run()
}

func TestMain(m *testing.M) {
code := runTestMain(m)
os.Exit(code)
}
Loading