<commit_before>package integration_test

import (
	"fmt"
	"io"
	"os/exec"

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

	"github.com/concourse/atc"
	"github.com/concourse/fly/version"
)

var _ = Describe("login Command", func() {
	var (
		atcServer *ghttp.Server
	)

	Describe("login with no target name", func() {
		var (
			flyCmd *exec.Cmd
		)

		BeforeEach(func() {
			atcServer = ghttp.NewServer()
			atcServer.AppendHandlers(
				infoHandler(),
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/api/v1/teams/main/auth/methods"),
					ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}),
				),
			)
			flyCmd = exec.Command(flyPath, "login", "-c", atcServer.URL(), "-n", "main")
		})

		It("instructs the user to specify --target", func() {
			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())

			<-sess.Exited
			Expect(sess.ExitCode()).To(Equal(1))

			Expect(sess.Err).To(gbytes.Say(`name for the target must be specified \(--target/-t\)`))
		})
	})

	Context("with no team name", func() {
		BeforeEach(func() {
			atcServer = ghttp.NewServer()
		})

		It("instructs the user to specify --team-name", func() {
			flyCmd := exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL())
			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())

			<-sess.Exited
			Expect(sess.ExitCode()).To(Equal(1))

			Expect(sess.Err).To(gbytes.Say("the required flag "))
			Expect(sess.Err).To(gbytes.Say("n, "))
			Expect(sess.Err).To(gbytes.Say("team-name' was not specified"))
		})
	})

	Context("with a team name", func() {
		BeforeEach(func() {
			atcServer = ghttp.NewServer()
		})

		It("uses specified team", func() {
			atcServer.AppendHandlers(
				infoHandler(),
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/api/v1/teams/some-team/auth/methods"),
					ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}),
				),
				tokenHandler("some-team"),<commit_msg>Revert "Ooops"<commit_after>package integration_test

import (
	"fmt"
	"io"
	"os/exec"

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

	"github.com/concourse/atc"
	"github.com/concourse/fly/version"
)

var _ = Describe("login Command", func() {
	var (
		atcServer *ghttp.Server
	)

	Describe("login with no target name", func() {
		var (
			flyCmd *exec.Cmd
		)

		BeforeEach(func() {
			atcServer = ghttp.NewServer()
			atcServer.AppendHandlers(
				infoHandler(),
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/api/v1/teams/main/auth/methods"),
					ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}),
				),
			)
			flyCmd = exec.Command(flyPath, "login", "-c", atcServer.URL(), "-n", "main")
		})

		It("instructs the user to specify --target", func() {
			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())

			<-sess.Exited
			Expect(sess.ExitCode()).To(Equal(1))

			Expect(sess.Err).To(gbytes.Say(`name for the target must be specified \(--target/-t\)`))
		})
	})

	Context("with no team name", func() {
		BeforeEach(func() {
			atcServer = ghttp.NewServer()
		})

		FIt("instructs the user to specify --team-name", func() {
			flyCmd := exec.Command(flyPath, "-t", "some-target", "login", "-c", atcServer.URL())
			sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())

			<-sess.Exited
			Expect(sess.ExitCode()).To(Equal(1))

			Expect(sess.Err).To(gbytes.Say("the required flag "))
			Expect(sess.Err).To(gbytes.Say("n, "))
			Expect(sess.Err).To(gbytes.Say("team-name' was not specified"))
		})
	})

	Context("with a team name", func() {
		BeforeEach(func() {
			atcServer = ghttp.NewServer()
		})

		It("uses specified team", func() {
			atcServer.AppendHandlers(
				infoHandler(),
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/api/v1/teams/some-team/auth/methods"),
					ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}),
				),
				tokenHandler("some-team"),
{'fraction_non_alphanumeric': 0.1840607210626186, 'fraction_numerical': 0.004743833017077799, 'mean_word_length': 3.8029612756264237, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6855008', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1602, 'n_words': 254}