forked from hashicorp/terraform
-
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.
command: Display state ID in PreApply+PostApply (hashicorp#12261)
- Loading branch information
1 parent
c2755e2
commit e41b763
Showing
2 changed files
with
125 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestTruncateId(t *testing.T) { | ||
testCases := []struct { | ||
Input string | ||
Expected string | ||
MaxLen int | ||
}{ | ||
{ | ||
Input: "Hello world", | ||
Expected: "H...d", | ||
MaxLen: 3, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "H...d", | ||
MaxLen: 5, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "He...d", | ||
MaxLen: 6, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "He...ld", | ||
MaxLen: 7, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "Hel...ld", | ||
MaxLen: 8, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "Hel...rld", | ||
MaxLen: 9, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "Hell...rld", | ||
MaxLen: 10, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "Hello world", | ||
MaxLen: 11, | ||
}, | ||
{ | ||
Input: "Hello world", | ||
Expected: "Hello world", | ||
MaxLen: 12, | ||
}, | ||
} | ||
for i, tc := range testCases { | ||
testName := fmt.Sprintf("%d", i) | ||
t.Run(testName, func(t *testing.T) { | ||
out := truncateId(tc.Input, tc.MaxLen) | ||
if out != tc.Expected { | ||
t.Fatalf("Expected %q to be shortened to %d as %q (given: %q)", | ||
tc.Input, tc.MaxLen, tc.Expected, out) | ||
} | ||
}) | ||
} | ||
} |