4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 func setmetaqf(user_data
int, name
string) int {
28 panic("expected user_data == 42")
31 if (name
== context_base_allocation
) {
37 func Test255OptSetMetaQueries(t
*testing
.T
) {
38 /* Get into negotiating state. */
41 t
.Fatalf("could not create handle: %s", err
)
45 err
= h
.SetOptMode(true)
47 t
.Fatalf("could not set opt mode: %s", err
)
50 err
= h
.ConnectCommand([]string{
51 "nbdkit", "-s", "--exit-with-parent", "-v",
55 t
.Fatalf("could not connect: %s", err
)
58 /* nbdkit does not match wildcard for SET, even though it does for LIST */
61 r
, err
:= h
.OptSetMetaContextQueries([]string{"base:"},
62 func(name
string) int {
63 return setmetaqf(42, name
)
66 t
.Fatalf("could not request opt_set_meta_context_queries: %s", err
)
68 if r
!= setq_count || r
!= 0 || setq_seen
{
69 t
.Fatalf("unexpected count after opt_set_meta_context_queries")
72 /* Negotiating with no contexts is not an error, but selects nothing.
73 * An explicit empty list overrides a non-empty implicit list.
77 err
= h
.AddMetaContext(context_base_allocation
)
79 t
.Fatalf("could not request add_meta_context: %s", err
)
81 r
, err
= h
.OptSetMetaContextQueries([]string{}, func(name
string) int {
82 return setmetaqf(42, name
)
85 t
.Fatalf("could not request opt_set_meta_context_queries: %s", err
)
87 if r
!= setq_count || r
!= 0 || setq_seen
{
88 t
.Fatalf("unexpected set_count after opt_set_meta_context_queries")
90 meta
, err
:= h
.CanMetaContext(context_base_allocation
)
92 t
.Fatalf("could not check can meta context: %s", err
)
95 t
.Fatalf("unexpected can meta context state")
98 /* Request 2 with expectation of 1; with SetRequestMetaContext off */
101 r
, err
= h
.OptSetMetaContextQueries([]string{
102 "x-nosuch:context", context_base_allocation
},
103 func(name
string) int {
104 return setmetaqf(42, name
)
107 t
.Fatalf("could not request opt_set_meta_context_queries: %s", err
)
109 if r
!= 1 || r
!= setq_count ||
!setq_seen
{
110 t
.Fatalf("unexpected set_count after opt_set_meta_context_queries")
112 meta
, err
= h
.CanMetaContext(context_base_allocation
)
114 t
.Fatalf("could not check can meta context: %s", err
)
117 t
.Fatalf("unexpected can meta context state")
120 /* Transition to transmission phase; our last set should remain active */
121 err
= h
.SetRequestMetaContext(false)
123 t
.Fatalf("could not set_request_meta_context: %s", err
)
127 t
.Fatalf("could not request opt_go: %s", err
)
129 meta
, err
= h
.CanMetaContext(context_base_allocation
)
131 t
.Fatalf("could not check can meta context: %s", err
)
134 t
.Fatalf("unexpected can meta context state")
137 err
= h
.Shutdown(nil)
139 t
.Fatalf("could not request shutdown: %s", err
)