File: naming_test.go

package info (click to toggle)
golang-github-jinzhu-gorm 1.9.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, experimental, sid, trixie
  • size: 660 kB
  • sloc: sh: 4; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,507 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gorm_test

import (
	"testing"

	"github.com/jinzhu/gorm"
)

func TestTheNamingStrategy(t *testing.T) {

	cases := []struct {
		name     string
		namer    gorm.Namer
		expected string
	}{
		{name: "auth", expected: "auth", namer: gorm.TheNamingStrategy.DB},
		{name: "userRestrictions", expected: "user_restrictions", namer: gorm.TheNamingStrategy.Table},
		{name: "clientID", expected: "client_id", namer: gorm.TheNamingStrategy.Column},
	}

	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			result := c.namer(c.name)
			if result != c.expected {
				t.Errorf("error in naming strategy. expected: %v got :%v\n", c.expected, result)
			}
		})
	}

}

func TestNamingStrategy(t *testing.T) {

	dbNameNS := func(name string) string {
		return "db_" + name
	}
	tableNameNS := func(name string) string {
		return "tbl_" + name
	}
	columnNameNS := func(name string) string {
		return "col_" + name
	}

	ns := &gorm.NamingStrategy{
		DB:     dbNameNS,
		Table:  tableNameNS,
		Column: columnNameNS,
	}

	cases := []struct {
		name     string
		namer    gorm.Namer
		expected string
	}{
		{name: "auth", expected: "db_auth", namer: ns.DB},
		{name: "user", expected: "tbl_user", namer: ns.Table},
		{name: "password", expected: "col_password", namer: ns.Column},
	}

	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			result := c.namer(c.name)
			if result != c.expected {
				t.Errorf("error in naming strategy. expected: %v got :%v\n", c.expected, result)
			}
		})
	}

}