<commit_before>package docker_metadata_fetcher_test

import (
	"net/url"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"

	"github.com/docker/docker/registry"
	"github.com/pivotal-cf-experimental/lattice-cli/app_runner/docker_metadata_fetcher"
)

var _ = Describe("DockerSessionFactory", func() {
	Describe("MakeSession", func() {
		var registryHost string
		var dockerRegistryServer *ghttp.Server

		BeforeEach(func() {
			dockerRegistryServer = ghttp.NewServer()
		})

		AfterEach(func() {
			dockerRegistryServer.Close()
		})

		Describe("Happy Path", func() {
			BeforeEach(func() {
				parts, _ := url.Parse(dockerRegistryServer.URL())
				registryHost = parts.Host

				dockerRegistryServer.RouteToHandler("GET", "/v1/_ping", ghttp.VerifyRequest("GET", "/v1/_ping"))
			})

			It("creates a registry session for the given repo", func() {
				sessionFactory := docker_metadata_fetcher.NewDockerSessionFactory()
				session, err := sessionFactory.MakeSession(registryHost + "/lattice-mappppppppppppappapapa")

				Expect(err).ToNot(HaveOccurred())
				registrySession, ok := session.(*registry.Session)
				Expect(ok).To(Equal(true))

				Expect(*registrySession.GetAuthConfig(true)).To(Equal(registry.AuthConfig{}))

			})
		})

		Context("When resolving the repo name fails", func() {
			It("returns errors from resolving the repo name", func() {
				sessionFactory := docker_metadata_fetcher.NewDockerSessionFactory()
				_, err := sessionFactory.MakeSession("¥Not-A-Valid-Repo-Name¥" + "/lattice-mappppppppppppappapapa")

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(Equal("Error resolving Docker repository name:\nInvalid namespace name (¥Not-A-Valid-Repo-Name¥), only [a-z0-9_] are allowed, size between 4 and 30"))

			})
		})

		Context("when creating a new endpoint fails", func() {
			It("returns an error", func() {
				sessionFactory := docker_metadata_fetcher.NewDockerSessionFactory()
				_, err := sessionFactory.MakeSession(registryHost + "/lattice-mappppppppppppappapapa")

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(MatchRegexp("Error Connecting to Docker registry:\nInvalid registry endpoint"))
			})
		})

	})
})<commit_msg>Fix failing test (bad test setup)<commit_after>package docker_metadata_fetcher_test

import (
	"net/url"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"

	"github.com/docker/docker/registry"
	"github.com/pivotal-cf-experimental/lattice-cli/app_runner/docker_metadata_fetcher"
)

var _ = Describe("DockerSessionFactory", func() {
	Describe("MakeSession", func() {
		var registryHost string
		var dockerRegistryServer *ghttp.Server

		BeforeEach(func() {
			dockerRegistryServer = ghttp.NewServer()
		})

		AfterEach(func() {
			dockerRegistryServer.Close()
		})

		Describe("Happy Path", func() {
			BeforeEach(func() {
				parts, _ := url.Parse(dockerRegistryServer.URL())
				registryHost = parts.Host

				dockerRegistryServer.RouteToHandler("GET", "/v1/_ping", ghttp.VerifyRequest("GET", "/v1/_ping"))
			})

			It("creates a registry session for the given repo", func() {
				sessionFactory := docker_metadata_fetcher.NewDockerSessionFactory()
				session, err := sessionFactory.MakeSession(registryHost + "/lattice-mappppppppppppappapapa")

				Expect(err).ToNot(HaveOccurred())
				registrySession, ok := session.(*registry.Session)
				Expect(ok).To(Equal(true))

				Expect(*registrySession.GetAuthConfig(true)).To(Equal(registry.AuthConfig{}))

			})
		})

		Context("When resolving the repo name fails", func() {
			It("returns errors from resolving the repo name", func() {
				sessionFactory := docker_metadata_fetcher.NewDockerSessionFactory()
				_, err := sessionFactory.MakeSession("¥Not-A-Valid-Repo-Name¥" + "/lattice-mappppppppppppappapapa")

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(Equal("Error resolving Docker repository name:\nInvalid namespace name (¥Not-A-Valid-Repo-Name¥), only [a-z0-9_] are allowed, size between 4 and 30"))

			})
		})

		Context("when creating a new endpoint fails", func() {
			It("returns an error", func() {
				sessionFactory := docker_metadata_fetcher.NewDockerSessionFactory()
				_, err := sessionFactory.MakeSession("nonexistantregistry.example.com/lattice-mappppppppppppappapapa")

				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(MatchRegexp("Error Connecting to Docker registry:\nInvalid registry endpoint"))
			})
		})

	})
})
{'fraction_non_alphanumeric': 0.1442264823896567, 'fraction_numerical': 0.003120820329915292, 'mean_word_length': 4.782216494845361, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '2276131', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1407, 'n_words': 244}