Skip to content

Commit 37efd0f

Browse files
authored
Merge pull request #1582 from hyperledger/add_coverage
Add more tests for missing coverage
2 parents 35db032 + 97e0169 commit 37efd0f

File tree

9 files changed

+462
-52
lines changed

9 files changed

+462
-52
lines changed

ffconfig/main_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright © 2022 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
"os"
22+
"os/exec"
23+
"testing"
24+
25+
"github.com/stretchr/testify/assert"
26+
)
27+
28+
var configPath string = "../test/data/config/firefly.core.yaml"
29+
30+
func TestMainFail(t *testing.T) {
31+
// Run the crashing code when FLAG is set
32+
if os.Getenv("FLAG") == "1" {
33+
main()
34+
return
35+
}
36+
// Run the test in a subprocess
37+
cmd := exec.Command(os.Args[0], "-test.run=TestMainFail")
38+
cmd.Env = append(os.Environ(), "FLAG=1")
39+
err := cmd.Run()
40+
41+
// Cast the error as *exec.ExitError and compare the result
42+
e, ok := err.(*exec.ExitError)
43+
expectedErrorString := "exit status 1"
44+
assert.Equal(t, true, ok)
45+
assert.Equal(t, expectedErrorString, e.Error())
46+
}
47+
48+
func TestConfigMigrateRootCmdErrorNoArgs(t *testing.T) {
49+
rootCmd.SetArgs([]string{})
50+
defer rootCmd.SetArgs([]string{})
51+
err := rootCmd.Execute()
52+
assert.Error(t, err)
53+
assert.Regexp(t, "a command is required", err)
54+
}
55+
56+
func TestConfigMigrateCmdMissingConfig(t *testing.T) {
57+
rootCmd.SetArgs([]string{"migrate"})
58+
defer rootCmd.SetArgs([]string{})
59+
err := rootCmd.Execute()
60+
assert.Error(t, err)
61+
assert.Regexp(t, "no such file or directory", err)
62+
}
63+
64+
func TestConfigMigrateCmd(t *testing.T) {
65+
rootCmd.SetArgs([]string{"migrate", "-f", configPath})
66+
defer rootCmd.SetArgs([]string{})
67+
err := rootCmd.Execute()
68+
assert.NoError(t, err)
69+
}
70+
71+
func TestMain(t *testing.T) {
72+
// Run the exiting code when FLAG is set
73+
if os.Getenv("FLAG") == "0" {
74+
rootCmd.SetArgs([]string{"migrate", "-f", configPath})
75+
main()
76+
return
77+
}
78+
79+
// Run the test in a subprocess
80+
cmd := exec.Command(os.Args[0], "-test.run=TestMain")
81+
cmd.Env = append(os.Environ(), "FLAG=0")
82+
err := cmd.Run()
83+
84+
// Cast the error as *exec.ExitError and compare the result
85+
_, ok := err.(*exec.ExitError)
86+
assert.Equal(t, false, ok)
87+
}
88+
89+
func TestConfigMigrateCmdWriteOutput(t *testing.T) {
90+
tmpDir, err := os.MkdirTemp(os.TempDir(), "out")
91+
assert.NoError(t, err)
92+
defer os.RemoveAll(tmpDir)
93+
94+
rootCmd.SetArgs([]string{"migrate", "-f", configPath, "-o", fmt.Sprintf(tmpDir, "out.config")})
95+
defer rootCmd.SetArgs([]string{})
96+
err = rootCmd.Execute()
97+
assert.NoError(t, err)
98+
}
99+
100+
func TestConfigMigrateCmdBadVersion(t *testing.T) {
101+
rootCmd.SetArgs([]string{"migrate", "-f", configPath, "--from", "badversion"})
102+
defer rootCmd.SetArgs([]string{})
103+
err := rootCmd.Execute()
104+
assert.Error(t, err)
105+
assert.Regexp(t, "bad 'from' version", err)
106+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright © 2023 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package bifactory
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/hyperledger/firefly-common/pkg/config"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestGetPluginUnknown(t *testing.T) {
28+
ctx := context.Background()
29+
_, err := GetPlugin(ctx, "foo")
30+
assert.Error(t, err)
31+
assert.Regexp(t, "FF10110", err)
32+
}
33+
34+
func TestGetPluginEthereum(t *testing.T) {
35+
ctx := context.Background()
36+
plugin, err := GetPlugin(ctx, "ethereum")
37+
assert.NoError(t, err)
38+
assert.NotNil(t, plugin)
39+
}
40+
41+
func TestGetPluginFabric(t *testing.T) {
42+
ctx := context.Background()
43+
plugin, err := GetPlugin(ctx, "fabric")
44+
assert.NoError(t, err)
45+
assert.NotNil(t, plugin)
46+
}
47+
48+
func TestGetPluginTezos(t *testing.T) {
49+
ctx := context.Background()
50+
plugin, err := GetPlugin(ctx, "tezos")
51+
assert.NoError(t, err)
52+
assert.NotNil(t, plugin)
53+
}
54+
55+
var root = config.RootSection("di")
56+
57+
func TestInitConfig(t *testing.T) {
58+
conf := root.SubArray("plugins")
59+
InitConfig(conf)
60+
}

