github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/integration-cli/docker_cli_search_test.go (about)

     1  package main
     2  
     3  import (
     4  	"os/exec"
     5  	"strings"
     6  
     7  	"github.com/go-check/check"
     8  )
     9  
    10  // search for repos named  "registry" on the central registry
    11  func (s *DockerSuite) TestSearchOnCentralRegistry(c *check.C) {
    12  	testRequires(c, Network)
    13  	searchCmd := exec.Command(dockerBinary, "search", "busybox")
    14  	out, exitCode, err := runCommandWithOutput(searchCmd)
    15  	if err != nil || exitCode != 0 {
    16  		c.Fatalf("failed to search on the central registry: %s, %v", out, err)
    17  	}
    18  
    19  	if !strings.Contains(out, "Busybox base image.") {
    20  		c.Fatal("couldn't find any repository named (or containing) 'Busybox base image.'")
    21  	}
    22  
    23  }
    24  
    25  func (s *DockerSuite) TestSearchStarsOptionWithWrongParameter(c *check.C) {
    26  	searchCmdStarsChars := exec.Command(dockerBinary, "search", "--stars=a", "busybox")
    27  	out, exitCode, err := runCommandWithOutput(searchCmdStarsChars)
    28  	if err == nil || exitCode == 0 {
    29  		c.Fatalf("Should not get right information: %s, %v", out, err)
    30  	}
    31  
    32  	if !strings.Contains(out, "invalid value") {
    33  		c.Fatal("couldn't find the invalid value warning")
    34  	}
    35  
    36  	searchCmdStarsNegativeNumber := exec.Command(dockerBinary, "search", "-s=-1", "busybox")
    37  	out, exitCode, err = runCommandWithOutput(searchCmdStarsNegativeNumber)
    38  	if err == nil || exitCode == 0 {
    39  		c.Fatalf("Should not get right information: %s, %v", out, err)
    40  	}
    41  
    42  	if !strings.Contains(out, "invalid value") {
    43  		c.Fatal("couldn't find the invalid value warning")
    44  	}
    45  
    46  }
    47  
    48  func (s *DockerSuite) TestSearchCmdOptions(c *check.C) {
    49  	testRequires(c, Network)
    50  	searchCmdhelp := exec.Command(dockerBinary, "search", "--help")
    51  	out, exitCode, err := runCommandWithOutput(searchCmdhelp)
    52  	if err != nil || exitCode != 0 {
    53  		c.Fatalf("failed to get search help information: %s, %v", out, err)
    54  	}
    55  
    56  	if !strings.Contains(out, "Usage: docker search [OPTIONS] TERM") {
    57  		c.Fatalf("failed to show docker search usage: %s, %v", out, err)
    58  	}
    59  
    60  	searchCmd := exec.Command(dockerBinary, "search", "busybox")
    61  	outSearchCmd, exitCode, err := runCommandWithOutput(searchCmd)
    62  	if err != nil || exitCode != 0 {
    63  		c.Fatalf("failed to search on the central registry: %s, %v", outSearchCmd, err)
    64  	}
    65  
    66  	searchCmdautomated := exec.Command(dockerBinary, "search", "--automated=true", "busybox")
    67  	outSearchCmdautomated, exitCode, err := runCommandWithOutput(searchCmdautomated) //The busybox is a busybox base image, not an AUTOMATED image.
    68  	if err != nil || exitCode != 0 {
    69  		c.Fatalf("failed to search with automated=true on the central registry: %s, %v", outSearchCmdautomated, err)
    70  	}
    71  
    72  	outSearchCmdautomatedSlice := strings.Split(outSearchCmdautomated, "\n")
    73  	for i := range outSearchCmdautomatedSlice {
    74  		if strings.HasPrefix(outSearchCmdautomatedSlice[i], "busybox ") {
    75  			c.Fatalf("The busybox is not an AUTOMATED image: %s, %v", out, err)
    76  		}
    77  	}
    78  
    79  	searchCmdStars := exec.Command(dockerBinary, "search", "-s=2", "busybox")
    80  	outSearchCmdStars, exitCode, err := runCommandWithOutput(searchCmdStars)
    81  	if err != nil || exitCode != 0 {
    82  		c.Fatalf("failed to search with stars=2 on the central registry: %s, %v", outSearchCmdStars, err)
    83  	}
    84  
    85  	if strings.Count(outSearchCmdStars, "[OK]") > strings.Count(outSearchCmd, "[OK]") {
    86  		c.Fatalf("The quantity of images with stars should be less than that of all images: %s, %v", outSearchCmdStars, err)
    87  	}
    88  
    89  	searchCmdOptions := exec.Command(dockerBinary, "search", "--stars=2", "--automated=true", "--no-trunc=true", "busybox")
    90  	out, exitCode, err = runCommandWithOutput(searchCmdOptions)
    91  	if err != nil || exitCode != 0 {
    92  		c.Fatalf("failed to search with stars&automated&no-trunc options on the central registry: %s, %v", out, err)
    93  	}
    94  
    95  }