Repository: knative/pkg
Pull request #1376 (2020-06-03 14:06:38)

[master] Fix spelling errors
<!--[master] Fix spelling errors-->
<!---->
Produced via:
  `github.com/client9/misspell`
/assign n3wscott vagababov
/cc n3wscott vagababov


knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1376#" title="Author self-approved">mattmoor</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[test/OWNERS](https://github.com/knative/pkg/blob/master/test/OWNERS)~~ [mattmoor]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
knative-metrics-robot: The following is the coverage report on the affected files.
Say `/test pull-knative-pkg-go-coverage` to re-run this coverage report

File | Old Coverage | New Coverage | Delta
---- |:------------:|:------------:|:-----:
[test/junit/junit.go](https://storage.cloud.google.com/knative-prow/pr-logs/pull/knative_pkg/1376/pull-knative-pkg-go-coverage/1268182421614891009/artifacts/line-cov.html#file0) | 74.1% | 92.1% | 18.0


Patch:
diff --git a/configmap/example.go b/configmap/example.go
index ee17666b7..2ffe448e5 100644
--- a/configmap/example.go
+++ b/configmap/example.go
@@ -17,6 +17,7 @@ limitations under the License.
 package configmap
 
 import (
+	"fmt"
 	"hash/crc32"
 )
 
@@ -29,6 +30,6 @@ const (
 )
 
 // Checksum generates a checksum for the example value to be compared against a respective label.
-func Checksum(value string) uint32 {
-	return crc32.ChecksumIEEE([]byte(value))
+func Checksum(value string) string {
+	return fmt.Sprintf("%08x", crc32.ChecksumIEEE([]byte(value)))
 }
diff --git a/configmap/hash-gen/main.go b/configmap/hash-gen/main.go
index ff105b7d7..c6e5110e3 100644
--- a/configmap/hash-gen/main.go
+++ b/configmap/hash-gen/main.go
@@ -74,7 +74,7 @@ func process(data []byte) ([]byte, error) {
 		return nil, errors.New("'metadata.labels' not found")
 	}
 
-	checksum := fmt.Sprint(configmap.Checksum(example.Value))
+	checksum := configmap.Checksum(example.Value)
 	existingLabel := value(labels, configmap.ExampleChecksumLabel)
 	if existingLabel != nil {
 		existingLabel.Value = checksum
diff --git a/webhook/configmaps/configmaps.go b/webhook/configmaps/configmaps.go
index 8cc150b0a..f6ffb81b7 100644
--- a/webhook/configmaps/configmaps.go
+++ b/webhook/configmaps/configmaps.go
@@ -187,7 +187,7 @@ func (ac *reconciler) validate(ctx context.Context, req *admissionv1beta1.Admiss
 	exampleData, hasExampleData := newObj.Data[configmap.ExampleKey]
 	exampleChecksum, hasExampleChecksumLabel := newObj.Labels[configmap.ExampleChecksumLabel]
 	if hasExampleData && hasExampleChecksumLabel &&
-		exampleChecksum != fmt.Sprint(configmap.Checksum(exampleData)) {
+		exampleChecksum != configmap.Checksum(exampleData) {
 		return fmt.Errorf(
 			"%q modified, you likely wanted to create an unindented configuration",
 			configmap.ExampleKey)


Test patch:
diff --git a/configmap/example_test.go b/configmap/example_test.go
index df6734433..aafc951f0 100644
--- a/configmap/example_test.go
+++ b/configmap/example_test.go
@@ -21,21 +21,21 @@ import "testing"
 func TestChecksum(t *testing.T) {
 	tests := []struct {
 		in   string
-		want uint32
+		want string
 	}{{
 		in:   "",
-		want: 0,
+		want: "00000000",
 	}, {
 		in:   "1",
-		want: 2212294583,
+		want: "83dcefb7",
 	}, {
 		in:   "a somewhat longer test",
-		want: 4278087538,
+		want: "fefe6f72",
 	}}
 
 	for _, test := range tests {
 		if got := Checksum(test.in); got != test.want {
-			t.Errorf("Checksum(%q) = %d, want %d", test.in, got, test.want)
+			t.Errorf("Checksum(%q) = %s, want %s", test.in, got, test.want)
 		}
 	}
 }
diff --git a/configmap/hash-gen/testdata/add_want.yaml b/configmap/hash-gen/testdata/add_want.yaml
index 2cccc9b4d..22de0a376 100644
--- a/configmap/hash-gen/testdata/add_want.yaml
+++ b/configmap/hash-gen/testdata/add_want.yaml
@@ -19,7 +19,7 @@ metadata:
   namespace: knative-serving
   labels:
     serving.knative.dev/release: devel
-    knative.dev/example-checksum: "2958957236"
+    knative.dev/example-checksum: b05e1ab4
 data:
   leave-me: "alone"
   _example: |
diff --git a/configmap/hash-gen/testdata/update_want.yaml b/configmap/hash-gen/testdata/update_want.yaml
index 2cccc9b4d..22de0a376 100644
--- a/configmap/hash-gen/testdata/update_want.yaml
+++ b/configmap/hash-gen/testdata/update_want.yaml
@@ -19,7 +19,7 @@ metadata:
   namespace: knative-serving
   labels:
     serving.knative.dev/release: devel
-    knative.dev/example-checksum: "2958957236"
+    knative.dev/example-checksum: b05e1ab4
 data:
   leave-me: "alone"
   _example: |
diff --git a/configmap/testing/configmap.go b/configmap/testing/configmap.go
index bd61285bf..5c4a2d8c1 100644
--- a/configmap/testing/configmap.go
+++ b/configmap/testing/configmap.go
@@ -86,7 +86,7 @@ func ConfigMapsFromTestFile(t *testing.T, name string, allowed ...string) (*core
 	// Check that the hashed exampleBody matches the assigned label, if present.
 	gotChecksum, hasExampleChecksumLabel := orig.Labels[configmap.ExampleChecksumLabel]
 	if hasExampleBody && hasExampleChecksumLabel {
-		wantChecksum := fmt.Sprint(configmap.Checksum(exampleBody))
+		wantChecksum := configmap.Checksum(exampleBody)
 		if gotChecksum != wantChecksum {
 			t.Errorf("example checksum label = %s, want %s", gotChecksum, wantChecksum)
 		}
diff --git a/test/junit/junit_test.go b/test/junit/junit_test.go
index 21cc64dc7..7241b8bea 100644
--- a/test/junit/junit_test.go
+++ b/test/junit/junit_test.go
@@ -160,8 +160,8 @@ func TestCreateXMLErrorMsg(t *testing.T) {
 	}
 	defer os.RemoveAll(testDir) // clean up
 	dest := path.Join(testDir, "TestCreateXMLErrorTestFile")
-	CreateXMLErrorMsg("dummySuite", "dummyTest", "dummyError has occured", dest)
-	expected := `<testsuites><testsuite name="dummySuite" time="0" failures="1" tests="1"><testcase name="dummyTest" time="0" classname=""><failure>dummyError has occured</failure><properties></properties></testcase><properties></properties></testsuite></testsuites>`
+	CreateXMLErrorMsg("dummySuite", "dummyTest", "dummyError has occurred", dest)
+	expected := `<testsuites><testsuite name="dummySuite" time="0" failures="1" tests="1"><testcase name="dummyTest" time="0" classname=""><failure>dummyError has occurred</failure><properties></properties></testcase><properties></properties></testsuite></testsuites>`
 
 	got, err := ioutil.ReadFile(dest)
 	if err != nil {