-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Showing
12 changed files
with
255 additions
and
55 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,111 @@ | ||
package grpc | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestConfig_GetServiceName(t *testing.T) { | ||
tests := []struct { | ||
TestName string | ||
ServiceName string | ||
Expected string | ||
}{ | ||
{ | ||
TestName: "simple no absolute path", | ||
ServiceName: "hello", | ||
Expected: "hello", | ||
}, | ||
{ | ||
TestName: "escape no absolute path", | ||
ServiceName: "hello/world!", | ||
Expected: "hello%2Fworld%21", | ||
}, | ||
{ | ||
TestName: "absolute path", | ||
ServiceName: "/my/sample/path/a|b", | ||
Expected: "my/sample/path", | ||
}, | ||
{ | ||
TestName: "escape absolute path", | ||
ServiceName: "/hello /world!/a|b", | ||
Expected: "hello%20/world%21", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.TestName, func(t *testing.T) { | ||
config := Config{ServiceName: test.ServiceName} | ||
assert.Equal(t, test.Expected, config.getServiceName()) | ||
}) | ||
} | ||
} | ||
|
||
func TestConfig_GetTunStreamName(t *testing.T) { | ||
tests := []struct { | ||
TestName string | ||
ServiceName string | ||
Expected string | ||
}{ | ||
{ | ||
TestName: "no absolute path", | ||
ServiceName: "hello", | ||
Expected: "Tun", | ||
}, | ||
{ | ||
TestName: "absolute path server", | ||
ServiceName: "/my/sample/path/tun_service|multi_service", | ||
Expected: "tun_service", | ||
}, | ||
{ | ||
TestName: "absolute path client", | ||
ServiceName: "/my/sample/path/tun_service", | ||
Expected: "tun_service", | ||
}, | ||
{ | ||
TestName: "escape absolute path client", | ||
ServiceName: "/m y/sa !mple/pa\\th/tun\\_serv!ice", | ||
Expected: "tun%5C_serv%21ice", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.TestName, func(t *testing.T) { | ||
config := Config{ServiceName: test.ServiceName} | ||
assert.Equal(t, test.Expected, config.getTunStreamName()) | ||
}) | ||
} | ||
} | ||
|
||
func TestConfig_GetTunMultiStreamName(t *testing.T) { | ||
tests := []struct { | ||
TestName string | ||
ServiceName string | ||
Expected string | ||
}{ | ||
{ | ||
TestName: "no absolute path", | ||
ServiceName: "hello", | ||
Expected: "TunMulti", | ||
}, | ||
{ | ||
TestName: "absolute path server", | ||
ServiceName: "/my/sample/path/tun_service|multi_service", | ||
Expected: "multi_service", | ||
}, | ||
{ | ||
TestName: "absolute path client", | ||
ServiceName: "/my/sample/path/multi_service", | ||
Expected: "multi_service", | ||
}, | ||
{ | ||
TestName: "escape absolute path client", | ||
ServiceName: "/m y/sa !mple/pa\\th/mu%lti\\_serv!ice", | ||
Expected: "mu%25lti%5C_serv%21ice", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.TestName, func(t *testing.T) { | ||
config := Config{ServiceName: test.ServiceName} | ||
assert.Equal(t, test.Expected, config.getTunMultiStreamName()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.