-
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
4f2c3cb
commit 226ab35
Showing
15 changed files
with
898 additions
and
3 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,41 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
import "testing" | ||
|
||
func TestClientBlocksEmpty(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "blocks"}) | ||
assertContainsSubstring(t, stdout, "Usage:") | ||
} | ||
|
||
func TestClientBlocksGetEmpty(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "blocks", "get"}) | ||
assertContainsSubstring(t, stdout, "Usage:") | ||
} | ||
|
||
func TestClientBlocksGetInvalidCID(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "blocks", "get", "invalid-cid"}) | ||
_ = stopDefra() | ||
assertContainsSubstring(t, stdout, "\"errors\"") | ||
} | ||
|
||
func TestClientBlocksGetNonExistentCID(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "blocks", "get", "bafybeieelb43ol5e5jiick2p7k4p577ph72ecwcuowlhbops4hpz24zhz4"}) | ||
_ = stopDefra() | ||
assertContainsSubstring(t, stdout, "could not find") | ||
} |
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,34 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPeerID(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
|
||
stdout, _ := runDefraCommand(t, conf, []string{"client", "peerid"}) | ||
|
||
defraLogLines := stopDefra() | ||
|
||
assertNotContainsSubstring(t, defraLogLines, "ERROR") | ||
|
||
assertContainsSubstring(t, stdout, "peerID") | ||
} | ||
|
||
func TestPeerIDWithNoHost(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
_, stderr := runDefraCommand(t, conf, []string{"client", "peerid"}) | ||
assertContainsSubstring(t, stderr, "failed to request peer ID") | ||
} |
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,63 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/config" | ||
) | ||
|
||
func TestPingSimple(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
|
||
stdout, _ := runDefraCommand(t, conf, []string{"client", "ping"}) | ||
|
||
nodeLog := stopDefra() | ||
|
||
assert.Contains(t, stdout, `{"data":{"response":"pong"}}`) | ||
for _, line := range nodeLog { | ||
assert.NotContains(t, line, "ERROR") | ||
} | ||
} | ||
|
||
func TestPingCommandToInvalidHost(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
_, stderr := runDefraCommand(t, conf, []string{"client", "ping", "--url", "'1!2:3!4'"}) | ||
|
||
nodeLog := stopDefra() | ||
|
||
for _, line := range nodeLog { | ||
assert.NotContains(t, line, "ERROR") | ||
} | ||
// for some line in stderr to contain the error message | ||
for _, line := range stderr { | ||
if strings.Contains(line, config.ErrFailedToValidateConfig.Error()) { | ||
return | ||
} | ||
} | ||
t.Error("expected error message not found in stderr") | ||
} | ||
|
||
func TestPingCommandNoHost(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
p, err := findFreePortInRange(49152, 65535) | ||
assert.NoError(t, err) | ||
addr := fmt.Sprintf("localhost:%d", p) | ||
_, stderr := runDefraCommand(t, conf, []string{"client", "ping", "--url", addr}) | ||
assertContainsSubstring(t, stderr, "failed to send ping") | ||
} |
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,66 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRequestSimple(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
|
||
stdout, _ := runDefraCommand(t, conf, []string{"client", "query", | ||
"query IntrospectionQuery {__schema {queryType { name }}}", | ||
}) | ||
nodeLog := stopDefra() | ||
|
||
assertContainsSubstring(t, stdout, "Query") | ||
assertNotContainsSubstring(t, nodeLog, "ERROR") | ||
} | ||
|
||
func TestRequestInvalidQuery(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
|
||
stdout, _ := runDefraCommand(t, conf, []string{"client", "query", "{}}"}) | ||
_ = stopDefra() | ||
|
||
assertContainsSubstring(t, stdout, "Syntax Error") | ||
} | ||
|
||
func TestRequestWithErrorNoType(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
defer stopDefra() | ||
|
||
stdout, _ := runDefraCommand(t, conf, []string{"client", "query", "query { User { whatever } }"}) | ||
|
||
assertContainsSubstring(t, stdout, "Cannot query field") | ||
} | ||
|
||
func TestRequestWithErrorNoField(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
defer stopDefra() | ||
|
||
fname := schemaFileFixture(t, "schema.graphql", ` | ||
type User { | ||
id: ID | ||
name: String | ||
}`) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname}) | ||
assertContainsSubstring(t, stdout, "success") | ||
|
||
stdout, _ = runDefraCommand(t, conf, []string{"client", "query", "query { User { nonexistent } }"}) | ||
|
||
assertContainsSubstring(t, stdout, `Cannot query field \"nonexistent\"`) | ||
} |
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,13 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
// TBD |
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,22 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
/* WIP client rpc replicator getall is broken currently | ||
func TestReplicatorGetAllEmpty(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
defer stopDefra() | ||
_, stderr := runDefraCommand(t, conf, []string{"client", "rpc", "replicator", "getall"}) | ||
assertContainsSubstring(t, stderr, "No replicator found") | ||
} | ||
*/ |
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,95 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAddSchemaFromFile(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
|
||
fname := schemaFileFixture(t, "schema.graphql", ` | ||
type User { | ||
id: ID | ||
name: String | ||
}`) | ||
|
||
stdout, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname}) | ||
|
||
nodeLog := stopDefra() | ||
|
||
assert.Contains(t, stdout, `{"data":{"result":"success"}}`) | ||
assertNotContainsSubstring(t, nodeLog, "ERROR") | ||
} | ||
|
||
func TestAddSchemaWithDuplicateType(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
|
||
fname1 := schemaFileFixture(t, "schema1.graphql", `type Post { id: ID title: String }`) | ||
fname2 := schemaFileFixture(t, "schema2.graphql", `type Post { id: ID author: String }`) | ||
|
||
stdout1, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname1}) | ||
stdout2, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname2}) | ||
|
||
_ = stopDefra() | ||
|
||
assertContainsSubstring(t, stdout1, `{"data":{"result":"success"}}`) | ||
assertContainsSubstring(t, stdout2, `schema type already exists. Name: Post`) | ||
} | ||
|
||
/* disabled because current implementation doesn't support this currently | ||
func TestAddSchemaWithMultipleFiles(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
fname1 := schemaFileFixture(t, "schema1.graphql", `type Post { id: ID title: String }`) | ||
fname2 := schemaFileFixture(t, "schema2.graphql", `type User { id: ID name: String }`) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname1, "-f", fname2}) | ||
nodeLog := stopDefra() | ||
assertContainsSubstring(t, stdout, `{"data":{"result":"success"}}`) | ||
assertNotContainsSubstring(t, nodeLog, "ERROR") | ||
stdout, _ = runDefraCommand(t, conf, []string{"client", "query", | ||
`query IntrospectionQuery { __schema { types { name } } }`}) | ||
assertContainsSubstring(t, stdout, `{"name":"Post"}`) | ||
assertContainsSubstring(t, stdout, `{"name":"User"}`) | ||
} | ||
*/ | ||
|
||
/* disabled because current implementation doesn't support this currently | ||
func TestAddSchemaWithMultipleFilesWithIntertwinedSchemas(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
fname1 := schemaFileFixture(t, "schema1.graphql", `type Post { id: ID title: String }`) | ||
fname2 := schemaFileFixture(t, "schema2.graphql", `type User { id: ID posts: [Post] }`) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname1, "-f", fname2}) | ||
nodeLog := stopDefra() | ||
assertContainsSubstring(t, stdout, `{"data":{"result":"success"}}`) | ||
assertNotContainsSubstring(t, nodeLog, "ERROR") | ||
stdout, _ = runDefraCommand(t, conf, []string{"client", "query", | ||
`query IntrospectionQuery { __schema { types { name } } }`}) | ||
assertContainsSubstring(t, stdout, `{"name":"Post"}`) | ||
assertContainsSubstring(t, stdout, `{"name":"User"}`) | ||
} | ||
*/ |
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,53 @@ | ||
// 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. | ||
|
||
package clitest | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestClientSchemaPatch(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
defer stopDefra() | ||
|
||
fname := schemaFileFixture(t, "schema.graphql", ` | ||
type User { | ||
id: ID | ||
name: String | ||
}`) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname}) | ||
assertContainsSubstring(t, stdout, "success") | ||
|
||
stdout, _ = runDefraCommand(t, conf, []string{"client", "schema", "patch", `[{ "op": "add", "path": "/User/Schema/Fields/-", "value": {"Name": "address", "Kind": "String"} }]`}) | ||
assertContainsSubstring(t, stdout, "success") | ||
|
||
stdout, _ = runDefraCommand(t, conf, []string{"client", "query", `query IntrospectionQuery { __type (name: "User") { fields { name } }}`}) | ||
assertContainsSubstring(t, stdout, "address") | ||
} | ||
|
||
func TestClientSchemaPatch_InvalidJSONPatch(t *testing.T) { | ||
conf := NewDefraNodeDefaultConfig(t) | ||
stopDefra := runDefraNode(t, conf) | ||
defer stopDefra() | ||
|
||
fname := schemaFileFixture(t, "schema.graphql", ` | ||
type User { | ||
id: ID | ||
name: String | ||
} | ||
`) | ||
stdout, _ := runDefraCommand(t, conf, []string{"client", "schema", "add", "-f", fname}) | ||
assertContainsSubstring(t, stdout, "success") | ||
|
||
stdout, _ = runDefraCommand(t, conf, []string{"client", "schema", "patch", `[{ "op": "invalidOp" }]`}) | ||
assertContainsSubstring(t, stdout, "Internal Server Error") | ||
} |
Oops, something went wrong.