Revert "ci: skip "lib/test-fork-safe-execvpe.sh" on Alpine Linux"
[libnbd.git] / golang / libnbd_210_opt_abort_test.go
blobf03cf06d72bae855b5332c922fe43e9a63cf9ed5
1 /* libnbd golang tests
2 * Copyright Red Hat
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
19 package libnbd
21 import "testing"
23 func Test210OptAbort(t *testing.T) {
24 h, err := Create()
25 if err != nil {
26 t.Fatalf("could not create handle: %s", err)
28 defer h.Close()
30 err = h.SetOptMode(true)
31 if err != nil {
32 t.Fatalf("could not set opt mode: %s", err)
35 err = h.ConnectCommand([]string{
36 "nbdkit", "-s", "--exit-with-parent", "-v", "null",
38 if err != nil {
39 t.Fatalf("could not connect: %s", err)
42 proto, err := h.GetProtocol()
43 if err != nil {
44 t.Fatalf("could not get correct protocol: %s", err)
45 } else if *proto != "newstyle-fixed" {
46 t.Fatalf("wrong protocol detected: %s", *proto)
49 sr, err := h.GetStructuredRepliesNegotiated()
50 if err != nil {
51 t.Fatalf("could not determine structured replies: %s", err)
52 } else if !sr {
53 t.Fatalf("structured replies not negotiated")
56 err = h.OptAbort()
57 if err != nil {
58 t.Fatalf("could not abort option mode: %s", err)
61 closed, err := h.AioIsClosed()
62 if err != nil {
63 t.Fatalf("could not determine state after opt_abort: %s", err)
64 } else if !closed {
65 t.Fatalf("wrong state after opt_abort")
68 _, err = h.GetSize()
69 if err == nil {
70 t.Fatalf("getting a size should not be possible")