github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/operations/operations_cloud_aws_test.go (about) 1 // Copyright 2016-2018, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package operations 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func Test_extractLambdaLogMessage(t *testing.T) { 24 t.Parallel() 25 26 res := extractLambdaLogMessage("START RequestId: 25e0d1e0-cbd6-11e7-9808-c7085dfe5723 Version: $LATEST\n", "foo") 27 assert.Nil(t, res) 28 res = extractLambdaLogMessage("2017-11-17T20:30:27.736Z 25e0d1e0-cbd6-11e7-9808-c7085dfe5723 GET /todo\n", "foo") 29 assert.NotNil(t, res) 30 assert.Equal(t, "GET /todo", res.Message) 31 res = extractLambdaLogMessage("END RequestId: 25e0d1e0-cbd6-11e7-9808-c7085dfe5723\n", "foo") 32 assert.Nil(t, res) 33 } 34 35 func Test_functionNameFromLogGroupNameRegExp(t *testing.T) { 36 t.Parallel() 37 38 match := oldFunctionNameFromLogGroupNameRegExp.FindStringSubmatch("/aws/lambda/examples-todoc57917fa023a27bc") 39 assert.Len(t, match, 2) 40 assert.Equal(t, "examples-todoc57917fa", match[1]) 41 } 42 43 func Test_oldFunctionNameFromLogGroupNameRegExp(t *testing.T) { 44 t.Parallel() 45 46 match := functionNameFromLogGroupNameRegExp.FindStringSubmatch("/aws/lambda/examples-todoc57917fa-023a27b") 47 assert.Len(t, match, 2) 48 assert.Equal(t, "examples-todoc57917fa", match[1]) 49 } 50 51 func Test_extractMultilineLambdaLogMessage(t *testing.T) { 52 t.Parallel() 53 54 res := extractLambdaLogMessage( 55 "2018-01-30T06:48:09.447Z\t840a5ca2-0589-11e8-af88-c5048a8b7b82\tfirst line\nsecond line\n\n", "foo") 56 // Keep embedded newline and the one extra trailing newline. 57 assert.Equal(t, "first line\nsecond line\n", res.Message) 58 }