Skip to content

Commit

Permalink
Add comments to all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
msdundar committed Jun 13, 2021
1 parent aea2e8f commit c2af6ef
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ on CI, depending on your needs.
go get github.com/msdundar/kanarya
```

> `kanarya` uses Go Modules to manage dependencies.
> `kanarya` uses Go Modules to manage dependencies, and supports Go versions
> `>=1.14.x`.
## Usage

Expand Down
4 changes: 4 additions & 0 deletions lambda_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/aws/aws-sdk-go/service/lambda"
)

// A HealthCheckResponse is used to reflect structure of a health check call
// targetting a lambda function. StatusCode stands for the HTTP status code
// returned by AWS. On the other hand, there can be an additional status code
// returned by applications in the response body, but this is optional.
type HealthCheckResponse struct {
StatusCode int64 `json:"statusCode"`
Body string `json:"body"`
Expand Down
4 changes: 4 additions & 0 deletions lambda_update_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (
"github.com/aws/aws-sdk-go/service/lambda"
)

// LambdaUpdateFunctionResponse is used to reflect the response returned from
// UpdateFunctionCode function.
type LambdaUpdateFunctionResponse struct {
FunctionArn string
FunctionName string
LastUpdateStatus string
}

// UpdateFunctionCode updates the function code of a lambda located on $LATEST.
// In later stages, new versions can be created from the updated $LATEST.
func UpdateFunctionCode(
client *lambda.Lambda,
lambdaPackage LambdaPackage,
Expand Down
2 changes: 2 additions & 0 deletions lambda_update_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
)

// TestUpdateFunctionCode updates the function code of a lambda located on
// $LATEST, and tests the output.
func TestUpdateFunctionCode(t *testing.T) {
lambdaClient := LambdaClient(os.Getenv("AWS_REGION"))

Expand Down
7 changes: 7 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/joho/godotenv"
)

// testLambdaPackage is a simple LambdaPackage instance that is used
// across the test suite.
var testLambdaPackage = LambdaPackage{
Location: "fixtures/index.zip",
Function: LambdaFunction{
Expand All @@ -24,6 +26,9 @@ var testLambdaPackage = LambdaPackage{
},
}

// setup runs as the first step when "go test" run. It configures the test suite
// by loading environment variables defined for the test environment, and for
// tools used for testing.
func setup() {
log.SetOutput(ioutil.Discard)

Expand All @@ -35,6 +40,8 @@ func setup() {
}
}

// TestMain is a Go 1.14 feature. See https://golang.org/pkg/testing/#hdr-Main
// for more details.
func TestMain(m *testing.M) {
setup()
os.Exit(m.Run())
Expand Down
5 changes: 5 additions & 0 deletions s3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
)

// S3Client initializes a new S3 client that can be used in S3 actions.
// Endpoint will be set to a localstack endpoint when running tests,
// otherwise it will use the default AWS location. Localstack requires
// S3ForcePathStyle is set to true, however, on production it will be set
// to false.
func S3Client(region string) *s3.S3 {
path_style := false

Expand Down
5 changes: 5 additions & 0 deletions s3_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
)

// An S3UploadResponse is used to represent structure of a response returned
// from an UploadToS3 call. It supports S3 buckets with versioning enabled or
// disabled.
type S3UploadResponse struct {
ETag string
}

// UploadToS3 uploads a given lambda package to an S3 bucket. Later, the object
// in the bucket can be used for deploying the lambda function.
func UploadToS3(client *s3.S3, lambdaPackage LambdaPackage) (S3UploadResponse, error) {
resp := S3UploadResponse{}

Expand Down
4 changes: 3 additions & 1 deletion test.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Terraform configuration to use together with Localstack
// Resources created in this section will only be used to run the test suite
// Resources created in this section will only be used to run the test suite.
// After starting the localstack, you can apply this Terraform config to create
// a fully functional testing environment. See README.md for more details.
provider "aws" {
access_key = "mock_access_key"
region = "us-east-1"
Expand Down

0 comments on commit c2af6ef

Please sign in to comment.