-
Notifications
You must be signed in to change notification settings - Fork 53
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 #25 from st3v/master
Allow for customizable instance IDs ... and a few fixes
- Loading branch information
Showing
7 changed files
with
129 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package fargo_test | ||
|
||
// MIT Licensed (see README.md) | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hudl/fargo" | ||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestInstanceID(t *testing.T) { | ||
i := fargo.Instance{ | ||
HostName: "i-6543", | ||
Port: 9090, | ||
App: "TESTAPP", | ||
IPAddr: "127.0.0.10", | ||
VipAddress: "127.0.0.10", | ||
SecureVipAddress: "127.0.0.10", | ||
Status: fargo.UP, | ||
} | ||
|
||
Convey("Given an instance with DataCenterInfo.Name set to Amazon", t, func() { | ||
i.DataCenterInfo = fargo.DataCenterInfo{Name: fargo.Amazon} | ||
|
||
Convey("When UniqueID function has NOT been set", func() { | ||
i.UniqueID = nil | ||
|
||
Convey("And InstanceID has been set in AmazonMetadata", func() { | ||
i.DataCenterInfo.Metadata.InstanceID = "EXPECTED-ID" | ||
|
||
Convey("Id() should return the provided InstanceID", func() { | ||
So(i.Id(), ShouldEqual, "EXPECTED-ID") | ||
}) | ||
}) | ||
|
||
Convey("And InstanceID has NOT been set in AmazonMetadata", func() { | ||
i.DataCenterInfo.Metadata.InstanceID = "" | ||
|
||
Convey("Id() should return an empty string", func() { | ||
So(i.Id(), ShouldEqual, "") | ||
}) | ||
}) | ||
}) | ||
|
||
Convey("When UniqueID function has been set", func() { | ||
i.UniqueID = func(i fargo.Instance) string { | ||
return fmt.Sprintf("%s:%d", i.App, 123) | ||
} | ||
|
||
Convey("And InstanceID has been set in AmazonMetadata", func() { | ||
i.DataCenterInfo.Metadata.InstanceID = "UNEXPECTED" | ||
|
||
Convey("Id() should return the ID that is provided by UniqueID", func() { | ||
So(i.Id(), ShouldEqual, "TESTAPP:123") | ||
}) | ||
}) | ||
|
||
Convey("And InstanceID has not been set in AmazonMetadata", func() { | ||
i.DataCenterInfo.Metadata.InstanceID = "" | ||
|
||
Convey("Id() should return the ID that is provided by UniqueID", func() { | ||
So(i.Id(), ShouldEqual, "TESTAPP:123") | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
Convey("Given an instance with DataCenterInfo.Name set to MyOwn", t, func() { | ||
i.DataCenterInfo = fargo.DataCenterInfo{Name: fargo.MyOwn} | ||
|
||
Convey("When UniqueID function has NOT been set", func() { | ||
i.UniqueID = nil | ||
|
||
Convey("Id() should return the host name", func() { | ||
So(i.Id(), ShouldEqual, "i-6543") | ||
}) | ||
}) | ||
|
||
Convey("When UniqueID function has been set", func() { | ||
i.Metadata.Raw = []byte(`{"instanceId": "unique-id"}`) | ||
i.UniqueID = func(i fargo.Instance) string { | ||
if id, err := i.Metadata.GetString("instanceId"); err == nil { | ||
return fmt.Sprintf("%s:%s", i.HostName, id) | ||
} | ||
return i.HostName | ||
} | ||
|
||
Convey("Id() should return the ID that is provided by UniqueID", func() { | ||
So(i.Id(), ShouldEqual, "i-6543:unique-id") | ||
}) | ||
}) | ||
}) | ||
} |
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