...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package test
16
17 import (
18 "regexp"
19 "testing"
20 )
21
22
23
24
25
26 func StringMatchesRegexList(t *testing.T, regexesToMatch []string, targetString string) bool {
27 for _, regexToMatch := range regexesToMatch {
28 matcher, err := regexp.Compile(regexToMatch)
29 if err != nil {
30 t.Fatalf("StringMatchesRegexList: regex '%v' failed to compile", regexToMatch)
31 }
32 if matcher.MatchString(targetString) {
33 return true
34 }
35 }
36 return false
37 }
38
39
40 func TrimLicenseHeaderFromYaml(yaml string) string {
41 r := regexp.MustCompile("(?s)# Copyright.*under the License.\n\n")
42 return r.ReplaceAllString(yaml, "")
43 }
44
45
46 func TrimLicenseHeaderFromTF(yaml string) string {
47 r := regexp.MustCompile("(?s)/\\*\\*\n \\* Copyright.*under the License.\n \\*/\n\n")
48 return r.ReplaceAllString(yaml, "")
49 }
50
View as plain text