Skip to content

Commit bd4973f

Browse files
committed
Add test
1 parent 34e2bdb commit bd4973f

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Flow CLI
3+
*
4+
* Copyright Flow Foundation
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package dependencymanager
20+
21+
import (
22+
"testing"
23+
24+
"github.com/stretchr/testify/assert"
25+
26+
"github.com/onflow/flowkit/v2/config"
27+
"github.com/onflow/flowkit/v2/output"
28+
29+
"github.com/onflow/flow-cli/internal/command"
30+
"github.com/onflow/flow-cli/internal/util"
31+
)
32+
33+
func TestListDependencies(t *testing.T) {
34+
t.Run("Empty dependencies", func(t *testing.T) {
35+
logger := output.NewStdoutLogger(output.NoneLog)
36+
_, state, _ := util.TestMocks(t)
37+
38+
result, err := list([]string{}, command.GlobalFlags{}, logger, nil, state)
39+
40+
assert.NoError(t, err)
41+
listResult, ok := result.(*ListResult)
42+
assert.True(t, ok)
43+
assert.Equal(t, 0, len(listResult.Dependencies))
44+
})
45+
46+
t.Run("With dependencies", func(t *testing.T) {
47+
logger := output.NewStdoutLogger(output.NoneLog)
48+
_, state, _ := util.TestMocks(t)
49+
50+
serviceAcc, _ := state.EmulatorServiceAccount()
51+
dep := config.Dependency{
52+
Name: "TestContract",
53+
Source: config.Source{
54+
NetworkName: "emulator",
55+
Address: serviceAcc.Address,
56+
ContractName: "TestContract",
57+
},
58+
}
59+
60+
state.Dependencies().AddOrUpdate(dep)
61+
62+
result, err := list([]string{}, command.GlobalFlags{}, logger, nil, state)
63+
64+
assert.NoError(t, err)
65+
listResult, ok := result.(*ListResult)
66+
assert.True(t, ok)
67+
assert.Equal(t, 1, len(listResult.Dependencies))
68+
69+
depInfo := listResult.Dependencies[0]
70+
assert.Equal(t, "TestContract", depInfo.Name)
71+
assert.Equal(t, "emulator", depInfo.NetworkName)
72+
assert.Equal(t, serviceAcc.Address.String(), depInfo.Address)
73+
assert.Equal(t, "TestContract", depInfo.Contract)
74+
})
75+
}
76+
77+
func TestListResult_JSON(t *testing.T) {
78+
t.Run("JSON output", func(t *testing.T) {
79+
result := &ListResult{
80+
Dependencies: []DependencyInfo{
81+
{
82+
Name: "TestContract",
83+
NetworkName: "emulator",
84+
Address: "0x01cf0e2f2f715450",
85+
Contract: "TestContract",
86+
},
87+
},
88+
}
89+
90+
jsonOutput := result.JSON()
91+
assert.Equal(t, result, jsonOutput)
92+
})
93+
}

0 commit comments

Comments
 (0)