Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API section to README; add HACKING.md; remove Makefile (#67)
- Loading branch information
Showing
3 changed files
with
175 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Hacking on Pebble | ||
|
||
Hacking on Pebble is easy. It's written in Go, so install or [download](https://golang.org/dl/) a copy of the latest version of Go. Pebble uses [Go modules](https://golang.org/ref/mod) for managing dependencies, so all of the standard Go tooling just works. | ||
|
||
To compile and run Pebble, use the `go run` command on the `cmd/pebble` directory. The first time you run it, it will download dependencies and build packages, so will take a few seconds (but after that be very fast): | ||
|
||
``` | ||
$ go run ./cmd/pebble | ||
Pebble lets you control services and perform management actions on | ||
the system that is running them. | ||
Usage: pebble <command> [<options>...] | ||
... | ||
``` | ||
|
||
If you want to build and install the executable to your `~/go/bin` directory (which you may want to add to your path), use `go install`: | ||
|
||
``` | ||
$ go install ./cmd/pebble | ||
``` | ||
|
||
However, during development it's easiest just to use `go run`, as that will automatically recompile if you've made any changes. | ||
|
||
|
||
## Running the daemon | ||
|
||
To run the Pebble daemon, set the `$PEBBLE` environment variable and use the `pebble run` sub-command, something like this: | ||
|
||
``` | ||
$ mkdir ~/pebble | ||
$ export PEBBLE=~/pebble | ||
$ go run ./cmd/pebble run | ||
2021-09-15T01:37:23.962Z [pebble] Started daemon. | ||
... | ||
``` | ||
|
||
|
||
## Using the CLI client | ||
|
||
The use the Pebble command line client, run one of the other Pebble sub-commands, such as `pebble plan` or `pebble services` (if the server is running in one terminal, do this in another): | ||
|
||
``` | ||
$ export PEBBLE=~/pebble | ||
$ go run ./cmd/pebble plan | ||
services: | ||
snappass: | ||
override: replace | ||
command: sleep 60 | ||
$ go run ./cmd/pebble services | ||
Service Startup Current | ||
snappass disabled inactive | ||
``` | ||
|
||
|
||
## Using Curl to hit the API | ||
|
||
For debugging, you can also use [curl](https://curl.se/) in Unix socket mode to hit the Pebble API: | ||
|
||
``` | ||
$ curl --unix-socket ~/pebble/.pebble.socket 'http://localhost/v1/services?names=snappass' | jq | ||
% Total % Received % Xferd Average Speed Time Time Time Current | ||
Dload Upload Total Spent Left Speed | ||
100 120 100 120 0 0 117k 0 --:--:-- --:--:-- --:--:-- 117k | ||
{ | ||
"type": "sync", | ||
"status-code": 200, | ||
"status": "OK", | ||
"result": [ | ||
{ | ||
"name": "snappass", | ||
"startup": "disabled", | ||
"current": "inactive" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
|
||
## Running the tests | ||
|
||
Pebble has a suite of Go unit tests, which you can run using the regular `go test` command. To test all packages in the Pebble repository: | ||
|
||
``` | ||
$ go test ./... | ||
ok github.com/canonical/pebble/client (cached) | ||
? github.com/canonical/pebble/cmd [no test files] | ||
ok github.com/canonical/pebble/cmd/pebble 0.095s | ||
... | ||
``` | ||
|
||
To test a single package, simply pass the package path to `go test`: | ||
|
||
``` | ||
$ go test ./cmd/pebble | ||
ok github.com/canonical/pebble/cmd/pebble 0.115s | ||
``` | ||
|
||
To run a single suite or a single test, pass the suite or test name to the [gocheck](https://labix.org/gocheck) test runner: | ||
|
||
``` | ||
$ go test ./cmd/pebble -v -check.v -check.f PebbleSuite | ||
=== RUN Test | ||
PASS: cmd_add_test.go:38: PebbleSuite.TestAdd 0.002s | ||
PASS: format_test.go:52: PebbleSuite.TestCanUnicode 0.000s | ||
... | ||
PASS: cmd_version_test.go:26: PebbleSuite.TestVersionCommand 0.000s | ||
OK: 20 passed | ||
--- PASS: Test (0.02s) | ||
PASS | ||
ok github.com/canonical/pebble/cmd/pebble 0.022s | ||
$ go test ./cmd/pebble -v -check.v -check.f PebbleSuite.TestAdd | ||
=== RUN Test | ||
PASS: cmd_add_test.go:38: PebbleSuite.TestAdd 0.002s | ||
OK: 1 passed | ||
--- PASS: Test (0.00s) | ||
PASS | ||
ok github.com/canonical/pebble/cmd/pebble 0.007s | ||
``` | ||
|
||
Note that during CI we run the tests with `-race` to catch data races: | ||
|
||
``` | ||
$ go test -race ./... | ||
ok github.com/canonical/pebble/client (cached) | ||
? github.com/canonical/pebble/cmd [no test files] | ||
ok github.com/canonical/pebble/cmd/pebble 0.165s | ||
... | ||
``` |
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