forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating template check for go templates (GoogleCloudPlatform#12097)
- Loading branch information
1 parent
7eddcfd
commit b477589
Showing
5 changed files
with
61 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package gotemplate | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestCheckVersionGuards(t *testing.T) { | ||
cases := map[string]struct { | ||
fileText string | ||
expectedResults []string | ||
}{ | ||
"allow standard format targeting ga": { | ||
fileText: "some text\n{{- if ne $.TargetVersionName \"ga\" }}\nmore text", | ||
expectedResults: nil, | ||
}, | ||
"disallow targeting beta": { | ||
fileText: "some text\n{{- if ne $.TargetVersionName \"beta\" }}\nmore text", | ||
expectedResults: []string{`2: {{- if ne $.TargetVersionName "beta" }}`}, | ||
}, | ||
"one valid, one invalid": { | ||
fileText: "some text\n{{- if ne $.TargetVersionName \"beta\" }}\nmore text\n{{- if ne $.TargetVersionName \"ga\" }}", | ||
expectedResults: []string{`2: {{- if ne $.TargetVersionName "beta" }}`}, | ||
}, | ||
"multiple invalid": { | ||
fileText: "some text\n{{- if ne $.TargetVersionName \"beta\" }}\nmore text\n\n\n{{- if eq $.TargetVersionName \"beta\" }}", | ||
expectedResults: []string{`2: {{- if ne $.TargetVersionName "beta" }}`, `6: {{- if eq $.TargetVersionName "beta" }}`}, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
tc := tc | ||
t.Run(tn, func(t *testing.T) { | ||
t.Parallel() | ||
results := CheckVersionGuards(strings.NewReader(tc.fileText)) | ||
if len(results) != len(tc.expectedResults) { | ||
t.Errorf("Expected length %d, got %d", len(tc.expectedResults), len(results)) | ||
return | ||
} | ||
for i, result := range results { | ||
if result != tc.expectedResults[i] { | ||
t.Errorf("Expected %v, got %v", tc.expectedResults[i], result) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.