forked from kptdev/kpt
-
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.
tests: Fix test flake from timestamp sanitization (kptdev#2713) (kptd…
…ev#2742) * Fix test flake from timestamp sanitization When timestamps "overlap", sanitization did not work correctly. For example: in 1s ... in 2.1s The first substitution would replace 1s => 0s in 0s ... in 2.0s The second substitution is predetermined, and replaces 2.1s => 0s, but 2.1s is no longer in the string. * Use new sanitization function in tests, remove old function Co-authored-by: Justin Santa Barbara <[email protected]>
- Loading branch information
1 parent
22a9f8a
commit 699a72e
Showing
3 changed files
with
90 additions
and
7 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,73 @@ | ||
package runner | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestSanitizeTimestamps(t *testing.T) { | ||
grid := []struct { | ||
Name string | ||
Input string | ||
Output string | ||
}{ | ||
{ | ||
Name: "Prefix match: 12s and 12.1s", | ||
Input: ` | ||
[RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" | ||
[PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 12s | ||
[RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) | ||
[PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 12.1s | ||
`, | ||
Output: ` | ||
[RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" | ||
[PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 0s | ||
[RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) | ||
[PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 0s | ||
`, | ||
}, | ||
{ | ||
Name: "Suffix match: 1s and 0.1s", | ||
Input: ` | ||
[RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" | ||
[PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 1s | ||
[RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) | ||
[PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 0.1s | ||
`, | ||
Output: ` | ||
[RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" | ||
[PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 0s | ||
[RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) | ||
[PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 0s | ||
`, | ||
}, | ||
{ | ||
Name: "Only substitute matching lines", | ||
Input: ` | ||
[RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" | ||
[PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 1s | ||
[RUNNING] \"gcr.io/kpt-fn/set-namespace:1s\" on 1 resource(s) | ||
[PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" notin 1s | ||
`, | ||
Output: ` | ||
[RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" | ||
[PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 0s | ||
[RUNNING] \"gcr.io/kpt-fn/set-namespace:1s\" on 1 resource(s) | ||
[PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" notin 1s | ||
`, | ||
}, | ||
} | ||
|
||
for _, g := range grid { | ||
g := g // Avoid range go-tcha | ||
t.Run(g.Name, func(t *testing.T) { | ||
got := sanitizeTimestamps(g.Input) | ||
want := g.Output | ||
|
||
if diff := cmp.Diff(got, want); diff != "" { | ||
t.Errorf("unexpected results (-want, +got): %s", diff) | ||
} | ||
}) | ||
} | ||
} |