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 listmetaqf(user_data
int, name
string) int {
28 panic("expected user_data == 42")
31 if (name
== context_base_allocation
) {
37 func Test245OptListMetaQueries(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 /* First pass: empty query should give at least "base:allocation".
59 * The explicit query overrides a non-empty nbd_add_meta_context.
63 err
= h
.AddMetaContext("x-nosuch:")
65 t
.Fatalf("could not request add_meta_context: %s", err
)
67 r
, err
:= h
.OptListMetaContextQueries([]string{ },
68 func(name
string) int {
69 return listmetaqf(42, name
)
72 t
.Fatalf("could not request opt_list_meta_context_queries: %s", err
)
74 if r
!= listq_count || r
< 1 ||
!listq_seen
{
75 t
.Fatalf("unexpected count after opt_list_meta_context_queries")
78 /* Second pass: bogus query has no response. */
81 err
= h
.ClearMetaContexts()
83 t
.Fatalf("could not request add_meta_context: %s", err
)
85 r
, err
= h
.OptListMetaContextQueries([]string{ "x-nosuch:" },
86 func(name
string) int {
87 return listmetaqf(42, name
)
90 t
.Fatalf("could not request opt_list_meta_context_queries: %s", err
)
92 if r
!= 0 || r
!= listq_count || listq_seen
{
93 t
.Fatalf("unexpected count after opt_list_meta_context_queries")
96 /* Third pass: specific query should have one match. */
99 r
, err
= h
.OptListMetaContextQueries([]string{
100 "x-nosuch:", context_base_allocation
},
101 func(name
string) int {
102 return listmetaqf(42, name
)
105 t
.Fatalf("could not request opt_list_meta_context_queries: %s", err
)
107 if r
!= 1 || r
!= listq_count ||
!listq_seen
{
108 t
.Fatalf("unexpected count after opt_list_meta_context_queries")
113 t
.Fatalf("could not request opt_abort: %s", err
)