2014-02-25 18:17:48 +02:00
package main
import (
2016-06-01 13:38:14 -07:00
"fmt"
2014-02-25 18:17:48 +02:00
"strings"
2015-04-18 09:46:47 -07:00
"github.com/go-check/check"
2019-04-04 15:23:19 +02:00
"gotest.tools/assert"
2014-02-25 18:17:48 +02:00
)
// search for repos named "registry" on the central registry
2015-04-18 09:46:47 -07:00
func ( s * DockerSuite ) TestSearchOnCentralRegistry ( c * check . C ) {
2015-08-28 10:36:42 -07:00
testRequires ( c , Network , DaemonIsLinux )
2015-07-22 02:01:24 +08:00
2015-10-05 12:01:58 +08:00
out , _ := dockerCmd ( c , "search" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . Assert ( c , strings . Contains ( out , "Busybox base image." ) , "couldn't find any repository named (or containing) 'Busybox base image.'" )
2014-02-25 18:17:48 +02:00
}
2015-04-03 08:55:08 +08:00
2015-04-18 09:46:47 -07:00
func ( s * DockerSuite ) TestSearchStarsOptionWithWrongParameter ( c * check . C ) {
2016-05-20 13:41:28 +02:00
out , _ , err := dockerCmdWithError ( "search" , "--filter" , "stars=a" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" , out )
assert . Assert ( c , strings . Contains ( out , "Invalid filter" ) , "couldn't find the invalid filter warning" )
2016-05-20 13:41:28 +02:00
out , _ , err = dockerCmdWithError ( "search" , "-f" , "stars=a" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" , out )
assert . Assert ( c , strings . Contains ( out , "Invalid filter" ) , "couldn't find the invalid filter warning" )
2016-05-20 13:41:28 +02:00
out , _ , err = dockerCmdWithError ( "search" , "-f" , "is-automated=a" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" , out )
assert . Assert ( c , strings . Contains ( out , "Invalid filter" ) , "couldn't find the invalid filter warning" )
2016-05-20 13:41:28 +02:00
out , _ , err = dockerCmdWithError ( "search" , "-f" , "is-official=a" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" , out )
assert . Assert ( c , strings . Contains ( out , "Invalid filter" ) , "couldn't find the invalid filter warning" )
2016-05-20 13:41:28 +02:00
// -s --stars deprecated since Docker 1.13
out , _ , err = dockerCmdWithError ( "search" , "--stars=a" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" , out )
assert . Assert ( c , strings . Contains ( out , "invalid syntax" ) , "couldn't find the invalid value warning" )
2015-04-03 08:55:08 +08:00
2016-05-20 13:41:28 +02:00
// -s --stars deprecated since Docker 1.13
2015-10-05 12:01:58 +08:00
out , _ , err = dockerCmdWithError ( "search" , "-s=-1" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" , out )
assert . Assert ( c , strings . Contains ( out , "invalid syntax" ) , "couldn't find the invalid value warning" )
2015-04-03 08:55:08 +08:00
}
2015-04-14 09:23:26 +08:00
2015-04-18 09:46:47 -07:00
func ( s * DockerSuite ) TestSearchCmdOptions ( c * check . C ) {
2016-05-20 13:41:28 +02:00
testRequires ( c , Network , DaemonIsLinux )
2015-07-22 02:01:24 +08:00
2015-10-05 12:01:58 +08:00
out , _ := dockerCmd ( c , "search" , "--help" )
2019-04-04 15:23:19 +02:00
assert . Assert ( c , strings . Contains ( out , "Usage:\tdocker search [OPTIONS] TERM" ) )
2015-04-14 09:23:26 +08:00
2015-10-05 12:01:58 +08:00
outSearchCmd , _ := dockerCmd ( c , "search" , "busybox" )
2015-07-22 02:01:24 +08:00
outSearchCmdNotrunc , _ := dockerCmd ( c , "search" , "--no-trunc=true" , "busybox" )
2016-05-20 13:41:28 +02:00
2019-04-04 15:23:19 +02:00
assert . Assert ( c , len ( outSearchCmd ) <= len ( outSearchCmdNotrunc ) , "The no-trunc option can't take effect." )
2015-05-05 08:51:13 +08:00
2016-05-20 13:41:28 +02:00
outSearchCmdautomated , _ := dockerCmd ( c , "search" , "--filter" , "is-automated=true" , "busybox" ) //The busybox is a busybox base image, not an AUTOMATED image.
2015-04-14 09:23:26 +08:00
outSearchCmdautomatedSlice := strings . Split ( outSearchCmdautomated , "\n" )
for i := range outSearchCmdautomatedSlice {
2019-04-04 15:23:19 +02:00
assert . Assert ( c , ! strings . HasPrefix ( outSearchCmdautomatedSlice [ i ] , "busybox " ) , "The busybox is not an AUTOMATED image: %s" , outSearchCmdautomated )
2016-05-20 13:41:28 +02:00
}
outSearchCmdNotOfficial , _ := dockerCmd ( c , "search" , "--filter" , "is-official=false" , "busybox" ) //The busybox is a busybox base image, official image.
outSearchCmdNotOfficialSlice := strings . Split ( outSearchCmdNotOfficial , "\n" )
for i := range outSearchCmdNotOfficialSlice {
2019-04-04 15:23:19 +02:00
assert . Assert ( c , ! strings . HasPrefix ( outSearchCmdNotOfficialSlice [ i ] , "busybox " ) , "The busybox is not an OFFICIAL image: %s" , outSearchCmdNotOfficial )
2015-04-14 09:23:26 +08:00
}
2016-05-20 13:41:28 +02:00
outSearchCmdOfficial , _ := dockerCmd ( c , "search" , "--filter" , "is-official=true" , "busybox" ) //The busybox is a busybox base image, official image.
outSearchCmdOfficialSlice := strings . Split ( outSearchCmdOfficial , "\n" )
2019-04-04 15:23:19 +02:00
assert . Equal ( c , len ( outSearchCmdOfficialSlice ) , 3 ) // 1 header, 1 line, 1 carriage return
assert . Assert ( c , strings . HasPrefix ( outSearchCmdOfficialSlice [ 1 ] , "busybox " ) , "The busybox is an OFFICIAL image: %s" , outSearchCmdOfficial )
2016-05-20 13:41:28 +02:00
outSearchCmdStars , _ := dockerCmd ( c , "search" , "--filter" , "stars=2" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . Assert ( c , strings . Count ( outSearchCmdStars , "[OK]" ) <= strings . Count ( outSearchCmd , "[OK]" ) , "The quantity of images with stars should be less than that of all images: %s" , outSearchCmdStars )
2015-04-14 09:23:26 +08:00
2016-05-20 13:41:28 +02:00
dockerCmd ( c , "search" , "--filter" , "is-automated=true" , "--filter" , "stars=2" , "--no-trunc=true" , "busybox" )
// --automated deprecated since Docker 1.13
outSearchCmdautomated1 , _ := dockerCmd ( c , "search" , "--automated=true" , "busybox" ) //The busybox is a busybox base image, not an AUTOMATED image.
outSearchCmdautomatedSlice1 := strings . Split ( outSearchCmdautomated1 , "\n" )
for i := range outSearchCmdautomatedSlice1 {
2019-04-04 15:23:19 +02:00
assert . Assert ( c , ! strings . HasPrefix ( outSearchCmdautomatedSlice1 [ i ] , "busybox " ) , "The busybox is not an AUTOMATED image: %s" , outSearchCmdautomated )
2016-05-20 13:41:28 +02:00
}
// -s --stars deprecated since Docker 1.13
outSearchCmdStars1 , _ := dockerCmd ( c , "search" , "--stars=2" , "busybox" )
2019-04-04 15:23:19 +02:00
assert . Assert ( c , strings . Count ( outSearchCmdStars1 , "[OK]" ) <= strings . Count ( outSearchCmd , "[OK]" ) , "The quantity of images with stars should be less than that of all images: %s" , outSearchCmdStars1 )
2016-05-20 13:41:28 +02:00
// -s --stars deprecated since Docker 1.13
2015-10-05 12:01:58 +08:00
dockerCmd ( c , "search" , "--stars=2" , "--automated=true" , "--no-trunc=true" , "busybox" )
2015-04-14 09:23:26 +08:00
}
2015-09-22 19:44:40 +08: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 12:01:58 +08:00
dockerCmd ( c , "search" , "ubuntu-" )
2015-09-22 19:44:40 +08:00
}
2016-06-01 13:38:14 -07:00
// test case for #23055
func ( s * DockerSuite ) TestSearchWithLimit ( c * check . C ) {
testRequires ( c , Network , DaemonIsLinux )
limit := 10
out , _ , err := dockerCmdWithError ( "search" , fmt . Sprintf ( "--limit=%d" , limit ) , "docker" )
2019-04-04 15:23:19 +02:00
assert . NilError ( c , err )
2016-06-01 13:38:14 -07:00
outSlice := strings . Split ( out , "\n" )
2019-04-04 15:23:19 +02:00
assert . Equal ( c , len ( outSlice ) , limit + 2 ) // 1 header, 1 carriage return
2016-06-01 13:38:14 -07:00
limit = 50
out , _ , err = dockerCmdWithError ( "search" , fmt . Sprintf ( "--limit=%d" , limit ) , "docker" )
2019-04-04 15:23:19 +02:00
assert . NilError ( c , err )
2016-06-01 13:38:14 -07:00
outSlice = strings . Split ( out , "\n" )
2019-04-04 15:23:19 +02:00
assert . Equal ( c , len ( outSlice ) , limit + 2 ) // 1 header, 1 carriage return
2016-06-01 13:38:14 -07:00
limit = 100
out , _ , err = dockerCmdWithError ( "search" , fmt . Sprintf ( "--limit=%d" , limit ) , "docker" )
2019-04-04 15:23:19 +02:00
assert . NilError ( c , err )
2016-06-01 13:38:14 -07:00
outSlice = strings . Split ( out , "\n" )
2019-04-04 15:23:19 +02:00
assert . Equal ( c , len ( outSlice ) , limit + 2 ) // 1 header, 1 carriage return
2016-06-01 13:38:14 -07:00
limit = 0
2017-01-18 03:08:31 +01:00
_ , _ , err = dockerCmdWithError ( "search" , fmt . Sprintf ( "--limit=%d" , limit ) , "docker" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" )
2016-06-01 13:38:14 -07:00
limit = 200
2017-01-18 03:08:31 +01:00
_ , _ , err = dockerCmdWithError ( "search" , fmt . Sprintf ( "--limit=%d" , limit ) , "docker" )
2019-04-04 15:23:19 +02:00
assert . ErrorContains ( c , err , "" )
2016-06-01 13:38:14 -07:00
}