(t *testing.T)
| 58 | const keepaliveSuffix = " keepalives=1 keepalives_idle=60 keepalives_interval=10 keepalives_count=5" |
| 59 | |
| 60 | func TestInjectPostgresApplicationName(t *testing.T) { |
| 61 | tests := []struct { |
| 62 | name string |
| 63 | input string |
| 64 | appNm string |
| 65 | want string |
| 66 | }{ |
| 67 | { |
| 68 | name: "adds application_name to postgres connection", |
| 69 | input: "postgres:host=localhost dbname=dl", |
| 70 | appNm: "duckgres/acme", |
| 71 | want: "postgres:host=localhost dbname=dl application_name='duckgres/acme'", |
| 72 | }, |
| 73 | { |
| 74 | name: "skips when name is empty", |
| 75 | input: "postgres:host=localhost dbname=dl", |
| 76 | appNm: "", |
| 77 | want: "postgres:host=localhost dbname=dl", |
| 78 | }, |
| 79 | { |
| 80 | name: "skips if application_name already set", |
| 81 | input: "postgres:host=localhost dbname=dl application_name=custom", |
| 82 | appNm: "duckgres/acme", |
| 83 | want: "postgres:host=localhost dbname=dl application_name=custom", |
| 84 | }, |
| 85 | { |
| 86 | name: "skips non-postgres metadata stores", |
| 87 | input: "sqlite:/tmp/test.db", |
| 88 | appNm: "duckgres/acme", |
| 89 | want: "sqlite:/tmp/test.db", |
| 90 | }, |
| 91 | { |
| 92 | name: "escapes single quotes", |
| 93 | input: "postgres:host=localhost dbname=dl", |
| 94 | appNm: "duckgres/it's", |
| 95 | want: "postgres:host=localhost dbname=dl application_name='duckgres/it''s'", |
| 96 | }, |
| 97 | { |
| 98 | name: "truncates to 63 bytes (libpq application_name ceiling)", |
| 99 | input: "postgres:host=localhost dbname=dl", |
| 100 | appNm: strings.Repeat("a", 80), |
| 101 | want: "postgres:host=localhost dbname=dl application_name='" + strings.Repeat("a", 63) + "'", |
| 102 | }, |
| 103 | } |
| 104 | |
| 105 | for _, tt := range tests { |
| 106 | t.Run(tt.name, func(t *testing.T) { |
| 107 | got := injectPostgresApplicationName(tt.input, tt.appNm) |
| 108 | if got != tt.want { |
| 109 | t.Errorf("injectPostgresApplicationName(%q, %q) =\n %s\nwant:\n %s", tt.input, tt.appNm, got, tt.want) |
| 110 | } |
| 111 | }) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | func TestBuildAttachStmt(t *testing.T) { |
| 116 | tests := []struct { |
nothing calls this directly
no test coverage detected