github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/pkg/test/runner/sanitize_test.go (about) 1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package runner 16 17 import ( 18 "testing" 19 20 "github.com/google/go-cmp/cmp" 21 ) 22 23 func TestSanitizeTimestamps(t *testing.T) { 24 grid := []struct { 25 Name string 26 Input string 27 Output string 28 }{ 29 { 30 Name: "Prefix match: 12s and 12.1s", 31 Input: ` 32 [RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" 33 [PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 12s 34 [RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) 35 [PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 12.1s 36 `, 37 Output: ` 38 [RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" 39 [PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 0s 40 [RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) 41 [PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 0s 42 `, 43 }, 44 { 45 Name: "Suffix match: 1s and 0.1s", 46 Input: ` 47 [RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" 48 [PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 1s 49 [RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) 50 [PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 0.1s 51 `, 52 Output: ` 53 [RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" 54 [PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 0s 55 [RUNNING] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" on 1 resource(s) 56 [PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" in 0s 57 `, 58 }, 59 { 60 Name: "Only substitute matching lines", 61 Input: ` 62 [RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" 63 [PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 1s 64 [RUNNING] \"gcr.io/kpt-fn/set-namespace:1s\" on 1 resource(s) 65 [PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" notin 1s 66 `, 67 Output: ` 68 [RUNNING] \"gcr.io/kpt-fn/starlark:v0.2.1\" 69 [PASS] \"gcr.io/kpt-fn/starlark:v0.2.1\" in 0s 70 [RUNNING] \"gcr.io/kpt-fn/set-namespace:1s\" on 1 resource(s) 71 [PASS] \"gcr.io/kpt-fn/set-namespace:v0.1.3\" notin 1s 72 `, 73 }, 74 } 75 76 for _, g := range grid { 77 g := g // Avoid range go-tcha 78 t.Run(g.Name, func(t *testing.T) { 79 got := sanitizeTimestamps(g.Input) 80 want := g.Output 81 82 if diff := cmp.Diff(got, want); diff != "" { 83 t.Errorf("unexpected results (-want, +got): %s", diff) 84 } 85 }) 86 } 87 }