2014-02-25 11:17:48 -05:00
package main
import (
"strings"
2015-04-18 12:46:47 -04:00
2015-10-05 00:01:58 -04:00
"github.com/docker/docker/pkg/integration/checker"
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 ) {
2015-08-28 13:36:42 -04:00
testRequires ( c , Network , DaemonIsLinux )
2015-07-21 14:01:24 -04:00
2015-10-05 00:01:58 -04:00
out , _ := dockerCmd ( c , "search" , "busybox" )
c . Assert ( out , checker . Contains , "Busybox base image." , check . Commentf ( "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-10-05 00:01:58 -04:00
out , _ , err := dockerCmdWithError ( "search" , "--stars=a" , "busybox" )
c . Assert ( err , check . NotNil , check . Commentf ( out ) )
c . Assert ( out , checker . Contains , "invalid value" , check . Commentf ( "couldn't find the invalid value warning" ) )
2015-04-02 20:55:08 -04:00
2015-10-05 00:01:58 -04:00
out , _ , err = dockerCmdWithError ( "search" , "-s=-1" , "busybox" )
c . Assert ( err , check . NotNil , check . Commentf ( out ) )
c . Assert ( out , checker . Contains , "invalid value" , check . Commentf ( "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-07-21 14:01:24 -04:00
2015-10-05 00:01:58 -04:00
out , _ := dockerCmd ( c , "search" , "--help" )
c . Assert ( out , checker . Contains , "Usage:\tdocker search [OPTIONS] TERM" )
2015-04-13 21:23:26 -04:00
2015-10-05 00:01:58 -04:00
outSearchCmd , _ := dockerCmd ( c , "search" , "busybox" )
2015-07-21 14:01:24 -04:00
outSearchCmdNotrunc , _ := dockerCmd ( c , "search" , "--no-trunc=true" , "busybox" )
2015-10-05 00:01:58 -04:00
c . Assert ( len ( outSearchCmd ) > len ( outSearchCmdNotrunc ) , check . Equals , false , check . Commentf ( "The no-trunc option can't take effect." ) )
2015-05-04 20:51:13 -04:00
2015-10-05 00:01:58 -04:00
outSearchCmdautomated , _ := dockerCmd ( c , "search" , "--automated=true" , "busybox" ) //The busybox is a busybox base image, not an AUTOMATED image.
2015-04-13 21:23:26 -04:00
outSearchCmdautomatedSlice := strings . Split ( outSearchCmdautomated , "\n" )
for i := range outSearchCmdautomatedSlice {
2015-10-05 00:01:58 -04:00
c . Assert ( strings . HasPrefix ( outSearchCmdautomatedSlice [ i ] , "busybox " ) , check . Equals , false , check . Commentf ( "The busybox is not an AUTOMATED image: %s" , out ) )
2015-04-13 21:23:26 -04:00
}
2015-10-05 00:01:58 -04:00
outSearchCmdStars , _ := dockerCmd ( c , "search" , "-s=2" , "busybox" )
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 ) )
2015-04-13 21:23:26 -04:00
2015-10-05 00:01:58 -04:00
dockerCmd ( c , "search" , "--stars=2" , "--automated=true" , "--no-trunc=true" , "busybox" )
2015-04-13 21:23:26 -04:00
}
2015-09-22 07:44:40 -04:00
// search for repos which start with "ubuntu-" on the central registry
func ( s * DockerSuite ) TestSearchOnCentralRegistryWithDash ( c * check . C ) {
testRequires ( c , Network , DaemonIsLinux )
2015-10-05 00:01:58 -04:00
dockerCmd ( c , "search" , "ubuntu-" )
2015-09-22 07:44:40 -04:00
}