2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// search for repos named "registry" on the central registry
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
2014-08-19 12:52:46 -04:00
|
|
|
searchCmd := exec.Command(dockerBinary, "search", "busybox")
|
2014-02-25 11:17:48 -05:00
|
|
|
out, exitCode, err := runCommandWithOutput(searchCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to search on the central registry: %s, %v", out, err)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
|
2014-06-24 17:16:34 -04:00
|
|
|
if !strings.Contains(out, "Busybox base image.") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("couldn't find any repository named (or containing) 'Busybox base image.'")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-04-02 20:55:08 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
|
2015-04-02 20:55:08 -04:00
|
|
|
searchCmdStarsChars := exec.Command(dockerBinary, "search", "--stars=a", "busybox")
|
|
|
|
out, exitCode, err := runCommandWithOutput(searchCmdStarsChars)
|
|
|
|
if err == nil || exitCode == 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Should not get right information: %s, %v", out, err)
|
2015-04-02 20:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(out, "invalid value") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("couldn't find the invalid value warning")
|
2015-04-02 20:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
searchCmdStarsNegativeNumber := exec.Command(dockerBinary, "search", "-s=-1", "busybox")
|
|
|
|
out, exitCode, err = runCommandWithOutput(searchCmdStarsNegativeNumber)
|
|
|
|
if err == nil || exitCode == 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Should not get right information: %s, %v", out, err)
|
2015-04-02 20:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(out, "invalid value") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("couldn't find the invalid value warning")
|
2015-04-02 20:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-04-13 21:23:26 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
2015-04-13 21:23:26 -04:00
|
|
|
searchCmdhelp := exec.Command(dockerBinary, "search", "--help")
|
|
|
|
out, exitCode, err := runCommandWithOutput(searchCmdhelp)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to get search help information: %s, %v", out, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
2015-05-13 22:45:01 -04:00
|
|
|
if !strings.Contains(out, "Usage:\tdocker search [OPTIONS] TERM") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to show docker search usage: %s, %v", out, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
searchCmd := exec.Command(dockerBinary, "search", "busybox")
|
|
|
|
outSearchCmd, exitCode, err := runCommandWithOutput(searchCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to search on the central registry: %s, %v", outSearchCmd, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
2015-05-04 20:51:13 -04:00
|
|
|
searchCmdNotrunc := exec.Command(dockerBinary, "search", "--no-trunc=true", "busybox")
|
|
|
|
outSearchCmdNotrunc, _, err := runCommandWithOutput(searchCmdNotrunc)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("failed to search on the central registry: %s, %v", outSearchCmdNotrunc, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(outSearchCmd) > len(outSearchCmdNotrunc) {
|
|
|
|
c.Fatalf("The no-trunc option can't take effect.")
|
|
|
|
}
|
|
|
|
|
2015-04-13 21:23:26 -04:00
|
|
|
searchCmdautomated := exec.Command(dockerBinary, "search", "--automated=true", "busybox")
|
|
|
|
outSearchCmdautomated, exitCode, err := runCommandWithOutput(searchCmdautomated) //The busybox is a busybox base image, not an AUTOMATED image.
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to search with automated=true on the central registry: %s, %v", outSearchCmdautomated, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
|
|
|
|
for i := range outSearchCmdautomatedSlice {
|
|
|
|
if strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox ") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("The busybox is not an AUTOMATED image: %s, %v", out, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
searchCmdStars := exec.Command(dockerBinary, "search", "-s=2", "busybox")
|
|
|
|
outSearchCmdStars, exitCode, err := runCommandWithOutput(searchCmdStars)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to search with stars=2 on the central registry: %s, %v", outSearchCmdStars, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("The quantity of images with stars should be less than that of all images: %s, %v", outSearchCmdStars, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
searchCmdOptions := exec.Command(dockerBinary, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
|
|
|
|
out, exitCode, err = runCommandWithOutput(searchCmdOptions)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to search with stars&automated&no-trunc options on the central registry: %s, %v", out, err)
|
2015-04-13 21:23:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|