Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
chore: rename to storagemb; tests + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thiskevinwang committed May 14, 2022
1 parent bd06d86 commit 4af8b27
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
18 changes: 15 additions & 3 deletions builtin/aws/lambda/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ func (p *Platform) ConfigSet(config interface{}) error {
}
}

// validate storage - value between 512 and 10240
if c.StorageMB != 0 {
if err := utils.Error(validation.ValidateStruct(c,
validation.Field(&c.StorageMB,
validation.Min(512).Error("Storage must a value between 512 and 10240"),
validation.Max(10240).Error("Storage must a value between 512 and 10240"),
),
)); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -281,7 +293,7 @@ func (p *Platform) Deploy(
architecture = DockerArchitectureMapper(img.Architecture, log)
}

storage := int64(p.config.Storage)
storage := int64(p.config.StorageMB)
if storage == 0 {
storage = DefaultStorageSize
}
Expand Down Expand Up @@ -875,7 +887,7 @@ deploy {
)

doc.SetField(
"storage",
"storagemb",
"The storage size (in MB) of the Lambda function's `/tmp` directory. Must be a value between 512 and 10240.",
docs.Default("512"),
)
Expand Down Expand Up @@ -910,7 +922,7 @@ type Config struct {
// The storage size (in MB) of the Lambda function's `/tmp` directory.
// Must be a value between 512 and 10240.
// Defaults to 512 MB.
Storage int `hcl:"storage,optional"`
StorageMB int `hcl:"storagemb,optional"`
}

var (
Expand Down
17 changes: 17 additions & 0 deletions builtin/aws/lambda/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,21 @@ func TestPlatformConfig(t *testing.T) {
require.EqualError(t, p.ConfigSet(cfg), "rpc error: code = InvalidArgument desc = Timeout: Timeout must not be negative.")
}
})

t.Run("disallows invalid storagemb", func(t *testing.T) {
var p Platform
{
cfg := &Config{
StorageMB: 100,
}
require.EqualError(t, p.ConfigSet(cfg), "rpc error: code = InvalidArgument desc = StorageMB: Storage must a value between 512 and 10240.")
}

{
cfg := &Config{
StorageMB: 20000,
}
require.EqualError(t, p.ConfigSet(cfg), "rpc error: code = InvalidArgument desc = StorageMB: Storage must a value between 512 and 10240.")
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The amount of memory, in megabytes, to assign the function.
- **Optional**
- Default: 265

#### storage
#### storagemb

The storage size (in MB) of the Lambda function's `/tmp` directory. Must be a value between 512 and 10240.

Expand Down

0 comments on commit 4af8b27

Please sign in to comment.