Skip to content

Commit 0f2ad63

Browse files
committed
readme: move uuid example to tests
Make example executable by adding reference output to the comments. Part of #123
1 parent 440350e commit 0f2ad63

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

README.md

-47
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ faster than other packages according to public benchmarks.
2626
* [API reference](#api-reference)
2727
* [Walking\-through example in Go](#walking-through-example-in-go)
2828
* [Help](#help)
29-
* [Usage](#usage)
3029
* [Schema](#schema)
3130
* [Custom (un)packing and typed selects and function calls](#custom-unpacking-and-typed-selects-and-function-calls)
3231
* [Options](#options)
@@ -175,52 +174,6 @@ To contact `go-tarantool` developers on any problems, create an issue at
175174
The developers of the [Tarantool server](http://github.com/tarantool/tarantool)
176175
will also be happy to provide advice or receive feedback.
177176

178-
## Usage
179-
180-
To enable support of UUID in msgpack with [google/uuid](https://github.com/google/uuid),
181-
import tarantool/uuid submodule.
182-
```go
183-
package main
184-
185-
import (
186-
"log"
187-
"time"
188-
189-
"github.com/tarantool/go-tarantool"
190-
_ "github.com/tarantool/go-tarantool/uuid"
191-
"github.com/google/uuid"
192-
)
193-
194-
func main() {
195-
server := "127.0.0.1:3013"
196-
opts := tarantool.Opts{
197-
Timeout: 500 * time.Millisecond,
198-
Reconnect: 1 * time.Second,
199-
MaxReconnects: 3,
200-
User: "test",
201-
Pass: "test",
202-
}
203-
client, err := tarantool.Connect(server, opts)
204-
if err != nil {
205-
log.Fatalf("Failed to connect: %s", err.Error())
206-
}
207-
208-
spaceNo := uint32(524)
209-
210-
id, uuidErr := uuid.Parse("c8f0fa1f-da29-438c-a040-393f1126ad39")
211-
if uuidErr != nil {
212-
log.Fatalf("Failed to prepare uuid: %s", uuidErr)
213-
}
214-
215-
resp, err := client.Replace(spaceNo, []interface{}{ id })
216-
217-
log.Println("UUID tuple replace")
218-
log.Println("Error", err)
219-
log.Println("Code", resp.Code)
220-
log.Println("Data", resp.Data)
221-
}
222-
```
223-
224177
## Schema
225178

226179
```go

uuid/example_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Run Tarantool instance before example execution:
2+
// $ cd uuid
3+
// $ TEST_TNT_LISTEN=3013 TEST_TNT_WORK_DIR=$(mktemp -d -t 'tarantool.XXX') tarantool config.lua
4+
// $ go test -v example_test.go
5+
package uuid_test
6+
7+
import (
8+
"fmt"
9+
"log"
10+
"time"
11+
12+
"github.com/google/uuid"
13+
"github.com/tarantool/go-tarantool"
14+
_ "github.com/tarantool/go-tarantool/uuid"
15+
)
16+
17+
// Example demonstrates how to use tuples with UUID. To enable support of UUID
18+
// in msgpack with google/uuid (https://github.com/google/uuid), import
19+
// tarantool/uuid submodule.
20+
func Example() {
21+
server := "127.0.0.1:3013"
22+
opts := tarantool.Opts{
23+
Timeout: 500 * time.Millisecond,
24+
Reconnect: 1 * time.Second,
25+
MaxReconnects: 3,
26+
User: "test",
27+
Pass: "test",
28+
}
29+
client, err := tarantool.Connect(server, opts)
30+
if err != nil {
31+
log.Fatalf("Failed to connect: %s", err.Error())
32+
}
33+
34+
spaceNo := uint32(524)
35+
36+
id, uuidErr := uuid.Parse("c8f0fa1f-da29-438c-a040-393f1126ad39")
37+
if uuidErr != nil {
38+
log.Fatalf("Failed to prepare uuid: %s", uuidErr)
39+
}
40+
41+
resp, err := client.Replace(spaceNo, []interface{}{id})
42+
43+
fmt.Println("UUID tuple replace")
44+
fmt.Println("Error", err)
45+
fmt.Println("Code", resp.Code)
46+
fmt.Println("Data", resp.Data)
47+
}

uuid/uuid.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// See also
88
//
9-
// * Tarantool's commit wht UUID support https://github.com/tarantool/tarantool/commit/d68fc29246714eee505bc9bbcd84a02de17972c5
9+
// * Tarantool commit with UUID support https://github.com/tarantool/tarantool/commit/d68fc29246714eee505bc9bbcd84a02de17972c5
1010
//
1111
// * Tarantool data model https://www.tarantool.io/en/doc/latest/book/box/data_model/
1212
//

0 commit comments

Comments
 (0)