github.com/eden-framework/sqlx@v0.0.2/builder/utils_test.go (about)

     1  package builder
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/onsi/gomega"
     7  )
     8  
     9  func TestValueMap(t *testing.T) {
    10  	type User struct {
    11  		ID       uint64 `db:"F_id"`
    12  		Name     string `db:"F_name"`
    13  		Username string `db:"F_username"`
    14  	}
    15  
    16  	user := User{
    17  		ID: 123123213,
    18  	}
    19  
    20  	t.Run("#FieldValuesFromStructBy", func(t *testing.T) {
    21  		gomega.NewWithT(t).Expect(FieldValuesFromStructBy(user, []string{})).To(gomega.HaveLen(0))
    22  
    23  		values := FieldValuesFromStructBy(user, []string{"ID"})
    24  
    25  		gomega.NewWithT(t).Expect(values).To(gomega.Equal(FieldValues{
    26  			"ID": user.ID,
    27  		}))
    28  	})
    29  
    30  	t.Run("#FieldValuesFromStructBy", func(t *testing.T) {
    31  		gomega.NewWithT(t).Expect(FieldValuesFromStructByNonZero(user)).
    32  			To(gomega.Equal(FieldValues{
    33  				"ID": user.ID,
    34  			}))
    35  
    36  		gomega.NewWithT(t).Expect(FieldValuesFromStructByNonZero(user, "Username")).
    37  			To(gomega.Equal(FieldValues{
    38  				"ID":       user.ID,
    39  				"Username": user.Username,
    40  			}))
    41  	})
    42  }