docker_utils_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. package main
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "io"
  7. "io/ioutil"
  8. "net/http"
  9. "net/http/httptest"
  10. "os"
  11. "os/exec"
  12. "path"
  13. "path/filepath"
  14. "strconv"
  15. "strings"
  16. "time"
  17. "github.com/docker/docker/api/types"
  18. "github.com/docker/docker/integration-cli/checker"
  19. "github.com/docker/docker/integration-cli/cli"
  20. "github.com/docker/docker/integration-cli/cli/build/fakecontext"
  21. "github.com/docker/docker/integration-cli/cli/build/fakestorage"
  22. "github.com/docker/docker/integration-cli/daemon"
  23. "github.com/docker/docker/integration-cli/registry"
  24. "github.com/docker/docker/integration-cli/request"
  25. icmd "github.com/docker/docker/pkg/testutil/cmd"
  26. "github.com/go-check/check"
  27. )
  28. // Deprecated
  29. func daemonHost() string {
  30. return request.DaemonHost()
  31. }
  32. // FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool
  33. func deleteContainer(container ...string) error {
  34. return icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...).Compare(icmd.Success)
  35. }
  36. func getAllContainers(c *check.C) string {
  37. result := icmd.RunCommand(dockerBinary, "ps", "-q", "-a")
  38. result.Assert(c, icmd.Success)
  39. return result.Combined()
  40. }
  41. // Deprecated
  42. func deleteAllContainers(c *check.C) {
  43. containers := getAllContainers(c)
  44. if containers != "" {
  45. err := deleteContainer(strings.Split(strings.TrimSpace(containers), "\n")...)
  46. c.Assert(err, checker.IsNil)
  47. }
  48. }
  49. func getPausedContainers(c *check.C) []string {
  50. result := icmd.RunCommand(dockerBinary, "ps", "-f", "status=paused", "-q", "-a")
  51. result.Assert(c, icmd.Success)
  52. return strings.Fields(result.Combined())
  53. }
  54. func unpauseContainer(c *check.C, container string) {
  55. dockerCmd(c, "unpause", container)
  56. }
  57. // Deprecated
  58. func unpauseAllContainers(c *check.C) {
  59. containers := getPausedContainers(c)
  60. for _, value := range containers {
  61. unpauseContainer(c, value)
  62. }
  63. }
  64. func deleteImages(images ...string) error {
  65. args := []string{dockerBinary, "rmi", "-f"}
  66. return icmd.RunCmd(icmd.Cmd{Command: append(args, images...)}).Error
  67. }
  68. // Deprecated: use cli.Docker or cli.DockerCmd
  69. func dockerCmdWithError(args ...string) (string, int, error) {
  70. result := cli.Docker(cli.Args(args...))
  71. if result.Error != nil {
  72. return result.Combined(), result.ExitCode, result.Compare(icmd.Success)
  73. }
  74. return result.Combined(), result.ExitCode, result.Error
  75. }
  76. // Deprecated: use cli.Docker or cli.DockerCmd
  77. func dockerCmd(c *check.C, args ...string) (string, int) {
  78. result := cli.DockerCmd(c, args...)
  79. return result.Combined(), result.ExitCode
  80. }
  81. // Deprecated: use cli.Docker or cli.DockerCmd
  82. func dockerCmdWithResult(args ...string) *icmd.Result {
  83. return cli.Docker(cli.Args(args...))
  84. }
  85. func findContainerIP(c *check.C, id string, network string) string {
  86. out, _ := dockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id)
  87. return strings.Trim(out, " \r\n'")
  88. }
  89. func getContainerCount(c *check.C) int {
  90. const containers = "Containers:"
  91. result := icmd.RunCommand(dockerBinary, "info")
  92. result.Assert(c, icmd.Success)
  93. lines := strings.Split(result.Combined(), "\n")
  94. for _, line := range lines {
  95. if strings.Contains(line, containers) {
  96. output := strings.TrimSpace(line)
  97. output = strings.TrimLeft(output, containers)
  98. output = strings.Trim(output, " ")
  99. containerCount, err := strconv.Atoi(output)
  100. c.Assert(err, checker.IsNil)
  101. return containerCount
  102. }
  103. }
  104. return 0
  105. }
  106. func inspectFieldAndUnmarshall(c *check.C, name, field string, output interface{}) {
  107. str := inspectFieldJSON(c, name, field)
  108. err := json.Unmarshal([]byte(str), output)
  109. if c != nil {
  110. c.Assert(err, check.IsNil, check.Commentf("failed to unmarshal: %v", err))
  111. }
  112. }
  113. // Deprecated: use cli.Inspect
  114. func inspectFilter(name, filter string) (string, error) {
  115. format := fmt.Sprintf("{{%s}}", filter)
  116. result := icmd.RunCommand(dockerBinary, "inspect", "-f", format, name)
  117. if result.Error != nil || result.ExitCode != 0 {
  118. return "", fmt.Errorf("failed to inspect %s: %s", name, result.Combined())
  119. }
  120. return strings.TrimSpace(result.Combined()), nil
  121. }
  122. // Deprecated: use cli.Inspect
  123. func inspectFieldWithError(name, field string) (string, error) {
  124. return inspectFilter(name, fmt.Sprintf(".%s", field))
  125. }
  126. // Deprecated: use cli.Inspect
  127. func inspectField(c *check.C, name, field string) string {
  128. out, err := inspectFilter(name, fmt.Sprintf(".%s", field))
  129. if c != nil {
  130. c.Assert(err, check.IsNil)
  131. }
  132. return out
  133. }
  134. // Deprecated: use cli.Inspect
  135. func inspectFieldJSON(c *check.C, name, field string) string {
  136. out, err := inspectFilter(name, fmt.Sprintf("json .%s", field))
  137. if c != nil {
  138. c.Assert(err, check.IsNil)
  139. }
  140. return out
  141. }
  142. // Deprecated: use cli.Inspect
  143. func inspectFieldMap(c *check.C, name, path, field string) string {
  144. out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field))
  145. if c != nil {
  146. c.Assert(err, check.IsNil)
  147. }
  148. return out
  149. }
  150. // Deprecated: use cli.Inspect
  151. func inspectMountSourceField(name, destination string) (string, error) {
  152. m, err := inspectMountPoint(name, destination)
  153. if err != nil {
  154. return "", err
  155. }
  156. return m.Source, nil
  157. }
  158. // Deprecated: use cli.Inspect
  159. func inspectMountPoint(name, destination string) (types.MountPoint, error) {
  160. out, err := inspectFilter(name, "json .Mounts")
  161. if err != nil {
  162. return types.MountPoint{}, err
  163. }
  164. return inspectMountPointJSON(out, destination)
  165. }
  166. var errMountNotFound = errors.New("mount point not found")
  167. // Deprecated: use cli.Inspect
  168. func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
  169. var mp []types.MountPoint
  170. if err := json.Unmarshal([]byte(j), &mp); err != nil {
  171. return types.MountPoint{}, err
  172. }
  173. var m *types.MountPoint
  174. for _, c := range mp {
  175. if c.Destination == destination {
  176. m = &c
  177. break
  178. }
  179. }
  180. if m == nil {
  181. return types.MountPoint{}, errMountNotFound
  182. }
  183. return *m, nil
  184. }
  185. // Deprecated: use cli.Inspect
  186. func inspectImage(c *check.C, name, filter string) string {
  187. args := []string{"inspect", "--type", "image"}
  188. if filter != "" {
  189. format := fmt.Sprintf("{{%s}}", filter)
  190. args = append(args, "-f", format)
  191. }
  192. args = append(args, name)
  193. result := icmd.RunCommand(dockerBinary, args...)
  194. result.Assert(c, icmd.Success)
  195. return strings.TrimSpace(result.Combined())
  196. }
  197. func getIDByName(c *check.C, name string) string {
  198. id, err := inspectFieldWithError(name, "Id")
  199. c.Assert(err, checker.IsNil)
  200. return id
  201. }
  202. // Deprecated: use cli.Build
  203. func buildImageSuccessfully(c *check.C, name string, cmdOperators ...cli.CmdOperator) {
  204. buildImage(name, cmdOperators...).Assert(c, icmd.Success)
  205. }
  206. // Deprecated: use cli.Build
  207. func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result {
  208. return cli.Docker(cli.Build(name), cmdOperators...)
  209. }
  210. // Deprecated: use trustedcmd
  211. func trustedBuild(cmd *icmd.Cmd) func() {
  212. trustedCmd(cmd)
  213. return nil
  214. }
  215. type gitServer interface {
  216. URL() string
  217. Close() error
  218. }
  219. type localGitServer struct {
  220. *httptest.Server
  221. }
  222. func (r *localGitServer) Close() error {
  223. r.Server.Close()
  224. return nil
  225. }
  226. func (r *localGitServer) URL() string {
  227. return r.Server.URL
  228. }
  229. type fakeGit struct {
  230. root string
  231. server gitServer
  232. RepoURL string
  233. }
  234. func (g *fakeGit) Close() {
  235. g.server.Close()
  236. os.RemoveAll(g.root)
  237. }
  238. func newFakeGit(c *check.C, name string, files map[string]string, enforceLocalServer bool) *fakeGit {
  239. ctx := fakecontext.New(c, "", fakecontext.WithFiles(files))
  240. defer ctx.Close()
  241. curdir, err := os.Getwd()
  242. if err != nil {
  243. c.Fatal(err)
  244. }
  245. defer os.Chdir(curdir)
  246. if output, err := exec.Command("git", "init", ctx.Dir).CombinedOutput(); err != nil {
  247. c.Fatalf("error trying to init repo: %s (%s)", err, output)
  248. }
  249. err = os.Chdir(ctx.Dir)
  250. if err != nil {
  251. c.Fatal(err)
  252. }
  253. if output, err := exec.Command("git", "config", "user.name", "Fake User").CombinedOutput(); err != nil {
  254. c.Fatalf("error trying to set 'user.name': %s (%s)", err, output)
  255. }
  256. if output, err := exec.Command("git", "config", "user.email", "fake.user@example.com").CombinedOutput(); err != nil {
  257. c.Fatalf("error trying to set 'user.email': %s (%s)", err, output)
  258. }
  259. if output, err := exec.Command("git", "add", "*").CombinedOutput(); err != nil {
  260. c.Fatalf("error trying to add files to repo: %s (%s)", err, output)
  261. }
  262. if output, err := exec.Command("git", "commit", "-a", "-m", "Initial commit").CombinedOutput(); err != nil {
  263. c.Fatalf("error trying to commit to repo: %s (%s)", err, output)
  264. }
  265. root, err := ioutil.TempDir("", "docker-test-git-repo")
  266. if err != nil {
  267. c.Fatal(err)
  268. }
  269. repoPath := filepath.Join(root, name+".git")
  270. if output, err := exec.Command("git", "clone", "--bare", ctx.Dir, repoPath).CombinedOutput(); err != nil {
  271. os.RemoveAll(root)
  272. c.Fatalf("error trying to clone --bare: %s (%s)", err, output)
  273. }
  274. err = os.Chdir(repoPath)
  275. if err != nil {
  276. os.RemoveAll(root)
  277. c.Fatal(err)
  278. }
  279. if output, err := exec.Command("git", "update-server-info").CombinedOutput(); err != nil {
  280. os.RemoveAll(root)
  281. c.Fatalf("error trying to git update-server-info: %s (%s)", err, output)
  282. }
  283. err = os.Chdir(curdir)
  284. if err != nil {
  285. os.RemoveAll(root)
  286. c.Fatal(err)
  287. }
  288. var server gitServer
  289. if !enforceLocalServer {
  290. // use fakeStorage server, which might be local or remote (at test daemon)
  291. server = fakestorage.New(c, root)
  292. } else {
  293. // always start a local http server on CLI test machine
  294. httpServer := httptest.NewServer(http.FileServer(http.Dir(root)))
  295. server = &localGitServer{httpServer}
  296. }
  297. return &fakeGit{
  298. root: root,
  299. server: server,
  300. RepoURL: fmt.Sprintf("%s/%s.git", server.URL(), name),
  301. }
  302. }
  303. // Write `content` to the file at path `dst`, creating it if necessary,
  304. // as well as any missing directories.
  305. // The file is truncated if it already exists.
  306. // Fail the test when error occurs.
  307. func writeFile(dst, content string, c *check.C) {
  308. // Create subdirectories if necessary
  309. c.Assert(os.MkdirAll(path.Dir(dst), 0700), check.IsNil)
  310. f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700)
  311. c.Assert(err, check.IsNil)
  312. defer f.Close()
  313. // Write content (truncate if it exists)
  314. _, err = io.Copy(f, strings.NewReader(content))
  315. c.Assert(err, check.IsNil)
  316. }
  317. // Return the contents of file at path `src`.
  318. // Fail the test when error occurs.
  319. func readFile(src string, c *check.C) (content string) {
  320. data, err := ioutil.ReadFile(src)
  321. c.Assert(err, check.IsNil)
  322. return string(data)
  323. }
  324. func containerStorageFile(containerID, basename string) string {
  325. return filepath.Join(testEnv.ContainerStoragePath(), containerID, basename)
  326. }
  327. // docker commands that use this function must be run with the '-d' switch.
  328. func runCommandAndReadContainerFile(c *check.C, filename string, command string, args ...string) []byte {
  329. result := icmd.RunCommand(command, args...)
  330. result.Assert(c, icmd.Success)
  331. contID := strings.TrimSpace(result.Combined())
  332. if err := waitRun(contID); err != nil {
  333. c.Fatalf("%v: %q", contID, err)
  334. }
  335. return readContainerFile(c, contID, filename)
  336. }
  337. func readContainerFile(c *check.C, containerID, filename string) []byte {
  338. f, err := os.Open(containerStorageFile(containerID, filename))
  339. c.Assert(err, checker.IsNil)
  340. defer f.Close()
  341. content, err := ioutil.ReadAll(f)
  342. c.Assert(err, checker.IsNil)
  343. return content
  344. }
  345. func readContainerFileWithExec(c *check.C, containerID, filename string) []byte {
  346. result := icmd.RunCommand(dockerBinary, "exec", containerID, "cat", filename)
  347. result.Assert(c, icmd.Success)
  348. return []byte(result.Combined())
  349. }
  350. // daemonTime provides the current time on the daemon host
  351. func daemonTime(c *check.C) time.Time {
  352. if testEnv.LocalDaemon() {
  353. return time.Now()
  354. }
  355. status, body, err := request.SockRequest("GET", "/info", nil, daemonHost())
  356. c.Assert(err, check.IsNil)
  357. c.Assert(status, check.Equals, http.StatusOK)
  358. type infoJSON struct {
  359. SystemTime string
  360. }
  361. var info infoJSON
  362. err = json.Unmarshal(body, &info)
  363. c.Assert(err, check.IsNil, check.Commentf("unable to unmarshal GET /info response"))
  364. dt, err := time.Parse(time.RFC3339Nano, info.SystemTime)
  365. c.Assert(err, check.IsNil, check.Commentf("invalid time format in GET /info response"))
  366. return dt
  367. }
  368. // daemonUnixTime returns the current time on the daemon host with nanoseconds precision.
  369. // It return the time formatted how the client sends timestamps to the server.
  370. func daemonUnixTime(c *check.C) string {
  371. return parseEventTime(daemonTime(c))
  372. }
  373. func parseEventTime(t time.Time) string {
  374. return fmt.Sprintf("%d.%09d", t.Unix(), int64(t.Nanosecond()))
  375. }
  376. func setupRegistry(c *check.C, schema1 bool, auth, tokenURL string) *registry.V2 {
  377. reg, err := registry.NewV2(schema1, auth, tokenURL, privateRegistryURL)
  378. c.Assert(err, check.IsNil)
  379. // Wait for registry to be ready to serve requests.
  380. for i := 0; i != 50; i++ {
  381. if err = reg.Ping(); err == nil {
  382. break
  383. }
  384. time.Sleep(100 * time.Millisecond)
  385. }
  386. c.Assert(err, check.IsNil, check.Commentf("Timeout waiting for test registry to become available: %v", err))
  387. return reg
  388. }
  389. func setupNotary(c *check.C) *testNotary {
  390. ts, err := newTestNotary(c)
  391. c.Assert(err, check.IsNil)
  392. return ts
  393. }
  394. // appendBaseEnv appends the minimum set of environment variables to exec the
  395. // docker cli binary for testing with correct configuration to the given env
  396. // list.
  397. func appendBaseEnv(isTLS bool, env ...string) []string {
  398. preserveList := []string{
  399. // preserve remote test host
  400. "DOCKER_HOST",
  401. // windows: requires preserving SystemRoot, otherwise dial tcp fails
  402. // with "GetAddrInfoW: A non-recoverable error occurred during a database lookup."
  403. "SystemRoot",
  404. // testing help text requires the $PATH to dockerd is set
  405. "PATH",
  406. }
  407. if isTLS {
  408. preserveList = append(preserveList, "DOCKER_TLS_VERIFY", "DOCKER_CERT_PATH")
  409. }
  410. for _, key := range preserveList {
  411. if val := os.Getenv(key); val != "" {
  412. env = append(env, fmt.Sprintf("%s=%s", key, val))
  413. }
  414. }
  415. return env
  416. }
  417. func createTmpFile(c *check.C, content string) string {
  418. f, err := ioutil.TempFile("", "testfile")
  419. c.Assert(err, check.IsNil)
  420. filename := f.Name()
  421. err = ioutil.WriteFile(filename, []byte(content), 0644)
  422. c.Assert(err, check.IsNil)
  423. return filename
  424. }
  425. func waitForContainer(contID string, args ...string) error {
  426. args = append([]string{dockerBinary, "run", "--name", contID}, args...)
  427. result := icmd.RunCmd(icmd.Cmd{Command: args})
  428. if result.Error != nil {
  429. return result.Error
  430. }
  431. return waitRun(contID)
  432. }
  433. // waitRestart will wait for the specified container to restart once
  434. func waitRestart(contID string, duration time.Duration) error {
  435. return waitInspect(contID, "{{.RestartCount}}", "1", duration)
  436. }
  437. // waitRun will wait for the specified container to be running, maximum 5 seconds.
  438. func waitRun(contID string) error {
  439. return waitInspect(contID, "{{.State.Running}}", "true", 5*time.Second)
  440. }
  441. // waitExited will wait for the specified container to state exit, subject
  442. // to a maximum time limit in seconds supplied by the caller
  443. func waitExited(contID string, duration time.Duration) error {
  444. return waitInspect(contID, "{{.State.Status}}", "exited", duration)
  445. }
  446. // waitInspect will wait for the specified container to have the specified string
  447. // in the inspect output. It will wait until the specified timeout (in seconds)
  448. // is reached.
  449. func waitInspect(name, expr, expected string, timeout time.Duration) error {
  450. return waitInspectWithArgs(name, expr, expected, timeout)
  451. }
  452. func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg ...string) error {
  453. return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout, arg...)
  454. }
  455. func getInspectBody(c *check.C, version, id string) []byte {
  456. endpoint := fmt.Sprintf("/%s/containers/%s/json", version, id)
  457. status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
  458. c.Assert(err, check.IsNil)
  459. c.Assert(status, check.Equals, http.StatusOK)
  460. return body
  461. }
  462. // Run a long running idle task in a background container using the
  463. // system-specific default image and command.
  464. func runSleepingContainer(c *check.C, extraArgs ...string) (string, int) {
  465. return runSleepingContainerInImage(c, defaultSleepImage, extraArgs...)
  466. }
  467. // Run a long running idle task in a background container using the specified
  468. // image and the system-specific command.
  469. func runSleepingContainerInImage(c *check.C, image string, extraArgs ...string) (string, int) {
  470. args := []string{"run", "-d"}
  471. args = append(args, extraArgs...)
  472. args = append(args, image)
  473. args = append(args, sleepCommandForDaemonPlatform()...)
  474. return dockerCmd(c, args...)
  475. }
  476. // minimalBaseImage returns the name of the minimal base image for the current
  477. // daemon platform.
  478. func minimalBaseImage() string {
  479. return testEnv.MinimalBaseImage()
  480. }
  481. func getGoroutineNumber() (int, error) {
  482. i := struct {
  483. NGoroutines int
  484. }{}
  485. status, b, err := request.SockRequest("GET", "/info", nil, daemonHost())
  486. if err != nil {
  487. return 0, err
  488. }
  489. if status != http.StatusOK {
  490. return 0, fmt.Errorf("http status code: %d", status)
  491. }
  492. if err := json.Unmarshal(b, &i); err != nil {
  493. return 0, err
  494. }
  495. return i.NGoroutines, nil
  496. }
  497. func waitForGoroutines(expected int) error {
  498. t := time.After(30 * time.Second)
  499. for {
  500. select {
  501. case <-t:
  502. n, err := getGoroutineNumber()
  503. if err != nil {
  504. return err
  505. }
  506. if n > expected {
  507. return fmt.Errorf("leaked goroutines: expected less than or equal to %d, got: %d", expected, n)
  508. }
  509. default:
  510. n, err := getGoroutineNumber()
  511. if err != nil {
  512. return err
  513. }
  514. if n <= expected {
  515. return nil
  516. }
  517. time.Sleep(200 * time.Millisecond)
  518. }
  519. }
  520. }
  521. // getErrorMessage returns the error message from an error API response
  522. func getErrorMessage(c *check.C, body []byte) string {
  523. var resp types.ErrorResponse
  524. c.Assert(json.Unmarshal(body, &resp), check.IsNil)
  525. return strings.TrimSpace(resp.Message)
  526. }
  527. func waitAndAssert(c *check.C, timeout time.Duration, f checkF, checker check.Checker, args ...interface{}) {
  528. after := time.After(timeout)
  529. for {
  530. v, comment := f(c)
  531. assert, _ := checker.Check(append([]interface{}{v}, args...), checker.Info().Params)
  532. select {
  533. case <-after:
  534. assert = true
  535. default:
  536. }
  537. if assert {
  538. if comment != nil {
  539. args = append(args, comment)
  540. }
  541. c.Assert(v, checker, args...)
  542. return
  543. }
  544. time.Sleep(100 * time.Millisecond)
  545. }
  546. }
  547. type checkF func(*check.C) (interface{}, check.CommentInterface)
  548. type reducer func(...interface{}) interface{}
  549. func reducedCheck(r reducer, funcs ...checkF) checkF {
  550. return func(c *check.C) (interface{}, check.CommentInterface) {
  551. var values []interface{}
  552. var comments []string
  553. for _, f := range funcs {
  554. v, comment := f(c)
  555. values = append(values, v)
  556. if comment != nil {
  557. comments = append(comments, comment.CheckCommentString())
  558. }
  559. }
  560. return r(values...), check.Commentf("%v", strings.Join(comments, ", "))
  561. }
  562. }
  563. func sumAsIntegers(vals ...interface{}) interface{} {
  564. var s int
  565. for _, v := range vals {
  566. s += v.(int)
  567. }
  568. return s
  569. }