-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from allegro/destringify
Create alias types for Id
- Loading branch information
Showing
18 changed files
with
119 additions
and
70 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
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
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
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,24 @@ | ||
package tasks | ||
|
||
import "strings" | ||
|
||
// Marathon Task Id | ||
// Usually in the form of AppId.uuid with '/' replaced with '_' | ||
type Id string | ||
|
||
func (id Id) String() string { | ||
return string(id) | ||
} | ||
|
||
// Marathon Application Id (aka PathId) | ||
// Usually in the form of /rootGroup/subGroup/subSubGroup/name | ||
// allowed characters: lowercase letters, digits, hyphens, slash | ||
type AppId string | ||
|
||
func (id AppId) String() string { | ||
return string(id) | ||
} | ||
|
||
func (id AppId) ConsulServiceName() string { | ||
return strings.Replace(strings.Trim(id.String(), "/"), "/", ".", -1) | ||
} |
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,28 @@ | ||
package tasks | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestId_String(t *testing.T) { | ||
t.Parallel() | ||
assert.Equal(t, "id", Id("id").String()) | ||
} | ||
|
||
func TestAppId_String(t *testing.T) { | ||
t.Parallel() | ||
assert.Equal(t, "appId", AppId("appId").String()) | ||
} | ||
|
||
func TestAppId_ConsulServiceName(t *testing.T) { | ||
t.Parallel() | ||
// given | ||
id := AppId("/rootGroup/subGroup/subSubGroup/name") | ||
|
||
// when | ||
serviceName := id.ConsulServiceName() | ||
|
||
// then | ||
assert.Equal(t, "rootGroup.subGroup.subSubGroup.name", serviceName) | ||
} |
Oops, something went wrong.