-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from ohsawa0515/ec2metadata
add ec2metadata testing
- Loading branch information
Showing
6 changed files
with
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
language: go | ||
sudo: false | ||
|
||
env: | ||
global: | ||
secure: "1PjOS0yhvV9gmkfu7Y6XEYPDkxejOb7Qe6m4BAFmLQe133DqsgvGf9TC3SItXuAQfzi5qJwgUiGotasX8wNFr2EQDO1Dzo+0rX2fNa/dLwgUam6foXx5HhXinGOHbbc6LyAaRx2D3eDqZaw3PssPZ94pMy9ALCCawXWc85sVwFQS0mPB8h6oBtVfN/Hdp7v1w7cVR89s1KYSA+T9FAYKGDaaRS9Mmihs3o52K9NsURsnPVZj7sI1Z2ir1xdOwFIvUIbl6nkRNs0lFEgrld+69+8p0bSGqcZJjo4EaVNb2F4HPm5z+zxwVPPJJn1WhqVgUFG9dQ5w2HZM6VcQynbxGqEQJRbXqY+wmCmL/HrWq0iof9hIF2gtTU2Z7CrNRDdTSmCsDMJP02sPD/XhqiKoeo8SM7GwGcayoDSzQUYXgcOeRUMtajyjLimM2u5CAu4+DbDfdip6OzinSkDgca65pYIub61abDRdOEGD+ayZkSrZofzeky+h0TakhlS2n1OZorDNTu32umGsB8iM9ycbB9WWONi034SaUimvLd3xl5qqUhEBTzhnFuTHnwN84ilHdw25V3Jm5IuU/v71hVecluRqDk5Fts+54utyyvas6M5NjsCW2mqpAkB1ScdnL1S78KITgNHF8QjDrVOrM+9O7x6dvr8qgtMZprm9Fo+NdEI=" | ||
|
||
- secure: GGwVbq8Fo/ygExdjMToQDYYaXG2r/QPWzvA/r4DDzqLMBPXht1DWSlfoyU9841M86p2W0Z2er2eqGlRwj0co9SubiQki166kImveP2hPPdpYvfrUcDJjk1NhjZDROLvC2pz1OE9w9niRN8s9X5pmJuF/ArkI1kFKUR+EMNQkITGumOw7KyZHia5d3BROYwAdtj6gz3EdHbiODe6nfZTC7bq3ZyBz/3xNhivBtZI0t54XqeElZcP4P00RMVux0M7pCxAwdWb8wuoRGitPgXOu416T4RyUYoU6Iy2EVTrzKj0xfjQTxFeAG5nAeOPC7tgQhmQ9rKiMbe9DD9v9PZjrNebVUOohv/1gCBOhisfgCIEmyAgjcLVMXLndE2iJdmL2sI8fiJKQFZ51YiCc4Jj7vHFWOsYglJO7YQ+B4Tw0xVMDEG2f97o9JxFgleRkdfEkHtvMtFSDC1b/86PT2QiasXOgL5I3gsaKtMqDF70/ogbpv3ZEK670thWsQ85fKnkR9Yq+Lia1PIVF6Zm6zCNWE2ZjtmSQSuLRp/5kTB5oEXU4U5B55oMIMbhSw7uX06hnDUSotpDdD4z3EHdMjCdx/TMW08lx5Mg5Lb29hr8tn2vwynqL44X/swZrubik/zVeSUCH4CeFMC2tyA37mP9SuEwnZu5ock3Ve0sn3wZY4+U= | ||
os: | ||
- linux | ||
- osx | ||
|
||
go: | ||
- 1.11 | ||
|
||
- 1.15 | ||
script: | ||
- go test -v | ||
- $HOME/gopath/bin/goveralls -repotoken $COVERALLS_TOKEN -service=travis-ci | ||
|
||
- "$HOME/gopath/bin/goveralls -repotoken $COVERALLS_TOKEN -service=travis-ci" | ||
before_install: | ||
- go get github.com/axw/gocov/gocov | ||
- go get github.com/mattn/goveralls | ||
- go get golang.org/x/tools/cmd/cover | ||
|
||
notifications: | ||
email: false | ||
slack: | ||
secure: "C5rLRy/goL4PB2gd7zmCy88EXZ4PKLTDD/vO7aMtm8jbBGMjnVFTj9EtBpILr01sa4VssD+UlE5UZhujVWSw7zed7QTZbC2AL7WoKRpetgRb8dTtGalDf0x5a1IWIM7LZHPGcj76Uog6EBysNDs/cMhAHKLUZPaRSH5SopCkScf8z/44AYoNM4/5qp9P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UN64GfnqNh2vzosddhvJ1K/yZO8g/U0E0+AM5ByAk/IiWs0U1sHbh3r6n8J/TBn/EaL9uYDirBp0hPQ2nLUebPC85SxMxDYVT7hdhPswvGeFSugvT5KdXjAa76I= |
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,8 @@ | ||
package main | ||
|
||
import "github.com/aws/aws-sdk-go/aws/ec2metadata" | ||
|
||
// GetInstanceID returns EC2 instance ID getting by metadata. | ||
func GetInstanceID(svc *ec2metadata.EC2Metadata) (string, error) { | ||
return svc.GetMetadata("instance-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/ec2metadata" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
var mockSession = session.Must(session.NewSession(&aws.Config{ | ||
Region: aws.String("mock-region"), | ||
})) | ||
|
||
func TestGetInstanceID(t *testing.T) { | ||
expectedInstanceID := "i-1234567890ab" | ||
metadataInstanceID := "i-1234567890ab" | ||
|
||
mux := http.NewServeMux() | ||
mux.HandleFunc("/latest/meta-data/instance-id", func(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprint(w, metadataInstanceID) | ||
}) | ||
server := httptest.NewServer(mux) | ||
defer server.Close() | ||
|
||
mockEC2MetaDataSvc := ec2metadata.New(mockSession, &aws.Config{ | ||
Endpoint: aws.String(server.URL), | ||
}) | ||
|
||
instanceID, err := GetInstanceID(mockEC2MetaDataSvc) | ||
if err != nil { | ||
t.Errorf("expected no error, but got %v.", err) | ||
} | ||
if instanceID != expectedInstanceID { | ||
t.Errorf("expected value of tag: %s, but got tag value: %v.", expectedInstanceID, instanceID) | ||
} | ||
} |
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