-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1582 from hyperledger/add_coverage
Add more tests for missing coverage
- Loading branch information
Showing
9 changed files
with
462 additions
and
52 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,106 @@ | ||
// Copyright © 2022 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var configPath string = "../test/data/config/firefly.core.yaml" | ||
|
||
func TestMainFail(t *testing.T) { | ||
// Run the crashing code when FLAG is set | ||
if os.Getenv("FLAG") == "1" { | ||
main() | ||
return | ||
} | ||
// Run the test in a subprocess | ||
cmd := exec.Command(os.Args[0], "-test.run=TestMainFail") | ||
cmd.Env = append(os.Environ(), "FLAG=1") | ||
err := cmd.Run() | ||
|
||
// Cast the error as *exec.ExitError and compare the result | ||
e, ok := err.(*exec.ExitError) | ||
expectedErrorString := "exit status 1" | ||
assert.Equal(t, true, ok) | ||
assert.Equal(t, expectedErrorString, e.Error()) | ||
} | ||
|
||
func TestConfigMigrateRootCmdErrorNoArgs(t *testing.T) { | ||
rootCmd.SetArgs([]string{}) | ||
defer rootCmd.SetArgs([]string{}) | ||
err := rootCmd.Execute() | ||
assert.Error(t, err) | ||
assert.Regexp(t, "a command is required", err) | ||
} | ||
|
||
func TestConfigMigrateCmdMissingConfig(t *testing.T) { | ||
rootCmd.SetArgs([]string{"migrate"}) | ||
defer rootCmd.SetArgs([]string{}) | ||
err := rootCmd.Execute() | ||
assert.Error(t, err) | ||
assert.Regexp(t, "no such file or directory", err) | ||
} | ||
|
||
func TestConfigMigrateCmd(t *testing.T) { | ||
rootCmd.SetArgs([]string{"migrate", "-f", configPath}) | ||
defer rootCmd.SetArgs([]string{}) | ||
err := rootCmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestMain(t *testing.T) { | ||
// Run the exiting code when FLAG is set | ||
if os.Getenv("FLAG") == "0" { | ||
rootCmd.SetArgs([]string{"migrate", "-f", configPath}) | ||
main() | ||
return | ||
} | ||
|
||
// Run the test in a subprocess | ||
cmd := exec.Command(os.Args[0], "-test.run=TestMain") | ||
cmd.Env = append(os.Environ(), "FLAG=0") | ||
err := cmd.Run() | ||
|
||
// Cast the error as *exec.ExitError and compare the result | ||
_, ok := err.(*exec.ExitError) | ||
assert.Equal(t, false, ok) | ||
} | ||
|
||
func TestConfigMigrateCmdWriteOutput(t *testing.T) { | ||
tmpDir, err := os.MkdirTemp(os.TempDir(), "out") | ||
assert.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
|
||
rootCmd.SetArgs([]string{"migrate", "-f", configPath, "-o", fmt.Sprintf(tmpDir, "out.config")}) | ||
defer rootCmd.SetArgs([]string{}) | ||
err = rootCmd.Execute() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestConfigMigrateCmdBadVersion(t *testing.T) { | ||
rootCmd.SetArgs([]string{"migrate", "-f", configPath, "--from", "badversion"}) | ||
defer rootCmd.SetArgs([]string{}) | ||
err := rootCmd.Execute() | ||
assert.Error(t, err) | ||
assert.Regexp(t, "bad 'from' version", err) | ||
} |
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,60 @@ | ||
// Copyright © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 bifactory | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetPluginUnknown(t *testing.T) { | ||
ctx := context.Background() | ||
_, err := GetPlugin(ctx, "foo") | ||
assert.Error(t, err) | ||
assert.Regexp(t, "FF10110", err) | ||
} | ||
|
||
func TestGetPluginEthereum(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "ethereum") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
func TestGetPluginFabric(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "fabric") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
func TestGetPluginTezos(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "tezos") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
var root = config.RootSection("di") | ||
|
||
func TestInitConfig(t *testing.T) { | ||
conf := root.SubArray("plugins") | ||
InitConfig(conf) | ||
} |
This file was deleted.
Oops, something went wrong.
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 © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 difactory | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetPluginUnknown(t *testing.T) { | ||
ctx := context.Background() | ||
_, err := GetPlugin(ctx, "foo") | ||
assert.Error(t, err) | ||
assert.Regexp(t, "FF10122", err) | ||
} | ||
|
||
func TestGetPluginPostgres(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "postgres") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
func TestGetPluginSQLite(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "sqlite3") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
var root = config.RootSection("di") | ||
|
||
func TestInitConfig(t *testing.T) { | ||
conf := root.SubArray("plugins") | ||
InitConfig(conf) | ||
} |
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,46 @@ | ||
// Copyright © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 dxfactory | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetPluginUnknown(t *testing.T) { | ||
ctx := context.Background() | ||
_, err := GetPlugin(ctx, "foo") | ||
assert.Error(t, err) | ||
assert.Regexp(t, "FF10213", err) | ||
} | ||
|
||
func TestGetPlugin(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "ffdx") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
var root = config.RootSection("di") | ||
|
||
func TestInitConfig(t *testing.T) { | ||
conf := root.SubArray("plugins") | ||
InitConfig(conf) | ||
} |
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,59 @@ | ||
// Copyright © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 eifactory | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetPluginUnknown(t *testing.T) { | ||
ctx := context.Background() | ||
_, err := GetPlugin(ctx, "foo") | ||
assert.Error(t, err) | ||
assert.Regexp(t, "FF10172", err) | ||
} | ||
|
||
func TestGetPluginWebSockets(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "websockets") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
func TestGetPluginWebHooks(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "webhooks") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
func TestGetPluginEvents(t *testing.T) { | ||
ctx := context.Background() | ||
plugin, err := GetPlugin(ctx, "system") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, plugin) | ||
} | ||
|
||
var root = config.RootSection("di") | ||
|
||
func TestInitConfig(t *testing.T) { | ||
InitConfig(root) | ||
} |
Oops, something went wrong.