-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7839112
commit 6334854
Showing
11 changed files
with
636 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
//go:build integrationcli | ||
// +build integrationcli | ||
|
||
package clitest | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/cli" | ||
"github.com/sourcenetwork/defradb/config" | ||
) | ||
|
||
func TestPingCommandToValidHostWithNoNode(t *testing.T) { | ||
logLines := captureStderr(t, func() { | ||
cfg := config.NewWithDefaults() | ||
defraCmd := cli.NewDefraCommand(cfg) | ||
defraCmd.RootCmd.SetArgs([]string{"client", "ping", "--url", "localhost:9876"}) | ||
assert.Error(t, defraCmd.Execute(context.Background())) | ||
}) | ||
gotExpectedError := false | ||
expectedError1 := "{\"Error\": \"failed to send ping: Get \\\"http://localhost:9876/api/v0/ping\\\": dial tcp [::1]:9876: connect: connection refused\"}" | ||
expectedError2 := "{\"Error\": \"failed to send ping: Get \\\"http://localhost:9876/api/v0/ping\\\": dial tcp 127.0.0.1:9876: connect: connection refused\"}" | ||
for _, line := range logLines { | ||
if strings.Contains(line, expectedError1) || strings.Contains(line, expectedError2) { | ||
gotExpectedError = true | ||
break | ||
} | ||
} | ||
assert.True(t, gotExpectedError) | ||
} | ||
|
||
func TestPingCommandToInvalidHost(t *testing.T) { | ||
logLines := captureStderr(t, func() { | ||
cfg := config.NewWithDefaults() | ||
defraCmd := cli.NewDefraCommand(cfg) | ||
defraCmd.RootCmd.SetArgs([]string{"client", "ping", "--url", "'1!2:3!4'"}) | ||
assert.Error(t, defraCmd.Execute(context.Background())) | ||
}) | ||
expectedError := "{\"Error\": \"failed to load config: failed to validate API config: invalid database URL provided\"}" | ||
assert.Contains(t, parseLogLine(logLines[0]), expectedError) | ||
} | ||
|
||
func TestPingCommandToValidLocalhostwithFramework(t *testing.T) { | ||
cfg := config.NewWithDefaults() | ||
testCfg := newRandomTestConfig(t) | ||
cfg.API.Address = testCfg.serialize().APIAddress | ||
cfg.Rootdir = testCfg.serialize().RootDir | ||
defraCmd := cli.NewDefraCommand(cfg) | ||
// defer(releasePortsOfCommand(defraCmd)) | ||
logLines := testFrameworkWithBackgroundNodeExec(t, testCfg, func() { | ||
defraCmd.RootCmd.SetArgs([]string{"client", "ping"}) | ||
err := defraCmd.Execute(context.Background()) | ||
assert.NoError(t, err) | ||
}) | ||
expectedOutput := `{"data":{"response":"pong"}}` | ||
assert.Contains(t, parseLogLine(logLines[0]), expectedOutput) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
//go:build integrationcli | ||
// +build integrationcli | ||
|
||
package clitest | ||
|
||
/* | ||
- schema | ||
- add | ||
- blocks | ||
- get | ||
- dump | ||
- peerid | ||
- query | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
//go:build integrationcli | ||
// +build integrationcli | ||
|
||
package clitest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/cli" | ||
"github.com/sourcenetwork/defradb/config" | ||
) | ||
|
||
// Executing init command creates valid config file. | ||
func TestCLIInitCommand(t *testing.T) { | ||
tmpdir := t.TempDir() | ||
logLines := captureStderr(t, func() { | ||
defraCmd := cli.NewDefraCommand(config.NewWithDefaults()) | ||
defraCmd.RootCmd.SetArgs([]string{"init", "--rootdir", tmpdir}) | ||
assert.NoError(t, defraCmd.Execute(context.Background())) | ||
}) | ||
t.Log(logLines) | ||
assert.Contains(t, parseLogLine(logLines[0]), "Initialized configuration file at "+tmpdir+"/"+config.DefaultConfigFileName) | ||
|
||
cfg := config.NewWithDefaults() | ||
cfg.Rootdir = tmpdir | ||
assert.NoError(t, cfg.Load(true)) | ||
} | ||
|
||
// Executing init command twice leads to error. | ||
// func TestCLIInitCommandTwiceErrors(t *testing.T) { | ||
// tmpdir := t.TempDir() | ||
// logLines := captureStderr(t, func() { | ||
// rootCmd := cli.NewDefraCommand(config.NewWithDefaults()).RootCmd | ||
// rootCmd.SetArgs([]string{"init", tmpdir}) | ||
// assert.NoError(t, rootCmd.Execute()) | ||
// }) | ||
// assert.Contains(t, parseLogLine(logLines[0]), "Initialized configuration file at "+tmpdir+"/"+config.DefaultConfigFileName) | ||
// logLines = captureStderr(t, func() { | ||
// rootCmd := cli.NewDefraCommand(config.NewWithDefaults()).RootCmd | ||
// rootCmd.SetArgs([]string{"init", tmpdir}) | ||
// assert.NoError(t, rootCmd.Execute()) // TBD: should this be an error? | ||
// }) | ||
// assert.Contains(t, parseLogLine(logLines[0]), "Configuration file already exists at "+tmpdir+"/"+config.DefaultConfigFileName+". Consider using --reinitialize") | ||
// } | ||
|
||
// Executing init command twice, but second time reinitializing. | ||
// func TestInitCommandTwiceReinitalize(t *testing.T) { | ||
// tmpdir := t.TempDir() | ||
// defraCommand := cli.NewDefraCommand(config.NewWithDefaults()) | ||
// logLines := captureStderr(t, func() { | ||
// defraCommand.RootCmd.SetArgs([]string{"init", "--rootdir", tmpdir}) | ||
// assert.NoError(t, defraCommand.Execute(context.Background())) | ||
// }) | ||
// t.Log(logLines) | ||
// assert.Contains(t, parseLogLine(logLines[0]), "Initialized configuration file at "+tmpdir+"/"+config.DefaultConfigFileName) | ||
// // logLines = captureStderr(t, func() { | ||
// // rootCmd.SetArgs([]string{"init", tmpdir, "--reinitialize"}) | ||
// // assert.NoError(t, rootCmd.Execute()) | ||
// // }) | ||
// // assert.Contains(t, parseLogLine(logLines[0]), "Reinitialized configuration file at "+tmpdir+"/"+config.DefaultConfigFileName) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
//go:build integrationcli | ||
// +build integrationcli | ||
|
||
package clitest | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/cli" | ||
"github.com/sourcenetwork/defradb/config" | ||
) | ||
|
||
func TestRootCommandEmptyRootDir(t *testing.T) { | ||
defraCmd := cli.NewDefraCommand(config.NewWithDefaults()) | ||
tmpdir := t.TempDir() | ||
defraCmd.RootCmd.SetArgs([]string{"--rootdir", tmpdir}) | ||
assert.NoError(t, defraCmd.Execute(context.Background())) | ||
assert.Equal(t, config.NewWithDefaults(), defraCmd.Cfg) | ||
} | ||
|
||
func TestRootCommandRootDirWithDefaultConfig(t *testing.T) { | ||
defraCmd := cli.NewDefraCommand(config.NewWithDefaults()) | ||
tmpdir := t.TempDir() | ||
cfg := config.NewWithDefaults() | ||
cfg.Rootdir = tmpdir | ||
assert.NoError(t, cfg.CreateRootDir()) | ||
defraCmd.RootCmd.SetArgs([]string{"--rootdir", tmpdir}) | ||
assert.NoError(t, defraCmd.Execute(context.Background())) | ||
assert.Equal(t, config.NewWithDefaults(), defraCmd.Cfg) | ||
} | ||
|
||
// loaded config is non-default | ||
func TestRootCommandRootDirWithNonDefaultConfig(t *testing.T) { | ||
tmpdir := t.TempDir() | ||
cfg := config.NewWithDefaults() | ||
cfg.Rootdir = tmpdir | ||
defraCmd := cli.NewDefraCommand(cfg) | ||
defraCmd.Cfg.Datastore.Store = "memory" | ||
assert.NoError(t, defraCmd.Cfg.WriteConfigFile()) | ||
defraCmd.RootCmd.SetArgs([]string{"--rootdir", tmpdir}) | ||
assert.NoError(t, defraCmd.Execute(context.Background())) | ||
assert.Equal(t, "memory", defraCmd.Cfg.Datastore.Store) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
//go:build integrationcli | ||
// +build integrationcli | ||
|
||
package clitest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
//go:build integrationcli | ||
// +build integrationcli | ||
|
||
package clitest | ||
|
||
/* | ||
import ( | ||
"bufio" | ||
"os" | ||
"testing" | ||
"github.com/sourcenetwork/defradb/cli" | ||
) | ||
// Execution error, {"Error": "badger store does not exist at /Users/o/.defradb/data. Try with an existing directory"} | ||
func TestServerDump(t *testing.T) { | ||
lines := capture(t, func() { | ||
cmd := cli.MakeCommandTree() | ||
tmpdir := t.TempDir() | ||
cmd.SetArgs([]string{"init", tmpdir}) | ||
cmd.Execute() | ||
cmd.SetArgs([]string{"--rootdir", tmpdir, "server-dump"}) | ||
cmd.Execute() | ||
// tmpdir := t.TempDir() | ||
// initCmd := cli.MakeInitCommand() | ||
// initCmd.SetArgs([]string{tmpdir}) | ||
// initCmd.Execute() | ||
// serverDumpCmd := cli.MakeServerDumpCmd() | ||
// serverDumpCmd.Execute() | ||
}) | ||
t.Log(lines) | ||
t.Fail() | ||
// Dumping DB state | ||
// keys are like | ||
// /db/blocks/ | ||
// /db/data/ | ||
// /db/system/ | ||
// /peers/peers/ | ||
// /providers/ | ||
} | ||
func TestServerDumpMemoryErrs(t *testing.T) { | ||
// we expect the following error: | ||
// Execution error, {"Error": "server-side dump is only supported for the Badger datastore"} | ||
} | ||
*/ |
Oops, something went wrong.