MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / TestSizes

Function TestSizes

cmd/build-lambda-zip/main_test.go:19–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestSizes(t *testing.T) {
20 if testing.Short() {
21 t.Skip()
22 return
23 }
24 t.Log("test how different arguments affect binary and archive sizes")
25 cases := []struct {
26 file string
27 args []string
28 }{
29 {"testdata/apigw.go", nil},
30 {"testdata/noop.go", nil},
31 {"testdata/noop.go", []string{"-tags", "lambda.norpc"}},
32 {"testdata/noop.go", []string{"-ldflags=-s -w"}},
33 {"testdata/noop.go", []string{"-tags", "lambda.norpc", "-ldflags=-s -w"}},
34 }
35 testDir, err := os.Getwd()
36 require.NoError(t, err)
37 tempDir, err := ioutil.TempDir("/tmp", "build-lambda-zip")
38 require.NoError(t, err)
39 for _, test := range cases {
40 require.NoError(t, os.Chdir(testDir))
41 testName := fmt.Sprintf("%s, %v", test.file, test.args)
42 t.Run(testName, func(t *testing.T) {
43 binPath := path.Join(tempDir, test.file+".bin")
44 zipPath := path.Join(tempDir, test.file+".zip")
45
46 buildArgs := []string{"build", "-o", binPath}
47 buildArgs = append(buildArgs, test.args...)
48 buildArgs = append(buildArgs, test.file)
49
50 gocmd := exec.Command("go", buildArgs...)
51 gocmd.Env = append(os.Environ(), "GOOS=linux")
52 gocmd.Stderr = os.Stderr
53 require.NoError(t, gocmd.Run())
54 require.NoError(t, os.Chdir(filepath.Dir(binPath)))
55 require.NoError(t, compressExeAndArgs(zipPath, binPath, []string{}))
56
57 binInfo, err := os.Stat(binPath)
58 require.NoError(t, err)
59 zipInfo, err := os.Stat(zipPath)
60 require.NoError(t, err)
61
62 t.Logf("zip size = %d Kb, bin size = %d Kb", zipInfo.Size()/1024, binInfo.Size()/1024)
63 })
64 }
65
66}
67
68func TestCompressExeAndArgs(t *testing.T) {
69 tempDir, err := ioutil.TempDir("/tmp", "build-lambda-zip")

Callers

nothing calls this directly

Calls 1

compressExeAndArgsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…