internal/coremsgs/es/es_struct_descriptions.go

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright © 2023 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package difactory
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/hyperledger/firefly-common/pkg/config"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestGetPluginUnknown(t *testing.T) {
28+
ctx := context.Background()
29+
_, err := GetPlugin(ctx, "foo")
30+
assert.Error(t, err)
31+
assert.Regexp(t, "FF10122", err)
32+
}
33+
34+
func TestGetPluginPostgres(t *testing.T) {
35+
ctx := context.Background()
36+
plugin, err := GetPlugin(ctx, "postgres")
37+
assert.NoError(t, err)
38+
assert.NotNil(t, plugin)
39+
}
40+
41+
func TestGetPluginSQLite(t *testing.T) {
42+
ctx := context.Background()
43+
plugin, err := GetPlugin(ctx, "sqlite3")
44+
assert.NoError(t, err)
45+
assert.NotNil(t, plugin)
46+
}
47+
48+
var root = config.RootSection("di")
49+
50+
func TestInitConfig(t *testing.T) {
51+
conf := root.SubArray("plugins")
52+
InitConfig(conf)
53+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright © 2023 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package dxfactory
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/hyperledger/firefly-common/pkg/config"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestGetPluginUnknown(t *testing.T) {
28+
ctx := context.Background()
29+
_, err := GetPlugin(ctx, "foo")
30+
assert.Error(t, err)
31+
assert.Regexp(t, "FF10213", err)
32+
}
33+
34+
func TestGetPlugin(t *testing.T) {
35+
ctx := context.Background()
36+
plugin, err := GetPlugin(ctx, "ffdx")
37+
assert.NoError(t, err)
38+
assert.NotNil(t, plugin)
39+
}
40+
41+
var root = config.RootSection("di")
42+
43+
func TestInitConfig(t *testing.T) {
44+
conf := root.SubArray("plugins")
45+
InitConfig(conf)
46+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright © 2023 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package eifactory
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/hyperledger/firefly-common/pkg/config"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestGetPluginUnknown(t *testing.T) {
28+
ctx := context.Background()
29+
_, err := GetPlugin(ctx, "foo")
30+
assert.Error(t, err)
31+
assert.Regexp(t, "FF10172", err)
32+
}
33+
34+
func TestGetPluginWebSockets(t *testing.T) {
35+
ctx := context.Background()
36+
plugin, err := GetPlugin(ctx, "websockets")
37+
assert.NoError(t, err)
38+
assert.NotNil(t, plugin)
39+
}
40+
41+
func TestGetPluginWebHooks(t *testing.T) {
42+
ctx := context.Background()
43+
plugin, err := GetPlugin(ctx, "webhooks")
44+
assert.NoError(t, err)
45+
assert.NotNil(t, plugin)
46+
}
47+
48+
func TestGetPluginEvents(t *testing.T) {
49+
ctx := context.Background()
50+
plugin, err := GetPlugin(ctx, "system")
51+
assert.NoError(t, err)
52+
assert.NotNil(t, plugin)
53+
}
54+
55+
var root = config.RootSection("di")
56+
57+
func TestInitConfig(t *testing.T) {
58+
InitConfig(root)
59+
}

0 commit comments

Comments
 (0)