-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples_test.go
More file actions
113 lines (100 loc) · 2.73 KB
/
Copy pathexamples_test.go
File metadata and controls
113 lines (100 loc) · 2.73 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package client_test
import (
"context"
"errors"
"fmt"
"log"
"os"
rocks "github.com/tarantool/go-luarocks"
"github.com/tarantool/go-luarocks/client"
)
// ExampleNew mirrors the README quick start: construct the facade against a
// tree and list what is installed (nothing, in a fresh tree).
func ExampleNew() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir)
r, err := client.New(rocks.Config{
Tree: dir,
WorkingDir: ".",
Servers: []string{"http://rocks.tarantool.org/"},
})
if err != nil {
log.Fatal(err)
}
installed, err := r.List(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Println("installed rocks:", len(installed))
// Output: installed rocks: 0
}
// ExampleRocks_Which resolves a module name against the tree; a fresh tree
// has no modules, so the lookup misses.
func ExampleRocks_Which() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir)
r, err := client.New(rocks.Config{Tree: dir, WorkingDir: "."})
if err != nil {
log.Fatal(err)
}
path, ok, err := r.Which(context.Background(), "no.such.module")
if err != nil {
log.Fatal(err)
}
fmt.Printf("%q %v\n", path, ok)
// Output: "" false
}
// ExampleRocks_Search shows the backend contract: operations the native
// backend does not implement return rocks.ErrNotImplemented, discriminated
// with errors.Is.
func ExampleRocks_Search() {
dir, err := os.MkdirTemp("", "rocks-tree")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dir)
r, err := client.New(rocks.Config{Tree: dir, WorkingDir: "."})
if err != nil {
log.Fatal(err)
}
_, err = r.Search(context.Background(), "metrics", client.SearchOpts{})
fmt.Println("not implemented:", errors.Is(err, rocks.ErrNotImplemented))
// Output: not implemented: true
}
// ExampleWithBackend selects the gopher-lua backend, which boots an embedded
// LuaRocks VM lazily on the first write operation.
func ExampleWithBackend() {
r, err := client.New(
rocks.Config{Tree: "/opt/tt/.rocks", WorkingDir: "."},
client.WithBackend(client.BackendLua),
)
if err != nil {
log.Fatal(err)
}
_ = r
}
// ExampleRocks_Install installs a rock and its transitive dependencies into
// the tree. (Runs a real fetch/build; shown for documentation.)
func ExampleRocks_Install() {
r, err := client.New(rocks.Config{
Tree: "/opt/tt/.rocks",
WorkingDir: ".",
Servers: []string{"http://rocks.tarantool.org/"},
Tarantool: rocks.TarantoolConfig{
Prefix: "/opt/tarantool",
IncludeDir: "/opt/tarantool/include/tarantool",
},
})
if err != nil {
log.Fatal(err)
}
if err := r.Install(context.Background(), "metrics", client.InstallOpts{}); err != nil {
log.Fatal(err)
}
}