summaryrefslogtreecommitdiff
path: root/doc/development/go_guide
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /doc/development/go_guide
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
downloadgitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'doc/development/go_guide')
-rw-r--r--doc/development/go_guide/go_upgrade.md6
-rw-r--r--doc/development/go_guide/index.md75
2 files changed, 78 insertions, 3 deletions
diff --git a/doc/development/go_guide/go_upgrade.md b/doc/development/go_guide/go_upgrade.md
index 75a093a55ac..53f2d7d176a 100644
--- a/doc/development/go_guide/go_upgrade.md
+++ b/doc/development/go_guide/go_upgrade.md
@@ -89,10 +89,14 @@ if you need help finding the correct person or labels:
1. Schedule an update with the [GitLab Development Kit](https://gitlab.com/gitlab-org/gitlab-development-kit/-/issues):
- Title the issue `Support using Go version <VERSION_NUMBER>`.
- Set the issue as related to every issue created in the previous step.
-1. Schedule one issue per Secure Stage team and add the `devops::secure` label to each:
+1. Schedule one issue per Sec Section team that maintains Go based Security Analyzers and add the `section::sec` label to each:
- [Static Analysis tracker](https://gitlab.com/gitlab-org/gitlab/-/issues).
- [Composition Analysis tracker](https://gitlab.com/gitlab-org/gitlab/-/issues).
- [Container Security tracker](https://gitlab.com/gitlab-org/gitlab/-/issues).
+
+ NOTE:
+ Updates to these Security analyzers should not block upgrades to Charts or Omnibus since
+ the analyzers are built independently as separate container images.
1. Schedule builder updates with Distribution projects:
- Dependency and GitLab Development Kit issues created in previous steps should be set as blockers.
- Each issue should have the title `Support building with Go <VERSION_NUMBER>` and description as noted:
diff --git a/doc/development/go_guide/index.md b/doc/development/go_guide/index.md
index 44f8924be04..9bf8b7ef89a 100644
--- a/doc/development/go_guide/index.md
+++ b/doc/development/go_guide/index.md
@@ -364,8 +364,7 @@ JSON format, as all our infrastructure assumes that. When using
[Logrus](https://github.com/sirupsen/logrus) you can turn on structured
logging simply by using the build in [JSON
formatter](https://github.com/sirupsen/logrus#formatters). This follows the
-same logging type we use in our [Ruby
-applications](../logging.md#use-structured-json-logging).
+same logging type we use in our [Ruby applications](../logging.md#use-structured-json-logging).
#### How to use Logrus
@@ -451,6 +450,78 @@ The conventional Secure [analyzer](https://gitlab.com/gitlab-org/security-produc
If the scanner report is small, less than 35 lines, then feel free to [inline the report](https://gitlab.com/gitlab-org/security-products/analyzers/sobelow/-/blob/8bd2428a/convert/convert_test.go#L13-77) rather than use a `testdata` directory.
+#### Test Diffs
+
+The [go-cmp]<https://github.com/google/go-cmp> package should be used when comparing large structs in tests. It makes it possible to output a specific diff where the two structs differ, rather than seeing the whole of both structs printed out in the test logs. Here is a small example:
+
+```golang
+package main
+
+import (
+ "reflect"
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+type Foo struct {
+ Desc Bar
+ Point Baz
+}
+
+type Bar struct {
+ A string
+ B string
+}
+
+type Baz struct {
+ X int
+ Y int
+}
+
+func TestHelloWorld(t *testing.T) {
+ want := Foo{
+ Desc: Bar{A: "a", B: "b"},
+ Point: Baz{X: 1, Y: 2},
+ }
+
+ got := Foo{
+ Desc: Bar{A: "a", B: "b"},
+ Point: Baz{X: 2, Y: 2},
+ }
+
+ t.Log("reflect comparison:")
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("Wrong result. want:\n%v\nGot:\n%v", want, got)
+ }
+
+ t.Log("cmp comparison:")
+ if diff := cmp.Diff(want, got); diff != "" {
+ t.Errorf("Wrong result. (-want +got):\n%s", diff)
+ }
+}
+```
+
+The output demonstrates why `go-cmp` is far superior when comparing large structs. Even though you could spot the difference with this small difference, it quickly gets unwieldy as the data grows.
+
+```plaintext
+ main_test.go:36: reflect comparison:
+ main_test.go:38: Wrong result. want:
+ {{a b} {1 2}}
+ Got:
+ {{a b} {2 2}}
+ main_test.go:41: cmp comparison:
+ main_test.go:43: Wrong result. (-want +got):
+ main.Foo{
+ Desc: {A: "a", B: "b"},
+ Point: main.Baz{
+ - X: 1,
+ + X: 2,
+ Y: 2,
+ },
+ }
+```
+
---
[Return to Development documentation](../index.md).