• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fogfish / scud / 16102336813

06 Jul 2025 07:14PM UTC coverage: 86.167% (+0.6%) from 85.599%
16102336813

Pull #37

github

fogfish
fix (minor) for L3 Lambda APIs
Pull Request #37: fix (minor) for L3 Lambda APIs

2 of 4 new or added lines in 2 files covered. (50.0%)

517 of 600 relevant lines covered (86.17%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.04
/handler.go
1
//
2
// Copyright (C) 2020 - 2024 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/fogfish/scud
7
//
8

9
package scud
10

11
import (
12
        "path/filepath"
13
        "strings"
14

15
        "github.com/aws/aws-cdk-go/awscdk/v2"
16
        "github.com/aws/aws-cdk-go/awscdk/v2/awslambda"
17
        "github.com/aws/aws-cdk-go/awscdk/v2/awslogs"
18
        "github.com/aws/constructs-go/constructs/v10"
19
        "github.com/aws/jsii-runtime-go"
20
)
21

22
// FunctionGoProps is properties of the function
23
type FunctionGoProps struct {
24
        *awslambda.FunctionProps
25

26
        // Canonical name of Golang module that containing the function
27
        //        SourceCodeModule: "github.com/fogfish/scud",
28
        SourceCodeModule string
29

30
        // Path to lambda function relative to the module
31
        //        SourceCodeLambda:  "test/lambda/go"
32
        SourceCodeLambda string
33

34
        // The version of software asset passed as linker flag
35
        //        -ldflags '-X main.version=...'
36
        SourceCodeVersion string
37

38
        // Variables and its values passed as linker flags
39
        //        -ldflags '-X key1=val1 -X key2=val2 ...'
40
        GoVar map[string]string
41

42
        // Go environment, default includes
43
        //        GOOS=linux
44
        //        GOARCH=arm64
45
        //        CGO_ENABLED=0
46
        GoEnv map[string]string
47
}
48

NEW
49
func (*FunctionGoProps) HKT1(awslambda.Function) {}
×
50

51
func (props *FunctionGoProps) UniqueID() string {
1✔
52
        return funcName(props.SourceCodeModule, props.SourceCodeLambda)
1✔
53
}
1✔
54

55
// NewFunctionGo creates Golang Lambda Function from "inline" code
56
func NewFunctionGo(scope constructs.Construct, id *string, spec *FunctionGoProps) awslambda.Function {
1✔
57
        var props awslambda.FunctionProps
1✔
58
        if spec.FunctionProps != nil {
2✔
59
                props = *spec.FunctionProps
1✔
60
        }
1✔
61

62
        if props.Timeout == nil {
2✔
63
                props.Timeout = awscdk.Duration_Minutes(jsii.Number(1))
1✔
64
        }
1✔
65

66
        if props.LogRetention == "" {
2✔
67
                props.LogRetention = awslogs.RetentionDays_FIVE_DAYS
1✔
68
        }
1✔
69

70
        if props.FunctionName == nil {
2✔
71
                props.FunctionName = jsii.Sprintf("%s-%s", *awscdk.Aws_STACK_NAME(), spec.UniqueID())
1✔
72
        }
1✔
73

74
        // arm64 is default deployment
75
        props.Architecture = awslambda.Architecture_ARM_64()
1✔
76
        if spec.GoEnv != nil {
2✔
77
                switch spec.GoEnv["GOARCH"] {
1✔
78
                case "amd64":
1✔
79
                        props.Architecture = awslambda.Architecture_X86_64()
1✔
80
                case "arm64":
1✔
81
                        props.Architecture = awslambda.Architecture_ARM_64()
1✔
82
                }
83
        }
84

85
        gocc := NewGoCompiler(
1✔
86
                spec.SourceCodeModule,
1✔
87
                spec.SourceCodeLambda,
1✔
88
                spec.SourceCodeVersion,
1✔
89
                spec.GoVar,
1✔
90
                spec.GoEnv,
1✔
91
        )
1✔
92
        props.Code = AssetCodeGo(gocc)
1✔
93
        props.Handler = jsii.String(goBinary)
1✔
94
        props.Runtime = awslambda.Runtime_PROVIDED_AL2()
1✔
95

1✔
96
        return awslambda.NewFunction(scope, id, &props)
1✔
97
}
98

99
func funcName(scModule, scLambda string) string {
1✔
100
        return shorten(filepath.Join(scModule, scLambda))
1✔
101
}
1✔
102

103
func shorten(path string) string {
1✔
104
        seq := strings.Split(path, string(filepath.Separator))
1✔
105
        if len(seq) == 1 {
1✔
106
                return path
×
107
        }
×
108

109
        for i := 0; i < len(seq)-1; i++ {
2✔
110
                seq[i] = shortenSegment(seq[i])
1✔
111
        }
1✔
112
        return strings.Join(seq, "")
1✔
113
}
114

115
// shortenSegment heuristically shortens a path segment
116
func shortenSegment(segment string) string {
1✔
117
        length := len(segment)
1✔
118
        switch {
1✔
119
        case length <= 3:
×
120
                return segment // Keep short names unchanged
×
121
        case length <= 6:
1✔
122
                return removeVowels(segment) // Remove vowels from medium-length names
1✔
123
        default:
1✔
124
                short := removeVowels(segment)
1✔
125
                if len(short) > 4 {
2✔
126
                        return short[:4]
1✔
127
                }
1✔
128
                return short
×
129
        }
130
}
131

132
func removeVowels(segment string) string {
1✔
133
        vowels := "aeiouAEIOU"
1✔
134
        keep := []rune{}
1✔
135
        for i, r := range segment {
2✔
136
                if i == 0 || !strings.ContainsRune(vowels, r) {
2✔
137
                        keep = append(keep, r)
1✔
138
                }
1✔
139
        }
140
        if len(keep) < 2 { // Ensure at least 2 characters remain
1✔
141
                return segment
×
142
        }
×
143
        return string(keep)
1✔
144
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc