-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
67 lines (59 loc) · 1.67 KB
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gerrittest
import (
"context"
"log"
"github.com/opalmer/dockertest"
)
// You can start the Gerrit container using the NewContainer() function. In
// this example an random port will be used for both http and the default
// image will be used. This kind of setup is useful if you don't want to
// gerrittest to perform any setup steps for you.
func ExampleNewContainer() {
container, err := NewContainer(
context.Background(), dockertest.RandomPort, dockertest.RandomPort, "")
if err != nil {
log.Fatal(err)
}
// Terminate the container when you're done.
if err := container.Terminate(); err != nil {
log.Fatal(err)
}
}
// Once you've started the service you'll want to setup Gerrit inside
// the container. Running Setup.Init will cause the administrative user to
// be created, generate an http API password and insert a public key for ssh
// access.
func ExampleGerrit_CreateChange() {
cfg := NewConfig()
gerrit, err := New(cfg)
if err != nil {
log.Fatal(err)
}
files := map[string]string{
"README.md": "# Hello",
"scripts/foo.bash": "echo 'foo'",
}
change, err := gerrit.CreateChange("testing", "test")
if err != nil {
log.Fatal(err)
}
defer change.Destroy() // nolint: errcheck
defer gerrit.Destroy() // nolint: errcheck
for relative, content := range files {
if err := change.Add(relative, 0600, content); err != nil {
log.Fatal(err)
}
}
if err := change.Push(); err != nil {
log.Fatal(err)
}
if _, err := change.ApplyLabel("1", CodeReviewLabel, 2); err != nil {
log.Fatal(err)
}
if _, err := change.ApplyLabel("1", VerifiedLabel, 1); err != nil {
log.Fatal(err)
}
if _, err := change.Submit(); err != nil {
log.Fatal(err)
}
}