github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/datetime_add_test.go (about) 1 package functions 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_DateTimeAdd(t *testing.T) { 11 tests := []struct { 12 name string 13 args []interface{} 14 expected interface{} 15 }{ 16 17 { 18 name: "datetime add 1 years", 19 args: []interface{}{ 20 "2010-01-01T00:00:00Z", 21 "P1Y", 22 }, 23 expected: "2011-01-01T00:00:00Z", 24 }, 25 { 26 name: "datetime add 3 months", 27 args: []interface{}{ 28 "2010-01-01T00:00:00Z", 29 "P3M", 30 }, 31 expected: "2010-04-01T00:00:00Z", 32 }, 33 } 34 for _, tt := range tests { 35 t.Run(tt.name, func(t *testing.T) { 36 actual := DateTimeAdd(tt.args...) 37 assert.Equal(t, tt.expected, actual) 38 }) 39 } 40 } 41 42 func Test_ISO8601DurationParse(t *testing.T) { 43 tests := []struct { 44 name string 45 args string 46 expected Iso8601Duration 47 }{ 48 49 { 50 name: "parse 1 year", 51 args: "P1Y", 52 expected: Iso8601Duration{Y: 1}, 53 }, 54 { 55 name: "parse 3 months", 56 args: "P3M", 57 expected: Iso8601Duration{M: 3}, 58 }, 59 { 60 name: "parse 12 hours", 61 args: "PT12H", 62 expected: Iso8601Duration{TH: 12}, 63 }, 64 } 65 for _, tt := range tests { 66 t.Run(tt.name, func(t *testing.T) { 67 actual, err := parseISO8601(tt.args) 68 require.NoError(t, err) 69 assert.Equal(t, tt.expected, actual) 70 }) 71 } 72 }