github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/bindings/test/containers_test.go (about)

     1  package test_bindings
     2  
     3  import (
     4  	"net/http"
     5  	"strings"
     6  	"time"
     7  
     8  	"github.com/containers/podman/v2/libpod/define"
     9  	"github.com/containers/podman/v2/pkg/bindings"
    10  	"github.com/containers/podman/v2/pkg/bindings/containers"
    11  	"github.com/containers/podman/v2/pkg/specgen"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  	"github.com/onsi/gomega/gexec"
    15  )
    16  
    17  var _ = Describe("Podman containers ", func() {
    18  	var (
    19  		bt  *bindingTest
    20  		s   *gexec.Session
    21  		err error
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		bt = newBindingTest()
    26  		bt.RestoreImagesFromCache()
    27  		s = bt.startAPIService()
    28  		time.Sleep(1 * time.Second)
    29  		err := bt.NewConnection()
    30  		Expect(err).To(BeNil())
    31  	})
    32  
    33  	AfterEach(func() {
    34  		s.Kill()
    35  		bt.cleanup()
    36  	})
    37  
    38  	It("podman pause a bogus container", func() {
    39  		// Pausing bogus container should return 404
    40  		err = containers.Pause(bt.conn, "foobar")
    41  		Expect(err).ToNot(BeNil())
    42  		code, _ := bindings.CheckResponseCode(err)
    43  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
    44  	})
    45  
    46  	It("podman unpause a bogus container", func() {
    47  		// Unpausing bogus container should return 404
    48  		err = containers.Unpause(bt.conn, "foobar")
    49  		Expect(err).ToNot(BeNil())
    50  		code, _ := bindings.CheckResponseCode(err)
    51  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
    52  	})
    53  
    54  	It("podman pause a running container by name", func() {
    55  		// Pausing by name should work
    56  		var name = "top"
    57  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
    58  		Expect(err).To(BeNil())
    59  		err = containers.Pause(bt.conn, name)
    60  		Expect(err).To(BeNil())
    61  
    62  		// Ensure container is paused
    63  		data, err := containers.Inspect(bt.conn, name, nil)
    64  		Expect(err).To(BeNil())
    65  		Expect(data.State.Status).To(Equal("paused"))
    66  	})
    67  
    68  	It("podman pause a running container by id", func() {
    69  		// Pausing by id should work
    70  		var name = "top"
    71  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
    72  		Expect(err).To(BeNil())
    73  		err = containers.Pause(bt.conn, cid)
    74  		Expect(err).To(BeNil())
    75  
    76  		// Ensure container is paused
    77  		data, err := containers.Inspect(bt.conn, cid, nil)
    78  		Expect(err).To(BeNil())
    79  		Expect(data.State.Status).To(Equal("paused"))
    80  	})
    81  
    82  	It("podman unpause a running container by name", func() {
    83  		// Unpausing by name should work
    84  		var name = "top"
    85  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
    86  		Expect(err).To(BeNil())
    87  		err = containers.Pause(bt.conn, name)
    88  		Expect(err).To(BeNil())
    89  		err = containers.Unpause(bt.conn, name)
    90  		Expect(err).To(BeNil())
    91  
    92  		// Ensure container is unpaused
    93  		data, err := containers.Inspect(bt.conn, name, nil)
    94  		Expect(err).To(BeNil())
    95  		Expect(data.State.Status).To(Equal("running"))
    96  	})
    97  
    98  	It("podman unpause a running container by ID", func() {
    99  		// Unpausing by ID should work
   100  		var name = "top"
   101  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   102  		Expect(err).To(BeNil())
   103  		// Pause by name
   104  		err = containers.Pause(bt.conn, name)
   105  		//paused := "paused"
   106  		//_, err = containers.Wait(bt.conn, cid, &paused)
   107  		//Expect(err).To(BeNil())
   108  		err = containers.Unpause(bt.conn, name)
   109  		Expect(err).To(BeNil())
   110  
   111  		// Ensure container is unpaused
   112  		data, err := containers.Inspect(bt.conn, name, nil)
   113  		Expect(err).To(BeNil())
   114  		Expect(data.State.Status).To(Equal("running"))
   115  	})
   116  
   117  	It("podman pause a paused container by name", func() {
   118  		// Pausing a paused container by name should fail
   119  		var name = "top"
   120  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   121  		Expect(err).To(BeNil())
   122  		err = containers.Pause(bt.conn, name)
   123  		Expect(err).To(BeNil())
   124  		err = containers.Pause(bt.conn, name)
   125  		Expect(err).ToNot(BeNil())
   126  		code, _ := bindings.CheckResponseCode(err)
   127  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   128  	})
   129  
   130  	It("podman pause a paused container by id", func() {
   131  		// Pausing a paused container by id should fail
   132  		var name = "top"
   133  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   134  		Expect(err).To(BeNil())
   135  		err = containers.Pause(bt.conn, cid)
   136  		Expect(err).To(BeNil())
   137  		err = containers.Pause(bt.conn, cid)
   138  		Expect(err).ToNot(BeNil())
   139  		code, _ := bindings.CheckResponseCode(err)
   140  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   141  	})
   142  
   143  	It("podman pause a stopped container by name", func() {
   144  		// Pausing a stopped container by name should fail
   145  		var name = "top"
   146  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   147  		Expect(err).To(BeNil())
   148  		err = containers.Stop(bt.conn, name, nil)
   149  		Expect(err).To(BeNil())
   150  		err = containers.Pause(bt.conn, name)
   151  		Expect(err).ToNot(BeNil())
   152  		code, _ := bindings.CheckResponseCode(err)
   153  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   154  	})
   155  
   156  	It("podman pause a stopped container by id", func() {
   157  		// Pausing a stopped container by id should fail
   158  		var name = "top"
   159  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   160  		Expect(err).To(BeNil())
   161  		err = containers.Stop(bt.conn, cid, nil)
   162  		Expect(err).To(BeNil())
   163  		err = containers.Pause(bt.conn, cid)
   164  		Expect(err).ToNot(BeNil())
   165  		code, _ := bindings.CheckResponseCode(err)
   166  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   167  	})
   168  
   169  	It("podman remove a paused container by id without force", func() {
   170  		// Removing a paused container without force should fail
   171  		var name = "top"
   172  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   173  		Expect(err).To(BeNil())
   174  		err = containers.Pause(bt.conn, cid)
   175  		Expect(err).To(BeNil())
   176  		err = containers.Remove(bt.conn, cid, bindings.PFalse, bindings.PFalse)
   177  		Expect(err).ToNot(BeNil())
   178  		code, _ := bindings.CheckResponseCode(err)
   179  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   180  	})
   181  
   182  	It("podman remove a paused container by id with force", func() {
   183  		// Removing a paused container with force should work
   184  		var name = "top"
   185  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   186  		Expect(err).To(BeNil())
   187  		err = containers.Pause(bt.conn, cid)
   188  		Expect(err).To(BeNil())
   189  		err = containers.Remove(bt.conn, cid, bindings.PTrue, bindings.PFalse)
   190  		Expect(err).To(BeNil())
   191  	})
   192  
   193  	It("podman stop a paused container by name", func() {
   194  		// Stopping a paused container by name should fail
   195  		var name = "top"
   196  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   197  		Expect(err).To(BeNil())
   198  		err = containers.Pause(bt.conn, name)
   199  		Expect(err).To(BeNil())
   200  		err = containers.Stop(bt.conn, name, nil)
   201  		Expect(err).ToNot(BeNil())
   202  		code, _ := bindings.CheckResponseCode(err)
   203  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   204  	})
   205  
   206  	It("podman stop a paused container by id", func() {
   207  		// Stopping a paused container by id should fail
   208  		var name = "top"
   209  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   210  		Expect(err).To(BeNil())
   211  		err = containers.Pause(bt.conn, cid)
   212  		Expect(err).To(BeNil())
   213  		err = containers.Stop(bt.conn, cid, nil)
   214  		Expect(err).ToNot(BeNil())
   215  		code, _ := bindings.CheckResponseCode(err)
   216  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   217  	})
   218  
   219  	It("podman stop a running container by name", func() {
   220  		// Stopping a running container by name should work
   221  		var name = "top"
   222  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   223  		Expect(err).To(BeNil())
   224  		err = containers.Stop(bt.conn, name, nil)
   225  		Expect(err).To(BeNil())
   226  
   227  		// Ensure container is stopped
   228  		data, err := containers.Inspect(bt.conn, name, nil)
   229  		Expect(err).To(BeNil())
   230  		Expect(isStopped(data.State.Status)).To(BeTrue())
   231  	})
   232  
   233  	It("podman stop a running container by ID", func() {
   234  		// Stopping a running container by ID should work
   235  		var name = "top"
   236  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   237  		Expect(err).To(BeNil())
   238  		err = containers.Stop(bt.conn, cid, nil)
   239  		Expect(err).To(BeNil())
   240  
   241  		// Ensure container is stopped
   242  		data, err := containers.Inspect(bt.conn, name, nil)
   243  		Expect(err).To(BeNil())
   244  		Expect(isStopped(data.State.Status)).To(BeTrue())
   245  	})
   246  
   247  	It("podman wait no condition", func() {
   248  		var (
   249  			name           = "top"
   250  			exitCode int32 = -1
   251  		)
   252  		_, err := containers.Wait(bt.conn, "foobar", nil)
   253  		Expect(err).ToNot(BeNil())
   254  		code, _ := bindings.CheckResponseCode(err)
   255  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   256  
   257  		errChan := make(chan error)
   258  		_, err = bt.RunTopContainer(&name, nil, nil)
   259  		Expect(err).To(BeNil())
   260  		go func() {
   261  			exitCode, err = containers.Wait(bt.conn, name, nil)
   262  			errChan <- err
   263  			close(errChan)
   264  		}()
   265  		err = containers.Stop(bt.conn, name, nil)
   266  		Expect(err).To(BeNil())
   267  		wait := <-errChan
   268  		Expect(wait).To(BeNil())
   269  		Expect(exitCode).To(BeNumerically("==", 143))
   270  	})
   271  
   272  	It("podman wait to pause|unpause condition", func() {
   273  		var (
   274  			name           = "top"
   275  			exitCode int32 = -1
   276  			pause          = define.ContainerStatePaused
   277  			running        = define.ContainerStateRunning
   278  		)
   279  		errChan := make(chan error)
   280  		_, err := bt.RunTopContainer(&name, nil, nil)
   281  		Expect(err).To(BeNil())
   282  		go func() {
   283  			exitCode, err = containers.Wait(bt.conn, name, &pause)
   284  			errChan <- err
   285  			close(errChan)
   286  		}()
   287  		err = containers.Pause(bt.conn, name)
   288  		Expect(err).To(BeNil())
   289  		wait := <-errChan
   290  		Expect(wait).To(BeNil())
   291  		Expect(exitCode).To(BeNumerically("==", -1))
   292  
   293  		errChan = make(chan error)
   294  		go func() {
   295  			defer GinkgoRecover()
   296  
   297  			_, waitErr := containers.Wait(bt.conn, name, &running)
   298  			errChan <- waitErr
   299  			close(errChan)
   300  		}()
   301  		err = containers.Unpause(bt.conn, name)
   302  		Expect(err).To(BeNil())
   303  		unPausewait := <-errChan
   304  		Expect(unPausewait).To(BeNil())
   305  		Expect(exitCode).To(BeNumerically("==", -1))
   306  	})
   307  
   308  	It("run  healthcheck", func() {
   309  		bt.runPodman([]string{"run", "-d", "--name", "hc", "--health-interval", "disable", "--health-retries", "2", "--health-cmd", "ls / || exit 1", alpine.name, "top"})
   310  
   311  		// bogus name should result in 404
   312  		_, err := containers.RunHealthCheck(bt.conn, "foobar")
   313  		Expect(err).ToNot(BeNil())
   314  		code, _ := bindings.CheckResponseCode(err)
   315  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   316  
   317  		// a container that has no healthcheck should be a 409
   318  		var name = "top"
   319  		bt.RunTopContainer(&name, bindings.PFalse, nil)
   320  		_, err = containers.RunHealthCheck(bt.conn, name)
   321  		Expect(err).ToNot(BeNil())
   322  		code, _ = bindings.CheckResponseCode(err)
   323  		Expect(code).To(BeNumerically("==", http.StatusConflict))
   324  
   325  		// TODO for the life of me, i cannot get this to work. maybe another set
   326  		// of eyes will
   327  		// successful healthcheck
   328  		//status := "healthy"
   329  		//for i:=0; i < 10; i++ {
   330  		//	result, err := containers.RunHealthCheck(connText, "hc")
   331  		//	Expect(err).To(BeNil())
   332  		//	if result.Status != "healthy" {
   333  		//		fmt.Println("Healthcheck container still starting, retrying in 1 second")
   334  		//		time.Sleep(1 * time.Second)
   335  		//		continue
   336  		//	}
   337  		//	status = result.Status
   338  		//	break
   339  		//}
   340  		//Expect(status).To(Equal("healthy"))
   341  
   342  		// TODO enable this when wait is working
   343  		// healthcheck on a stopped container should be a 409
   344  		//err = containers.Stop(connText, "hc", nil)
   345  		//Expect(err).To(BeNil())
   346  		//_, err = containers.Wait(connText, "hc")
   347  		//Expect(err).To(BeNil())
   348  		//_, err = containers.RunHealthCheck(connText, "hc")
   349  		//code, _ = bindings.CheckResponseCode(err)
   350  		//Expect(code).To(BeNumerically("==", http.StatusConflict))
   351  	})
   352  
   353  	It("logging", func() {
   354  		stdoutChan := make(chan string, 10)
   355  		s := specgen.NewSpecGenerator(alpine.name, false)
   356  		s.Terminal = true
   357  		s.Command = []string{"date", "-R"}
   358  		r, err := containers.CreateWithSpec(bt.conn, s)
   359  		Expect(err).To(BeNil())
   360  		err = containers.Start(bt.conn, r.ID, nil)
   361  		Expect(err).To(BeNil())
   362  
   363  		_, err = containers.Wait(bt.conn, r.ID, nil)
   364  		Expect(err).To(BeNil())
   365  
   366  		opts := containers.LogOptions{Stdout: bindings.PTrue, Follow: bindings.PTrue}
   367  		go func() {
   368  			containers.Logs(bt.conn, r.ID, opts, stdoutChan, nil)
   369  		}()
   370  		o := <-stdoutChan
   371  		o = strings.TrimSpace(o)
   372  		_, err = time.Parse(time.RFC1123Z, o)
   373  		Expect(err).ShouldNot(HaveOccurred())
   374  	})
   375  
   376  	It("podman top", func() {
   377  		var name = "top"
   378  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   379  		Expect(err).To(BeNil())
   380  
   381  		// By name
   382  		_, err = containers.Top(bt.conn, name, nil)
   383  		Expect(err).To(BeNil())
   384  
   385  		// By id
   386  		_, err = containers.Top(bt.conn, cid, nil)
   387  		Expect(err).To(BeNil())
   388  
   389  		// With descriptors
   390  		output, err := containers.Top(bt.conn, cid, []string{"user,pid,hpid"})
   391  		Expect(err).To(BeNil())
   392  		header := strings.Split(output[0], "\t")
   393  		for _, d := range []string{"USER", "PID", "HPID"} {
   394  			Expect(d).To(BeElementOf(header))
   395  		}
   396  
   397  		// With bogus ID
   398  		_, err = containers.Top(bt.conn, "IdoNotExist", nil)
   399  		Expect(err).ToNot(BeNil())
   400  
   401  		// With bogus descriptors
   402  		_, err = containers.Top(bt.conn, cid, []string{"Me,Neither"})
   403  		Expect(err).To(BeNil())
   404  	})
   405  
   406  	It("podman bogus container does not exist in local storage", func() {
   407  		// Bogus container existence check should fail
   408  		containerExists, err := containers.Exists(bt.conn, "foobar", false)
   409  		Expect(err).To(BeNil())
   410  		Expect(containerExists).To(BeFalse())
   411  	})
   412  
   413  	It("podman container exists in local storage by name", func() {
   414  		// Container existence check by name should work
   415  		var name = "top"
   416  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   417  		Expect(err).To(BeNil())
   418  		containerExists, err := containers.Exists(bt.conn, name, false)
   419  		Expect(err).To(BeNil())
   420  		Expect(containerExists).To(BeTrue())
   421  	})
   422  
   423  	It("podman container exists in local storage by ID", func() {
   424  		// Container existence check by ID should work
   425  		var name = "top"
   426  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   427  		Expect(err).To(BeNil())
   428  		containerExists, err := containers.Exists(bt.conn, cid, false)
   429  		Expect(err).To(BeNil())
   430  		Expect(containerExists).To(BeTrue())
   431  	})
   432  
   433  	It("podman container exists in local storage by short ID", func() {
   434  		// Container existence check by short ID should work
   435  		var name = "top"
   436  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   437  		Expect(err).To(BeNil())
   438  		containerExists, err := containers.Exists(bt.conn, cid[0:12], false)
   439  		Expect(err).To(BeNil())
   440  		Expect(containerExists).To(BeTrue())
   441  	})
   442  
   443  	It("podman kill bogus container", func() {
   444  		// Killing bogus container should return 404
   445  		err := containers.Kill(bt.conn, "foobar", "SIGTERM")
   446  		Expect(err).ToNot(BeNil())
   447  		code, _ := bindings.CheckResponseCode(err)
   448  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   449  	})
   450  
   451  	It("podman kill a running container by name with SIGINT", func() {
   452  		// Killing a running container should work
   453  		var name = "top"
   454  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   455  		Expect(err).To(BeNil())
   456  		err = containers.Kill(bt.conn, name, "SIGINT")
   457  		Expect(err).To(BeNil())
   458  		_, err = containers.Exists(bt.conn, name, false)
   459  		Expect(err).To(BeNil())
   460  	})
   461  
   462  	It("podman kill a running container by ID with SIGTERM", func() {
   463  		// Killing a running container by ID should work
   464  		var name = "top"
   465  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   466  		Expect(err).To(BeNil())
   467  		err = containers.Kill(bt.conn, cid, "SIGTERM")
   468  		Expect(err).To(BeNil())
   469  		_, err = containers.Exists(bt.conn, cid, false)
   470  		Expect(err).To(BeNil())
   471  	})
   472  
   473  	It("podman kill a running container by ID with SIGKILL", func() {
   474  		// Killing a running container by ID with TERM should work
   475  		var name = "top"
   476  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   477  		Expect(err).To(BeNil())
   478  		err = containers.Kill(bt.conn, cid, "SIGKILL")
   479  		Expect(err).To(BeNil())
   480  	})
   481  
   482  	It("podman kill a running container by bogus signal", func() {
   483  		//Killing a running container by bogus signal should fail
   484  		var name = "top"
   485  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   486  		Expect(err).To(BeNil())
   487  		err = containers.Kill(bt.conn, cid, "foobar")
   488  		Expect(err).ToNot(BeNil())
   489  		code, _ := bindings.CheckResponseCode(err)
   490  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   491  	})
   492  
   493  	It("podman kill latest container with SIGTERM", func() {
   494  		// Killing latest container should work
   495  		var name1 = "first"
   496  		var name2 = "second"
   497  		var latestContainers = 1
   498  		_, err := bt.RunTopContainer(&name1, bindings.PFalse, nil)
   499  		Expect(err).To(BeNil())
   500  		_, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
   501  		Expect(err).To(BeNil())
   502  		containerLatestList, err := containers.List(bt.conn, nil, nil, &latestContainers, nil, nil, nil)
   503  		Expect(err).To(BeNil())
   504  		err = containers.Kill(bt.conn, containerLatestList[0].Names[0], "SIGTERM")
   505  		Expect(err).To(BeNil())
   506  	})
   507  
   508  	It("container init on a bogus container", func() {
   509  		err := containers.ContainerInit(bt.conn, "doesnotexist")
   510  		Expect(err).ToNot(BeNil())
   511  		code, _ := bindings.CheckResponseCode(err)
   512  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   513  	})
   514  
   515  	It("container init", func() {
   516  		s := specgen.NewSpecGenerator(alpine.name, false)
   517  		ctr, err := containers.CreateWithSpec(bt.conn, s)
   518  		Expect(err).To(BeNil())
   519  		err = containers.ContainerInit(bt.conn, ctr.ID)
   520  		Expect(err).To(BeNil())
   521  		//	trying to init again should be an error
   522  		err = containers.ContainerInit(bt.conn, ctr.ID)
   523  		Expect(err).ToNot(BeNil())
   524  	})
   525  
   526  	It("podman prune stopped containers", func() {
   527  		// Start and stop a container to enter in exited state.
   528  		var name = "top"
   529  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   530  		Expect(err).To(BeNil())
   531  		err = containers.Stop(bt.conn, name, nil)
   532  		Expect(err).To(BeNil())
   533  
   534  		// Prune container should return no errors and one pruned container ID.
   535  		pruneResponse, err := containers.Prune(bt.conn, nil)
   536  		Expect(err).To(BeNil())
   537  		Expect(len(pruneResponse.Err)).To(Equal(0))
   538  		Expect(len(pruneResponse.ID)).To(Equal(1))
   539  	})
   540  
   541  	It("podman prune stopped containers with filters", func() {
   542  		// Start and stop a container to enter in exited state.
   543  		var name = "top"
   544  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   545  		Expect(err).To(BeNil())
   546  		err = containers.Stop(bt.conn, name, nil)
   547  		Expect(err).To(BeNil())
   548  
   549  		// Invalid filter keys should return error.
   550  		filtersIncorrect := map[string][]string{
   551  			"status": {"dummy"},
   552  		}
   553  		pruneResponse, err := containers.Prune(bt.conn, filtersIncorrect)
   554  		Expect(err).ToNot(BeNil())
   555  
   556  		// Mismatched filter params no container should be pruned.
   557  		filtersIncorrect = map[string][]string{
   558  			"name": {"r"},
   559  		}
   560  		pruneResponse, err = containers.Prune(bt.conn, filtersIncorrect)
   561  		Expect(err).To(BeNil())
   562  		Expect(len(pruneResponse.Err)).To(Equal(0))
   563  		Expect(len(pruneResponse.ID)).To(Equal(0))
   564  
   565  		// Valid filter params container should be pruned now.
   566  		filters := map[string][]string{
   567  			"name": {"top"},
   568  		}
   569  		pruneResponse, err = containers.Prune(bt.conn, filters)
   570  		Expect(err).To(BeNil())
   571  		Expect(len(pruneResponse.Err)).To(Equal(0))
   572  		Expect(len(pruneResponse.ID)).To(Equal(1))
   573  	})
   574  
   575  	It("podman prune running containers", func() {
   576  		// Start the container.
   577  		var name = "top"
   578  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   579  		Expect(err).To(BeNil())
   580  
   581  		// Check if the container is running.
   582  		data, err := containers.Inspect(bt.conn, name, nil)
   583  		Expect(err).To(BeNil())
   584  		Expect(data.State.Status).To(Equal("running"))
   585  
   586  		// Prune. Should return no error no prune response ID.
   587  		pruneResponse, err := containers.Prune(bt.conn, nil)
   588  		Expect(err).To(BeNil())
   589  		Expect(len(pruneResponse.ID)).To(Equal(0))
   590  	})
   591  
   592  	It("podman inspect bogus container", func() {
   593  		_, err := containers.Inspect(bt.conn, "foobar", nil)
   594  		Expect(err).ToNot(BeNil())
   595  		code, _ := bindings.CheckResponseCode(err)
   596  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   597  	})
   598  
   599  	It("podman inspect running container", func() {
   600  		var name = "top"
   601  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   602  		Expect(err).To(BeNil())
   603  		// Inspecting running container should succeed
   604  		_, err = containers.Inspect(bt.conn, name, nil)
   605  		Expect(err).To(BeNil())
   606  	})
   607  
   608  	It("podman inspect stopped container", func() {
   609  		var name = "top"
   610  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   611  		Expect(err).To(BeNil())
   612  		err = containers.Stop(bt.conn, name, nil)
   613  		Expect(err).To(BeNil())
   614  		// Inspecting stopped container should succeed
   615  		_, err = containers.Inspect(bt.conn, name, nil)
   616  		Expect(err).To(BeNil())
   617  	})
   618  
   619  	It("podman inspect running container with size", func() {
   620  		var name = "top"
   621  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   622  		Expect(err).To(BeNil())
   623  		_, err = containers.Inspect(bt.conn, name, bindings.PTrue)
   624  		Expect(err).To(BeNil())
   625  	})
   626  
   627  	It("podman inspect stopped container with size", func() {
   628  		var name = "top"
   629  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   630  		Expect(err).To(BeNil())
   631  		err = containers.Stop(bt.conn, name, nil)
   632  		Expect(err).To(BeNil())
   633  		// Inspecting stopped container with size should succeed
   634  		_, err = containers.Inspect(bt.conn, name, bindings.PTrue)
   635  		Expect(err).To(BeNil())
   636  	})
   637  
   638  	It("podman remove bogus container", func() {
   639  		err = containers.Remove(bt.conn, "foobar", nil, nil)
   640  		code, _ := bindings.CheckResponseCode(err)
   641  		Expect(code).To(BeNumerically("==", http.StatusNotFound))
   642  	})
   643  
   644  	It("podman remove running container by name", func() {
   645  		var name = "top"
   646  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   647  		Expect(err).To(BeNil())
   648  		// Removing running container should fail
   649  		err = containers.Remove(bt.conn, name, nil, nil)
   650  		Expect(err).ToNot(BeNil())
   651  		code, _ := bindings.CheckResponseCode(err)
   652  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   653  	})
   654  
   655  	It("podman remove running container by ID", func() {
   656  		var name = "top"
   657  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   658  		Expect(err).To(BeNil())
   659  		// Removing running container should fail
   660  		err = containers.Remove(bt.conn, cid, nil, nil)
   661  		Expect(err).ToNot(BeNil())
   662  		code, _ := bindings.CheckResponseCode(err)
   663  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   664  	})
   665  
   666  	It("podman forcibly remove running container by name", func() {
   667  		var name = "top"
   668  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   669  		Expect(err).To(BeNil())
   670  		// Removing running container should fail
   671  		err = containers.Remove(bt.conn, name, bindings.PTrue, nil)
   672  		Expect(err).To(BeNil())
   673  		//code, _ := bindings.CheckResponseCode(err)
   674  		//Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   675  	})
   676  
   677  	It("podman forcibly remove running container by ID", func() {
   678  		var name = "top"
   679  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   680  		Expect(err).To(BeNil())
   681  		// Removing running container should fail
   682  		err = containers.Remove(bt.conn, cid, bindings.PTrue, nil)
   683  		Expect(err).To(BeNil())
   684  		//code, _ := bindings.CheckResponseCode(err)
   685  		//Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   686  	})
   687  
   688  	It("podman remove running container and volume by name", func() {
   689  		var name = "top"
   690  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   691  		Expect(err).To(BeNil())
   692  		// Removing running container should fail
   693  		err = containers.Remove(bt.conn, name, nil, bindings.PTrue)
   694  		Expect(err).ToNot(BeNil())
   695  		code, _ := bindings.CheckResponseCode(err)
   696  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   697  	})
   698  
   699  	It("podman remove running container and volume by ID", func() {
   700  		var name = "top"
   701  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   702  		Expect(err).To(BeNil())
   703  		// Removing running container should fail
   704  		err = containers.Remove(bt.conn, cid, nil, bindings.PTrue)
   705  		Expect(err).ToNot(BeNil())
   706  		code, _ := bindings.CheckResponseCode(err)
   707  		Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   708  	})
   709  
   710  	It("podman forcibly remove running container and volume by name", func() {
   711  		var name = "top"
   712  		_, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   713  		Expect(err).To(BeNil())
   714  		// Removing running container should fail
   715  		err = containers.Remove(bt.conn, name, bindings.PTrue, bindings.PTrue)
   716  		Expect(err).To(BeNil())
   717  		//code, _ := bindings.CheckResponseCode(err)
   718  		//Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   719  	})
   720  
   721  	It("podman forcibly remove running container and volume by ID", func() {
   722  		var name = "top"
   723  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   724  		Expect(err).To(BeNil())
   725  		// Removing running container should fail
   726  		err = containers.Remove(bt.conn, cid, bindings.PTrue, bindings.PTrue)
   727  		Expect(err).To(BeNil())
   728  		//code, _ := bindings.CheckResponseCode(err)
   729  		//Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
   730  	})
   731  
   732  	It("List containers with filters", func() {
   733  		var name = "top"
   734  		var name2 = "top2"
   735  		cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
   736  		Expect(err).To(BeNil())
   737  		_, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
   738  		Expect(err).To(BeNil())
   739  		s := specgen.NewSpecGenerator(alpine.name, false)
   740  		s.Terminal = true
   741  		s.Command = []string{"date", "-R"}
   742  		_, err = containers.CreateWithSpec(bt.conn, s)
   743  		Expect(err).To(BeNil())
   744  		// Validate list container with id filter
   745  		filters := make(map[string][]string)
   746  		filters["id"] = []string{cid}
   747  		c, err := containers.List(bt.conn, filters, bindings.PTrue, nil, nil, nil, nil)
   748  		Expect(err).To(BeNil())
   749  		Expect(len(c)).To(Equal(1))
   750  	})
   751  
   752  	It("List containers always includes pod information", func() {
   753  		podName := "testpod"
   754  		ctrName := "testctr"
   755  		bt.Podcreate(&podName)
   756  		_, err := bt.RunTopContainer(&ctrName, bindings.PTrue, &podName)
   757  		Expect(err).To(BeNil())
   758  
   759  		lastNum := 1
   760  
   761  		c, err := containers.List(bt.conn, nil, bindings.PTrue, &lastNum, nil, nil, nil)
   762  		Expect(err).To(BeNil())
   763  		Expect(len(c)).To(Equal(1))
   764  		Expect(c[0].PodName).To(Equal(podName))
   765  	})
   766  })