docker_cli_search_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "os/exec"
  4. "strings"
  5. "testing"
  6. )
  7. // search for repos named "registry" on the central registry
  8. func TestSearchOnCentralRegistry(t *testing.T) {
  9. testRequires(t, Network)
  10. searchCmd := exec.Command(dockerBinary, "search", "busybox")
  11. out, exitCode, err := runCommandWithOutput(searchCmd)
  12. if err != nil || exitCode != 0 {
  13. t.Fatalf("failed to search on the central registry: %s, %v", out, err)
  14. }
  15. if !strings.Contains(out, "Busybox base image.") {
  16. t.Fatal("couldn't find any repository named (or containing) 'Busybox base image.'")
  17. }
  18. logDone("search - search for repositories named (or containing) 'Busybox base image.'")
  19. }
  20. func TestSearchStarsOptionWithWrongParameter(t *testing.T) {
  21. searchCmdStarsChars := exec.Command(dockerBinary, "search", "--stars=a", "busybox")
  22. out, exitCode, err := runCommandWithOutput(searchCmdStarsChars)
  23. if err == nil || exitCode == 0 {
  24. t.Fatalf("Should not get right information: %s, %v", out, err)
  25. }
  26. if !strings.Contains(out, "invalid value") {
  27. t.Fatal("couldn't find the invalid value warning")
  28. }
  29. searchCmdStarsNegativeNumber := exec.Command(dockerBinary, "search", "-s=-1", "busybox")
  30. out, exitCode, err = runCommandWithOutput(searchCmdStarsNegativeNumber)
  31. if err == nil || exitCode == 0 {
  32. t.Fatalf("Should not get right information: %s, %v", out, err)
  33. }
  34. if !strings.Contains(out, "invalid value") {
  35. t.Fatal("couldn't find the invalid value warning")
  36. }
  37. logDone("search - Verify search with wrong parameter.")
  38. }