Skip to content

Commit

Permalink
Add test for parsing connection paths (cosmos#4111)
Browse files Browse the repository at this point in the history
* Use regex to parse identifiers in a key path

* typo

* Add regex godoc comment and 2 examples

* Revert back to just TestMustParseConnectionPath

* re-add description vars from main branch

* chore: lint fix

---------

Co-authored-by: Jim Fasarakis-Hilliard <d.f.hilliard@gmail.com>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: srdtrk <59252793+srdtrk@users.noreply.github.com>
Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
5 people committed Sep 16, 2023
1 parent b93d02a commit f4e1f71
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions modules/core/24-host/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@ func TestMustParseClientStatePath(t *testing.T) {
}
}
}

func TestMustParseConnectionPath(t *testing.T) {
testCases := []struct {
name string
path string
expected string
expPass bool
}{
{"valid", "a/connection", "connection", true},
{"valid localhost", "/connection-localhost", "connection-localhost", true},
{"invalid empty path", "", "", false},
}

for _, tc := range testCases {
if tc.expPass {
require.NotPanics(t, func() {
connID := host.MustParseConnectionPath(tc.path)
require.Equal(t, connID, tc.expected)
})
} else {
require.Panics(t, func() {
host.MustParseConnectionPath(tc.path)
})
}
}
}

0 comments on commit f4e1f71

Please sign in to comment.