-
Notifications
You must be signed in to change notification settings - Fork 4
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
ca316fa
commit 483cc61
Showing
4 changed files
with
86 additions
and
15 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
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,71 @@ | ||
package chains | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/ignite/cli/v28/ignite/pkg/chainregistry" | ||
) | ||
|
||
func TestCleanGRPCEntries(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
entries []chainregistry.APIProvider | ||
expected []chainregistry.APIProvider | ||
}{ | ||
{ | ||
name: "Clean entries with http:// and https://", | ||
entries: []chainregistry.APIProvider{ | ||
{Address: "http://example1.com:1234/"}, | ||
{Address: "https://example2.com:5678"}, | ||
{Address: "http://example3.com:9012"}, | ||
}, | ||
expected: []chainregistry.APIProvider{ | ||
{Address: "example1.com:1234"}, | ||
{Address: "example2.com:5678"}, | ||
{Address: "example3.com:9012"}, | ||
}, | ||
}, | ||
{ | ||
name: "Remove trailing slashes", | ||
entries: []chainregistry.APIProvider{ | ||
{Address: "http://example.com:1234/"}, | ||
{Address: "https://example.com:5678/"}, | ||
}, | ||
expected: []chainregistry.APIProvider{ | ||
{Address: "example.com:1234"}, | ||
{Address: "example.com:5678"}, | ||
}, | ||
}, | ||
{ | ||
name: "Filter entries without ports", | ||
entries: []chainregistry.APIProvider{ | ||
{Address: "example.com"}, | ||
{Address: "example.com:1234"}, | ||
}, | ||
expected: []chainregistry.APIProvider{ | ||
{Address: "example.com:1234"}, | ||
}, | ||
}, | ||
{ | ||
name: "Empty input", | ||
entries: []chainregistry.APIProvider{}, | ||
expected: []chainregistry.APIProvider{}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Copy the entries so that modifications in one test case | ||
// don't affect others | ||
input := make([]chainregistry.APIProvider, len(tt.entries)) | ||
copy(input, tt.entries) | ||
|
||
result := cleanGRPCEntries(input) | ||
|
||
if !reflect.DeepEqual(result, tt.expected) { | ||
t.Errorf("cleanGRPCEntries() = %v, want %v", result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
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