func TestUserFullNameWithNeither(t *testing.T) { u, err := user.New() if err != nil { t.Errorf("Got an unexpected error: %v", err) } fullName := u.FullName() if fullName != "" { t.Errorf("Expected '%s' to be empty", fullName) } }
func TestUserFullNameWithoutFirstName(t *testing.T) { u, err := user.New() if err != nil { t.Errorf("Got an unexpected error: %v", err) } u.LastName = "Manning" fullName := u.FullName() if fullName != "Manning" { t.Errorf("Expected '%s' to be Manning", fullName) } }
func TestUserFullName(t *testing.T) { for _, fullNameCase := range fullNameCases { u, err := user.New() if err != nil { t.Errorf("Got an unexpected error: %v", err) } u.FirstName = fullNameCase.FirstName u.LastName = fullNameCase.LastName fullName := u.FullName() if fullName != fullNameCase.Result { t.Errorf("Expected '%s' to equal '%s'", fullName, fullNameCase.Result) } } }
func main() { // database mgoSession, err := mgo.Dial("128.199.130.44:27017") if err != nil { panic(err) } // register services userService := user.New(userStore.New(mgoSession, "example")) loginService := login.New(userService) registerService := register.New(userService) // create server r := render.New(render.Options{ Directory: "server/views", Layout: "layout", Extensions: []string{".html"}, Delims: render.Delims{"[[", "]]"}, IsDevelopment: true, }) g := gin.New() g.Use(cors.Middleware(cors.Config{ Origins: "*", Methods: "GET, PUT, POST, DELETE", RequestHeaders: "Origin, Content-Type", Credentials: true, ValidateHeaders: false, })) g.Use(sessions.Sessions("webadmin", sessions.NewCookieStore([]byte("something-very-secret")))) g.Static("/assets", "./public") // register handlers NewUserHandlers(userService, r).RegisterHandlers(g) NewFrontendHandlers(loginService, registerService, r).RegisterHandlers(g) // run server g.Run(":3000") }
package user_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "user" ) var _ = Describe("User", func() { var u *user.User BeforeEach(func() { var err error u, err = user.New() Expect(err).NotTo(HaveOccurred()) }) Describe("Full Name", func() { Context("With a first and last name", func() { It("should concatenate the names with a ' '", func() { u.FirstName = "Peyton" u.LastName = "Manning" Expect(u.FullName()).To(Equal("Peyton Manning")) }) }) Context("With only a first name", func() { It("should return the first name", func() { u.FirstName = "Peyton" Expect(u.FullName()).To(Equal("Peyton")) })