Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First import of Swagger support, lots more work to do
- Loading branch information
Showing
106 changed files
with
41,667 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package router_test | ||
|
||
import ( | ||
"github.com/awslabs/aws-sam-local/router" | ||
"github.com/awslabs/goformation/cloudformation" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func getApiResourceFromTemplate(path string) (*router.AWSServerlessApi) { | ||
templateUri := &path | ||
apiResource := &router.AWSServerlessApi{ | ||
AWSServerlessApi: &cloudformation.AWSServerlessApi{ | ||
DefinitionUri: &cloudformation.AWSServerlessApi_StringOrS3Location{ | ||
String: templateUri, | ||
}, | ||
}, | ||
} | ||
return apiResource | ||
} | ||
|
||
var _ = Describe("Api", func() { | ||
|
||
Context("Load local Swagger definitions", func() { | ||
/*apiResource := router.AWSServerlessApi{} | ||
templateUri := new(string) | ||
*templateUri = "test/templates/open-api/pet-store-simple.json" | ||
definitionUri := new(cloudformation.AWSServerlessApi_StringOrS3Location) | ||
definitionUri.String = templateUri | ||
apiResource.DefinitionUri = definitionUri*/ | ||
It("Succesfully loads the basic template", func() { | ||
apiResource := getApiResourceFromTemplate("../test/templates/open-api/pet-store-simple.json") | ||
|
||
mounts, err := apiResource.Mounts() | ||
|
||
Expect(err).Should(BeNil()) | ||
Expect(mounts).ShouldNot(BeNil()) | ||
|
||
Expect(mounts).ShouldNot(BeEmpty()) | ||
Expect(len(mounts)).Should(BeIdenticalTo(4)) | ||
}) | ||
|
||
It("Succesfully reads integration definition", func() { | ||
apiResource := getApiResourceFromTemplate("../test/templates/open-api/pet-store-simple.json") | ||
|
||
mounts, err := apiResource.Mounts() | ||
|
||
Expect(err).Should(BeNil()) | ||
Expect(mounts).ShouldNot(BeNil()) | ||
|
||
for _, mount := range mounts { | ||
if mount.Method == "get" && mount.Path == "/pets" { | ||
Expect(mount.IntegrationArn.Arn).Should(BeIdenticalTo("arn:aws:lambda:us-west-2:123456789012:function:Calc")) | ||
} | ||
} | ||
}) | ||
|
||
}) | ||
}) |
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,48 @@ | ||
package router | ||
|
||
import ( | ||
"regexp" | ||
"fmt" | ||
) | ||
|
||
type ApiGatewayIntegration struct { | ||
Uri string `json:"uri"` | ||
PassthroughBehavior string `json:"passthroughBehavior"` | ||
Type string `json:"type"` | ||
} | ||
|
||
func (i *ApiGatewayIntegration) GetFunctionArn() (*LambdaFunctionArn, error) { | ||
// arn:aws:apigateway:us-west-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:Calc/invocations | ||
firstMatch, err := getFirstMatch(`.*/functions/(.*)/invocations`, i.Uri) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &LambdaFunctionArn{ Arn: firstMatch }, nil | ||
} | ||
|
||
type LambdaFunctionArn struct { | ||
Arn string | ||
} | ||
|
||
func (a *LambdaFunctionArn) GetFunctionName() (string, error) { | ||
firstMatch, err := getFirstMatch(`.*:function:(.*)/invocations`, a.Arn) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return firstMatch, nil | ||
} | ||
|
||
func getFirstMatch(regex string, value string) (string, error) { | ||
re := regexp.MustCompile(regex) | ||
match := re.FindStringSubmatch(value) | ||
|
||
if len(match) < 2 { | ||
return "", fmt.Errorf("Could not find match in %s", value) | ||
} | ||
|
||
return match[1], nil | ||
} |
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
Oops, something went wrong.