github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/integration-cli/docker_cli_search_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/docker/docker/pkg/integration/checker"
     8  	"github.com/go-check/check"
     9  )
    10  
    11  // search for repos named  "registry" on the central registry
    12  func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
    13  	testRequires(c, Network, DaemonIsLinux)
    14  
    15  	out, _ := dockerCmd(c, "search", "busybox")
    16  	c.Assert(out, checker.Contains, "Busybox base image.", check.Commentf("couldn't find any repository named (or containing) 'Busybox base image.'"))
    17  }
    18  
    19  func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
    20  	out, _, err := dockerCmdWithError("search", "--filter", "stars=a", "busybox")
    21  	c.Assert(err, check.NotNil, check.Commentf(out))
    22  	c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
    23  
    24  	out, _, err = dockerCmdWithError("search", "-f", "stars=a", "busybox")
    25  	c.Assert(err, check.NotNil, check.Commentf(out))
    26  	c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
    27  
    28  	out, _, err = dockerCmdWithError("search", "-f", "is-automated=a", "busybox")
    29  	c.Assert(err, check.NotNil, check.Commentf(out))
    30  	c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
    31  
    32  	out, _, err = dockerCmdWithError("search", "-f", "is-official=a", "busybox")
    33  	c.Assert(err, check.NotNil, check.Commentf(out))
    34  	c.Assert(out, checker.Contains, "Invalid filter", check.Commentf("couldn't find the invalid filter warning"))
    35  
    36  	// -s --stars deprecated since Docker 1.13
    37  	out, _, err = dockerCmdWithError("search", "--stars=a", "busybox")
    38  	c.Assert(err, check.NotNil, check.Commentf(out))
    39  	c.Assert(out, checker.Contains, "invalid syntax", check.Commentf("couldn't find the invalid value warning"))
    40  
    41  	// -s --stars deprecated since Docker 1.13
    42  	out, _, err = dockerCmdWithError("search", "-s=-1", "busybox")
    43  	c.Assert(err, check.NotNil, check.Commentf(out))
    44  	c.Assert(out, checker.Contains, "invalid syntax", check.Commentf("couldn't find the invalid value warning"))
    45  }
    46  
    47  func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
    48  	testRequires(c, Network, DaemonIsLinux)
    49  
    50  	out, _ := dockerCmd(c, "search", "--help")
    51  	c.Assert(out, checker.Contains, "Usage:\tdocker search [OPTIONS] TERM")
    52  
    53  	outSearchCmd, _ := dockerCmd(c, "search", "busybox")
    54  	outSearchCmdNotrunc, _ := dockerCmd(c, "search", "--no-trunc=true", "busybox")
    55  
    56  	c.Assert(len(outSearchCmd) > len(outSearchCmdNotrunc), check.Equals, false, check.Commentf("The no-trunc option can't take effect."))
    57  
    58  	outSearchCmdautomated, _ := dockerCmd(c, "search", "--filter", "is-automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
    59  	outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
    60  	for i := range outSearchCmdautomatedSlice {
    61  		c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", outSearchCmdautomated))
    62  	}
    63  
    64  	outSearchCmdNotOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=false", "busybox") //The busybox is a busybox base image, official image.
    65  	outSearchCmdNotOfficialSlice := strings.Split(outSearchCmdNotOfficial, "\n")
    66  	for i := range outSearchCmdNotOfficialSlice {
    67  		c.Assert(strings.HasPrefix(outSearchCmdNotOfficialSlice[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an OFFICIAL image: %s", outSearchCmdNotOfficial))
    68  	}
    69  
    70  	outSearchCmdOfficial, _ := dockerCmd(c, "search", "--filter", "is-official=true", "busybox") //The busybox is a busybox base image, official image.
    71  	outSearchCmdOfficialSlice := strings.Split(outSearchCmdOfficial, "\n")
    72  	c.Assert(outSearchCmdOfficialSlice, checker.HasLen, 3) // 1 header, 1 line, 1 carriage return
    73  	c.Assert(strings.HasPrefix(outSearchCmdOfficialSlice[1], "busybox "), check.Equals, true, check.Commentf("The busybox is an OFFICIAL image: %s", outSearchCmdNotOfficial))
    74  
    75  	outSearchCmdStars, _ := dockerCmd(c, "search", "--filter", "stars=2", "busybox")
    76  	c.Assert(strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]"), check.Equals, false, check.Commentf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars))
    77  
    78  	dockerCmd(c, "search", "--filter", "is-automated=true", "--filter", "stars=2", "--no-trunc=true", "busybox")
    79  
    80  	// --automated deprecated since Docker 1.13
    81  	outSearchCmdautomated1, _ := dockerCmd(c, "search", "--automated=true", "busybox") //The busybox is a busybox base image, not an AUTOMATED image.
    82  	outSearchCmdautomatedSlice1 := strings.Split(outSearchCmdautomated1, "\n")
    83  	for i := range outSearchCmdautomatedSlice1 {
    84  		c.Assert(strings.HasPrefix(outSearchCmdautomatedSlice1[i], "busybox "), check.Equals, false, check.Commentf("The busybox is not an AUTOMATED image: %s", outSearchCmdautomated))
    85  	}
    86  
    87  	// -s --stars deprecated since Docker 1.13
    88  	outSearchCmdStars1, _ := dockerCmd(c, "search", "--stars=2", "busybox")
    89  	c.Assert(strings.Count(outSearchCmdStars1, "[OK]") > strings.Count(outSearchCmd, "[OK]"), check.Equals, false, check.Commentf("The quantity of images with stars should be less than that of all images: %s", outSearchCmdStars1))
    90  
    91  	// -s --stars deprecated since Docker 1.13
    92  	dockerCmd(c, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
    93  }
    94  
    95  // search for repos which start with "ubuntu-" on the central registry
    96  func (s *DockerSuite) TestSearchOnCentralRegistryWithDash(c *check.C) {
    97  	testRequires(c, Network, DaemonIsLinux)
    98  
    99  	dockerCmd(c, "search", "ubuntu-")
   100  }
   101  
   102  // test case for #23055
   103  func (s *DockerSuite) TestSearchWithLimit(c *check.C) {
   104  	testRequires(c, Network, DaemonIsLinux)
   105  
   106  	limit := 10
   107  	out, _, err := dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
   108  	c.Assert(err, checker.IsNil)
   109  	outSlice := strings.Split(out, "\n")
   110  	c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
   111  
   112  	limit = 50
   113  	out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
   114  	c.Assert(err, checker.IsNil)
   115  	outSlice = strings.Split(out, "\n")
   116  	c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
   117  
   118  	limit = 100
   119  	out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
   120  	c.Assert(err, checker.IsNil)
   121  	outSlice = strings.Split(out, "\n")
   122  	c.Assert(outSlice, checker.HasLen, limit+2) // 1 header, 1 carriage return
   123  
   124  	limit = 0
   125  	out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
   126  	c.Assert(err, checker.Not(checker.IsNil))
   127  
   128  	limit = 200
   129  	out, _, err = dockerCmdWithError("search", fmt.Sprintf("--limit=%d", limit), "docker")
   130  	c.Assert(err, checker.Not(checker.IsNil))
   131  }