github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/helper_test.go (about) 1 package models 2 3 import "testing" 4 5 func Test_truncateLongMessage(t *testing.T) { 6 cases := []struct { 7 Name string 8 Text string 9 Expected string 10 }{ 11 { 12 Name: "short text", 13 Text: "foo", 14 Expected: "foo", 15 }, 16 { 17 Name: "long text", 18 Text: "looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text", 19 Expected: "looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong...", 20 }, 21 { 22 Name: "with newlines", 23 Text: `foo 24 bar`, 25 Expected: "foo\\nbar", 26 }, 27 } 28 29 for _, tc := range cases { 30 ret := truncateLongMessage(tc.Text) 31 if ret != tc.Expected { 32 t.Fatalf("Fail `%s`: expected=%s got=%s", tc.Name, tc.Expected, ret) 33 } 34 } 35 }