package cf_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/peterellisjones/cf-test-helpers/cf" ) var _ = Describe("NewUserContext", func() { var createUser = func() cf.UserContext { return cf.NewUserContext("http://FAKE_API.example.com", "FAKE_USERNAME", "FAKE_PASSWORD", "FAKE_ORG", "FAKE_SPACE") } It("returns a UserContext struct", func() { Expect(createUser()).To(BeAssignableToTypeOf(cf.UserContext{})) }) It("sets UserContext.ApiUrl", func() { Expect(createUser().ApiUrl).To(Equal("http://FAKE_API.example.com")) }) It("sets UserContext.Username", func() { Expect(createUser().Username).To(Equal("FAKE_USERNAME")) }) It("sets UserContext.Password", func() { Expect(createUser().Password).To(Equal("FAKE_PASSWORD")) })
package helpers import ( "os" "github.com/peterellisjones/cf-test-helpers/cf" ) var AdminUserContext = cf.NewUserContext(os.Getenv("API_ENDPOINT"), os.Getenv("ADMIN_USER"), os.Getenv("ADMIN_PASSWORD"), os.Getenv("CF_ORG"), os.Getenv("CF_SPACE")) var RegularUserContext = cf.NewUserContext(os.Getenv("API_ENDPOINT"), os.Getenv("CF_USER"), os.Getenv("CF_USER_PASSWORD"), os.Getenv("CF_ORG"), os.Getenv("CF_SPACE"))
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/peterellisjones/cf-test-helpers/cf" "github.com/vito/cmdtest" ) var _ = Describe("CreateEnvironmentForUserContext", func() { var FakeCfCalls = [][]string{} var FakeCf = func(args ...string) *cmdtest.Session { FakeCfCalls = append(FakeCfCalls, args) var session, _ = cmdtest.Start(exec.Command("echo", "nothing")) return session } var user = cf.NewUserContext("http://FAKE_API.example.com", "FAKE_USERNAME", "FAKE_PASSWORD", "FAKE_ORG", "FAKE_SPACE") var admin = cf.NewUserContext("http://FAKE_API.example.com", "FAKE_ADMIN_USERNAME", "FAKE_ADMIN_PASSWORD", "FAKE_ADMIN_ORG", "FAKE_ADMIN_SPACE") BeforeEach(func() { FakeCfCalls = [][]string{} cf.Cf = FakeCf }) It("calls cf api", func() { cf.CreateEnvironmentForUserContext(admin, user) Expect(FakeCfCalls[0]).To(Equal([]string{"api", "http://FAKE_API.example.com"})) }) It("calls cf auth with admin credentials", func() { cf.CreateEnvironmentForUserContext(admin, user)