Skip to content

[WIP] Increate cmd folder test cover #353

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

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d47ed78
Add generate_test
744189447 May 21, 2019
8c8d630
Add cql test
744189447 May 23, 2019
11018f1
Return to break the loop
744189447 May 24, 2019
dbdafca
Add UnInit function for unit test
744189447 May 24, 2019
f69369a
Add cql unit test of all
744189447 May 24, 2019
d811390
Delete waiting for transaction confirmation
744189447 May 24, 2019
dfa5db8
Include cmd and test folder unit test calc.
May 20, 2019
1603c26
Merge branch 'develop' into feature/cql_test
May 24, 2019
ce876df
Delete waiting for transaction confirmation
744189447 May 27, 2019
d18ae8e
Add generate_test
744189447 May 21, 2019
27b3b60
Add cql test
744189447 May 23, 2019
b22a322
Add UnInit function for unit test
744189447 May 24, 2019
b9742c3
Add cql unit test of all
744189447 May 24, 2019
1392997
Delete waiting for transaction confirmation
744189447 May 24, 2019
0bb5ed2
Include cmd and test folder unit test calc.
May 20, 2019
5539863
Delete waiting for transaction confirmation
744189447 May 27, 2019
029d710
Fix readline data race by fork repo.
May 27, 2019
44bc075
Add cqld bootstrap test
744189447 May 28, 2019
f9873c9
Reset common vars before each cql test convey.
May 28, 2019
228a21f
Remove cql unit test grant wait.
May 28, 2019
68622ee
Reduce cql generate test difficulty.
May 28, 2019
800327a
Fix cql idminer goroutine may blocked by channel.
May 28, 2019
ec151b1
Reset go test script to develop.
May 29, 2019
fc77335
Merge branch 'develop' into feature/cql_test
May 29, 2019
a9dfb14
Merge remote-tracking branch 'origin/feature/cql_test' into feature/c…
744189447 May 29, 2019
029631c
Delete the working directory declaration
744189447 May 29, 2019
c6b147b
Add error tests
744189447 May 29, 2019
9f237f7
Merge branch 'develop' into feature/cql_test
Jun 5, 2019
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
5 changes: 3 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

[[override]]
name = "github.com/gohxs/readline"
source = "github.com/CovenantSQL/readline"
branch = "master"

[[override]]
Expand Down
9 changes: 9 additions & 0 deletions client/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ func Init(configFile string, masterKey []byte) (err error) {
return
}

// UnInit is just for unit test. Do not use it!
func UnInit() {
if !atomic.CompareAndSwapUint32(&driverInitialized, 1, 0) {
return
}

stopPeersUpdater()
}

