<commit_before>// +build !noInternet,!noDocker

package docker

import (
	"encoding/json"
	"os/exec"
	"strings"
	"time"

	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/commandreporter"
	"github.com/cloudfoundry-incubator/cf-test-helpers/helpers"
	. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/skip_messages"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"
)

var _ = DockerDescribe("Private Docker Registry Application Lifecycle", func() {
	var (
		appName  string
		username string
		password string
	)

	type dockerCreds struct {
		Username string `json:"username"`
		Password string `json:"password"`
	}

	type createAppRequest struct {
		Name              string      `json:"name"`
		SpaceGuid         string      `json:"space_guid"`
		DockerImage       string      `json:"docker_image"`
		DockerCredentials dockerCreds `json:"docker_credentials"`
	}

	BeforeEach(func() {
		if Config.GetBackend() != "diego" {
			Skip(skip_messages.SkipDiegoMessage)
		}

		if !Config.GetIncludePrivateDockerRegistry() {
			Skip(skip_messages.SkipPrivateDockerRegistryMessage)
		}
	})

	JustBeforeEach(func() {
		spaceName := TestSetup.RegularUserContext().Space
		session := cf.Cf("space", spaceName, "--guid")
		Eventually(session, Config.DefaultTimeoutDuration()).Should(Exit(0))
		spaceGuid := string(session.Out.Contents())
		spaceGuid = strings.TrimSpace(spaceGuid)
		appName = random_name.CATSRandomName("APP")

		newAppRequest, err := json.Marshal(createAppRequest{
			Name:        appName,
			SpaceGuid:   spaceGuid,
			DockerImage: Config.GetPrivateDockerRegistryImage(),
			DockerCredentials: dockerCreds{
				Username: username,
				Password: password,
			}})

		Expect(err).NotTo(HaveOccurred())

		cmd := exec.Command("cf", "curl", "-X", "POST", "/v2/apps", "-d", string(newAppRequest))
		cfCurlSession, err := Start(cmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())

		// Redact the docker password from the test logs
		cmd.Args[6] = strings.Replace(cmd.Args[6], `"password":"`+password+`"`, `"password":"***"`, 1)
		reporter := commandreporter.NewCommandReporter()
		reporter.Report(time.Now(), cmd)

		Eventually(cfCurlSession).Should(Exit(0))
	})

	AfterEach(func() {
		app_helpers.AppReport(appName, Config.DefaultTimeoutDuration())
		Eventually(cf.Cf("delete", appName, "-f"), Config.DefaultTimeoutDuration()).Should(Exit(0))
	})

	Context("when the correct username and password are given", func() {<commit_msg>Bump timeout on curl command<commit_after>// +build !noInternet,!noDocker

package docker

import (
	"encoding/json"
	"os/exec"
	"strings"
	"time"

	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/commandreporter"
	"github.com/cloudfoundry-incubator/cf-test-helpers/helpers"
	. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/skip_messages"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"
)

var _ = DockerDescribe("Private Docker Registry Application Lifecycle", func() {
	var (
		appName  string
		username string
		password string
	)

	type dockerCreds struct {
		Username string `json:"username"`
		Password string `json:"password"`
	}

	type createAppRequest struct {
		Name              string      `json:"name"`
		SpaceGuid         string      `json:"space_guid"`
		DockerImage       string      `json:"docker_image"`
		DockerCredentials dockerCreds `json:"docker_credentials"`
	}

	BeforeEach(func() {
		if Config.GetBackend() != "diego" {
			Skip(skip_messages.SkipDiegoMessage)
		}

		if !Config.GetIncludePrivateDockerRegistry() {
			Skip(skip_messages.SkipPrivateDockerRegistryMessage)
		}
	})

	JustBeforeEach(func() {
		spaceName := TestSetup.RegularUserContext().Space
		session := cf.Cf("space", spaceName, "--guid")
		Eventually(session, Config.DefaultTimeoutDuration()).Should(Exit(0))
		spaceGuid := string(session.Out.Contents())
		spaceGuid = strings.TrimSpace(spaceGuid)
		appName = random_name.CATSRandomName("APP")

		newAppRequest, err := json.Marshal(createAppRequest{
			Name:        appName,
			SpaceGuid:   spaceGuid,
			DockerImage: Config.GetPrivateDockerRegistryImage(),
			DockerCredentials: dockerCreds{
				Username: username,
				Password: password,
			}})

		Expect(err).NotTo(HaveOccurred())

		cmd := exec.Command("cf", "curl", "-X", "POST", "/v2/apps", "-d", string(newAppRequest))
		cfCurlSession, err := Start(cmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())

		// Redact the docker password from the test logs
		cmd.Args[6] = strings.Replace(cmd.Args[6], `"password":"`+password+`"`, `"password":"***"`, 1)
		reporter := commandreporter.NewCommandReporter()
		reporter.Report(time.Now(), cmd)

		Eventually(cfCurlSession, Config.DefaultTimeoutDuration()).Should(Exit(0))
	})

	AfterEach(func() {
		app_helpers.AppReport(appName, Config.DefaultTimeoutDuration())
		Eventually(cf.Cf("delete", appName, "-f"), Config.DefaultTimeoutDuration()).Should(Exit(0))
	})

	Context("when the correct username and password are given", func() {
{'fraction_non_alphanumeric': 0.14458689458689458, 'fraction_numerical': 0.002492877492877493, 'mean_word_length': 4.808686659772492, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2995446', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1871, 'n_words': 297}