MCPcopy Create free account
hub / github.com/abice/go-enum / TestExampleSQLStrIntOnly

Function TestExampleSQLStrIntOnly

example/sql_str_int_enum_test.go:17–307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestExampleSQLStrIntOnly(t *testing.T) {
18 tests := map[string]struct {
19 setupMock func(t testing.TB, mocks *MockSQL)
20 tester func(t testing.TB, db *sql.DB)
21 }{
22 "NonNullable select nil": {
23 setupMock: func(t testing.TB, mocks *MockSQL) {
24 gomock.InOrder(
25 // Select In Work
26 mocks.Conn.EXPECT().Prepare("SELECT god FROM job WHERE id = ?").Return(mocks.Stmt, nil),
27 mocks.Stmt.EXPECT().NumInput().Return(1),
28 mocks.Stmt.EXPECT().Query(gomock.Any()).Return(mocks.Rows, nil),
29 mocks.Rows.EXPECT().Columns().Return([]string{`god`}),
30 mocks.Rows.EXPECT().Next(gomock.Any()).SetArg(0, []driver.Value{nil}).Return(nil),
31 mocks.Rows.EXPECT().Close().Return(nil),
32 mocks.Stmt.EXPECT().Close().Return(nil),
33 )
34 },
35 tester: func(t testing.TB, conn *sql.DB) {
36 // Get inWork god
37 god, err := getGreekGod(conn)
38 require.NoError(t, err, "failed getting project god")
39 require.Equal(t, GreekGod(""), god)
40 },
41 },
42 "Nullable Select Null": {
43 setupMock: func(t testing.TB, mocks *MockSQL) {
44 gomock.InOrder(
45 // Select In Work
46 mocks.Conn.EXPECT().Prepare("SELECT god FROM job WHERE id = ?").Return(mocks.Stmt, nil),
47 mocks.Stmt.EXPECT().NumInput().Return(1),
48 mocks.Stmt.EXPECT().Query(gomock.Any()).Return(mocks.Rows, nil),
49 mocks.Rows.EXPECT().Columns().Return([]string{`god`}),
50 mocks.Rows.EXPECT().Next(gomock.Any()).SetArg(0, []driver.Value{nil}).Return(nil),
51 mocks.Rows.EXPECT().Close().Return(nil),
52 mocks.Stmt.EXPECT().Close().Return(nil),
53 )
54 },
55 tester: func(t testing.TB, conn *sql.DB) {
56 // Get inWork god
57 god, err := getNullGreekGod(conn)
58 require.NoError(t, err, "failed getting project god")
59 require.False(t, god.Valid)
60 },
61 },
62 "Select a string": {
63 setupMock: func(t testing.TB, mocks *MockSQL) {
64 gomock.InOrder(
65 // Select In Work
66 mocks.Conn.EXPECT().Prepare("SELECT god FROM job WHERE id = ?").Return(mocks.Stmt, nil),
67 mocks.Stmt.EXPECT().NumInput().Return(1),
68 mocks.Stmt.EXPECT().Query(gomock.Any()).Return(mocks.Rows, nil),
69 mocks.Rows.EXPECT().Columns().Return([]string{`god`}),
70 mocks.Rows.EXPECT().Next(gomock.Any()).SetArg(0, []driver.Value{GreekGodAthena.String()}).Return(nil),
71 mocks.Rows.EXPECT().Close().Return(nil),
72 mocks.Stmt.EXPECT().Close().Return(nil),
73 )
74 },

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
getGreekGodFunction · 0.85
GreekGodTypeAlias · 0.85
getNullGreekGodFunction · 0.85
MatchesValuesFunction · 0.85
setGreekGodFunction · 0.85
NewNullGreekGodFunction · 0.85
NewMockDriverFunction · 0.85
WithMockSQLFunction · 0.85
PrepareMethod · 0.45
EXPECTMethod · 0.45
NumInputMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…