11package sql
22
33import (
4- "testing"
54 "context"
65 "github.com/google/sqlcommenter/go/core"
6+ "testing"
77)
88
99func TestWithComment_NoContext (t * testing.T ) {
1010 testBasicConn := & mockConn {}
1111 testCases := []struct {
12- desc string
12+ desc string
1313 commenterOptions core.CommenterOptions
14- query string
15- wantQuery string
16- } {
14+ query string
15+ wantQuery string
16+ }{
1717 {
18- desc : "empty commenter options" ,
18+ desc : "empty commenter options" ,
1919 commenterOptions : core.CommenterOptions {},
20- query : "SELECT 1;" ,
21- wantQuery : "SELECT 1;" ,
20+ query : "SELECT 1;" ,
21+ wantQuery : "SELECT 1;" ,
2222 },
2323 {
2424 desc : "only enable DBDriver" ,
2525 commenterOptions : core.CommenterOptions {
2626 Config : core.CommenterConfig {EnableDBDriver : true },
2727 },
28- query : "SELECT 1;" ,
28+ query : "SELECT 1;" ,
2929 wantQuery : "SELECT 1/*db_driver=database%2Fsql%3A*/;" ,
3030 },
3131 {
3232 desc : "enable DBDriver and pass static tag driver name" ,
3333 commenterOptions : core.CommenterOptions {
3434 Config : core.CommenterConfig {EnableDBDriver : true },
35- Tags : core.StaticTags {DriverName : "postgres" },
35+ Tags : core.StaticTags {DriverName : "postgres" },
3636 },
37- query : "SELECT 1;" ,
37+ query : "SELECT 1;" ,
3838 wantQuery : "SELECT 1/*db_driver=database%2Fsql%3Apostgres*/;" ,
3939 },
4040 {
4141 desc : "enable DBDriver and pass all static tags" ,
4242 commenterOptions : core.CommenterOptions {
4343 Config : core.CommenterConfig {EnableDBDriver : true },
44- Tags : core.StaticTags {DriverName : "postgres" , Application : "app-1" },
44+ Tags : core.StaticTags {DriverName : "postgres" , Application : "app-1" },
4545 },
46- query : "SELECT 1;" ,
46+ query : "SELECT 1;" ,
4747 wantQuery : "SELECT 1/*db_driver=database%2Fsql%3Apostgres*/;" ,
4848 },
4949 {
5050 desc : "enable other tags and pass all static tags" ,
5151 commenterOptions : core.CommenterOptions {
5252 Config : core.CommenterConfig {EnableDBDriver : true , EnableApplication : true , EnableFramework : true },
53- Tags : core.StaticTags {DriverName : "postgres" , Application : "app-1" },
53+ Tags : core.StaticTags {DriverName : "postgres" , Application : "app-1" },
5454 },
55- query : "SELECT 1;" ,
55+ query : "SELECT 1;" ,
5656 wantQuery : "SELECT 1/*application=app-1,db_driver=database%2Fsql%3Apostgres*/;" ,
5757 },
5858 }
@@ -68,70 +68,70 @@ func TestWithComment_NoContext(t *testing.T) {
6868func TestWithComment_WithContext (t * testing.T ) {
6969 testBasicConn := & mockConn {}
7070 testCases := []struct {
71- desc string
71+ desc string
7272 commenterOptions core.CommenterOptions
73- ctx context.Context
74- query string
75- wantQuery string
76- } {
73+ ctx context.Context
74+ query string
75+ wantQuery string
76+ }{
7777 {
78- desc : "empty commenter options" ,
78+ desc : "empty commenter options" ,
7979 commenterOptions : core.CommenterOptions {},
8080 ctx : getContextWithKeyValue (
81- map [string ]string {
82- "route" : "listData" ,
81+ map [string ]string {
82+ "route" : "listData" ,
8383 "framework" : "custom-golang" ,
8484 },
8585 ),
86- query : "SELECT 1;" ,
86+ query : "SELECT 1;" ,
8787 wantQuery : "SELECT 1;" ,
8888 },
8989 {
9090 desc : "only all options but context has few tags" ,
9191 commenterOptions : core.CommenterOptions {
9292 Config : core.CommenterConfig {
93- EnableDBDriver : true ,
94- EnableRoute : true ,
95- EnableFramework : true ,
96- EnableController : true ,
97- EnableAction : true ,
93+ EnableDBDriver : true ,
94+ EnableRoute : true ,
95+ EnableFramework : true ,
96+ EnableController : true ,
97+ EnableAction : true ,
9898 EnableTraceparent : true ,
9999 EnableApplication : true ,
100100 },
101101 Tags : core.StaticTags {DriverName : "postgres" , Application : "app-1" },
102102 },
103103 ctx : getContextWithKeyValue (
104- map [string ]string {
105- "route" : "listData" ,
104+ map [string ]string {
105+ "route" : "listData" ,
106106 "framework" : "custom-golang" ,
107107 },
108108 ),
109- query : "SELECT 1;" ,
109+ query : "SELECT 1;" ,
110110 wantQuery : "SELECT 1/*application=app-1,db_driver=database%2Fsql%3Apostgres,framework=custom-golang,route=listData*/;" ,
111111 },
112112 {
113113 desc : "only all options but context contains all tags" ,
114114 commenterOptions : core.CommenterOptions {
115115 Config : core.CommenterConfig {
116- EnableDBDriver : true ,
117- EnableRoute : true ,
118- EnableFramework : true ,
119- EnableController : true ,
120- EnableAction : true ,
116+ EnableDBDriver : true ,
117+ EnableRoute : true ,
118+ EnableFramework : true ,
119+ EnableController : true ,
120+ EnableAction : true ,
121121 EnableTraceparent : true ,
122122 EnableApplication : true ,
123123 },
124124 Tags : core.StaticTags {DriverName : "postgres" , Application : "app-1" },
125125 },
126126 ctx : getContextWithKeyValue (
127- map [string ]string {
128- "route" : "listData" ,
129- "framework" : "custom-golang" ,
127+ map [string ]string {
128+ "route" : "listData" ,
129+ "framework" : "custom-golang" ,
130130 "controller" : "custom-controller" ,
131- "action" : "any action" ,
131+ "action" : "any action" ,
132132 },
133133 ),
134- query : "SELECT 1;" ,
134+ query : "SELECT 1;" ,
135135 wantQuery : "SELECT 1/*action=any+action,application=app-1,db_driver=database%2Fsql%3Apostgres,framework=custom-golang,route=listData*/;" ,
136136 },
137137 }
0 commit comments