// Create sends create database operation to block producer.
func Create(meta ResourceMeta) (txHash hash.Hash, dsn string, err error) {
if atomic.LoadUint32(&driverInitialized) == 0 {
Expand Down
43 changes: 43 additions & 0 deletions cmd/cql/internal/adapter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// +build !testbinary

/*
* Copyright 2018-2019 The CovenantSQL Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package internal

import (
"testing"

"github.com/CovenantSQL/CovenantSQL/client"
. "github.com/smartystreets/goconvey/convey"
)

func TestAdapter(t *testing.T) {
Convey("adapter", t, func() {
// reset
commonVarsReset()
adapterAddr = ""
adapterUseMirrorAddr = ""

adapterAddr = "127.0.0.1:9001"
configFile = FJ(testWorkingDir, "./bench_testnet/node_c/config.yaml")
client.UnInit()
configInit()
bgServerInit()
cancelFunc := startAdapterServer(adapterAddr, adapterUseMirrorAddr)
cancelFunc()
})
}
85 changes: 85 additions & 0 deletions cmd/cql/internal/base_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// +build !testbinary

/*
* Copyright 2018-2019 The CovenantSQL Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package internal

import (
"path/filepath"
"testing"

"github.com/CovenantSQL/CovenantSQL/utils"
. "github.com/smartystreets/goconvey/convey"
)

var (
FJ = filepath.Join
baseDir = utils.GetProjectSrcDir()
testWorkingDir = FJ(baseDir, "./test/")
)

func commonVarsReset() {
// common flags
help = false
withPassword = false
password = ""
consoleLogLevel = "info"

// config flags
configFile = "~/.cql/config.yaml"
waitTxConfirmationMaxDuration = 0

// wait flag
waitTxConfirmation = false

// bg server flags
tmpPath = ""
bgLogLevel = "info"

// reset exit status
SetExitStatus(0)
}

func TestBase(t *testing.T) {
cmd := Command{
UsageLine: "cql generate",
}

Convey("LongName", t, func() {
longName := cmd.LongName()
So(longName, ShouldResemble, "generate")
})

Convey("Name", t, func() {
name := cmd.Name()
So(name, ShouldResemble, "generate")
})

//Convey("Usage", t, func() {
// go cmd.Usage()
// time.Sleep(1 * time.Second)
//})

//Convey("Exit", t, func() {
// go func() {
// SetExitStatus(1)
// AtExit(func() {})
// ExitIfErrors()
// }()
// time.Sleep(1 * time.Second)
//})
}
48 changes: 48 additions & 0 deletions cmd/cql/internal/console_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// +build !testbinary

/*
* Copyright 2018-2019 The CovenantSQL Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package internal

import (
"testing"

"github.com/CovenantSQL/CovenantSQL/client"
. "github.com/smartystreets/goconvey/convey"
)

func TestConsole(t *testing.T) {
Convey("console", t, func() {
// reset
commonVarsReset()
variables = varsFlag{}
dsn = ""
outFile = ""
noRC = false
singleTransaction = false
command = ""
fileName = ""
adapterAddr = ""
explorerAddr = ""
client.UnInit()

dsn = "covenantsql://c9e8b381aa466a8d9955701967ad5535e7899ab138b8674ab14b31b75c64b656"
command = "select 1 from test1;"
configFile = FJ(testWorkingDir, "./bench_testnet/node_c/config.yaml")
runConsole(CmdConsole, []string{dsn})
})
}
54 changes: 54 additions & 0 deletions cmd/cql/internal/create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// +build !testbinary

/*
* Copyright 2018-2019 The CovenantSQL Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package internal

import (
"testing"

"github.com/CovenantSQL/CovenantSQL/client"
. "github.com/smartystreets/goconvey/convey"
)

func TestCreate(t *testing.T) {
Convey("create", t, func() {
// reset
commonVarsReset()
targetMiners = List{}
node32 = 0
meta = client.ResourceMeta{}
client.UnInit()

//targetMiners = List{[]string{"000005aa62048f85da4ae9698ed59c14ec0d48a88a07c15a32265634e7e64ade", "000005f4f22c06f76c43c4f48d5a7ec1309cc94030cbf9ebae814172884ac8b5"}}
node32 = 1
// waitTxConfirmation = true
configFile = FJ(testWorkingDir, "./bench_testnet/node_c/config.yaml")
jsonStr := `
{
"loadavgpercpu": 0,
"encryptionkey": "",
"useeventualconsistency": false,
"consistencylevel": 1,
"isolationlevel": 1,
"gasprice": 1,
"advancepayment": 20000000
}
`
runCreate(CmdCreate, []string{jsonStr})
})
}
18 changes: 9 additions & 9 deletions cmd/cql/internal/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ func runDrop(cmd *Command, args []string) {
return
}

txHash, err := client.Drop(dsn)
_, err := client.Drop(dsn)
if err != nil {
// drop database failed
ConsoleLog.WithField("db", dsn).WithError(err).Error("drop database failed")
SetExitStatus(1)
return
}

if waitTxConfirmation {
err = wait(txHash)
if err != nil {
ConsoleLog.WithField("db", dsn).WithError(err).Error("drop database failed")
SetExitStatus(1)
return
}
}
//if waitTxConfirmation {
// err = wait(txHash)
// if err != nil {
// ConsoleLog.WithField("db", dsn).WithError(err).Error("drop database failed")
// SetExitStatus(1)
// return
// }
//}

// drop database success
ConsoleLog.Infof("drop database %#v success", dsn)
Expand Down
39 changes: 39 additions & 0 deletions cmd/cql/internal/drop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// +build !testbinary

/*
* Copyright 2018 The CovenantSQL Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package internal

import (
"testing"

"github.com/CovenantSQL/CovenantSQL/client"
. "github.com/smartystreets/goconvey/convey"
)

func TestDrop(t *testing.T) {
Convey("drop", t, func() {
// reset
commonVarsReset()
client.UnInit()

dsn = "covenantsql://c9e8b381aa466a8d9955701967ad5535e7899ab138b8674ab14b31b75c64b656"
waitTxConfirmation = true
configFile = FJ(testWorkingDir, "./bench_testnet/node_c/config.yaml")
runDrop(CmdDrop, []string{dsn})
})
}
44 changes: 44 additions & 0 deletions cmd/cql/internal/explorer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// +build !testbinary

/*
* Copyright 2018-2019 The CovenantSQL Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package internal

import (
"testing"

"github.com/CovenantSQL/CovenantSQL/client"
. "github.com/smartystreets/goconvey/convey"
)

func TestExplorer(t *testing.T) {
Convey("explorer", t, func() {
// reset
commonVarsReset()
explorerAddr = ""
explorerService = nil
explorerHTTPServer = nil
client.UnInit()

explorerAddr = "127.0.0.1:9002"
configFile = FJ(testWorkingDir, "./bench_testnet/node_c/config.yaml")
configInit()
bgServerInit()
cancelFunc := startExplorerServer(explorerAddr)
cancelFunc()
})
}
Loading