From c2af6ef18362e0e50b39eb2ca60e345e7d942657 Mon Sep 17 00:00:00 2001 From: "M. Serhat Dundar" Date: Mon, 14 Jun 2021 01:30:36 +0200 Subject: [PATCH] Add comments to all functions --- README.md | 3 ++- lambda_health_check.go | 4 ++++ lambda_update_function.go | 4 ++++ lambda_update_function_test.go | 2 ++ main_test.go | 7 +++++++ s3_client.go | 5 +++++ s3_uploader.go | 5 +++++ test.tf | 4 +++- 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 85c2801..b3669a8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lambda_health_check.go b/lambda_health_check.go index f2dc920..d98fea2 100644 --- a/lambda_health_check.go +++ b/lambda_health_check.go @@ -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"` diff --git a/lambda_update_function.go b/lambda_update_function.go index 4622d58..4cee07b 100644 --- a/lambda_update_function.go +++ b/lambda_update_function.go @@ -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, diff --git a/lambda_update_function_test.go b/lambda_update_function_test.go index 37d8475..726365f 100644 --- a/lambda_update_function_test.go +++ b/lambda_update_function_test.go @@ -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")) diff --git a/main_test.go b/main_test.go index f7432c8..e062fe7 100644 --- a/main_test.go +++ b/main_test.go @@ -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{ @@ -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) @@ -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()) diff --git a/s3_client.go b/s3_client.go index 5c9173d..42601fa 100644 --- a/s3_client.go +++ b/s3_client.go @@ -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 diff --git a/s3_uploader.go b/s3_uploader.go index 4c5fcd0..53463bb 100644 --- a/s3_uploader.go +++ b/s3_uploader.go @@ -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{} diff --git a/test.tf b/test.tf index c018a4e..75a5ff5 100644 --- a/test.tf +++ b/test.tf @@ -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"