diff options
author | techknowlogick <techknowlogick@users.noreply.github.com> | 2018-06-20 01:06:01 -0400 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-06-20 08:06:01 +0300 |
commit | d84da8fe6562d9e7d2b5bb3626631ecefdca854e (patch) | |
tree | d613bf56f51757b652751fce4c33fe1ef3d7dc69 /models/models_test.go | |
parent | a93f13849cd7f54029f1dc17b642d024b98ee71e (diff) | |
download | gitea-d84da8fe6562d9e7d2b5bb3626631ecefdca854e.tar.gz gitea-d84da8fe6562d9e7d2b5bb3626631ecefdca854e.zip |
Change parsing of postgresql settings (#4275)
* Change parsing of postgresql settings
Fix #4200
* Add copyright
* update postgresql connection string
* add tests
Diffstat (limited to 'models/models_test.go')
-rw-r--r-- | models/models_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/models/models_test.go b/models/models_test.go index 649b1e02e5..7016fdb4b7 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -1,4 +1,5 @@ // Copyright 2016 The Gogs Authors. All rights reserved. +// Copyright 2018 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -53,3 +54,42 @@ func Test_parsePostgreSQLHostPort(t *testing.T) { assert.Equal(t, test.Port, port) } } + +func Test_getPostgreSQLConnectionString(t *testing.T) { + tests := []struct { + Host string + Port string + User string + Passwd string + Name string + Param string + SSLMode string + Output string + }{ + { + Host: "/tmp/pg.sock", + Port: "4321", + User: "testuser", + Passwd: "space space !#$%^^%^```-=?=", + Name: "gitea", + Param: "", + SSLMode: "false", + Output: "postgres://testuser:space%20space%20%21%23$%25%5E%5E%25%5E%60%60%60-=%3F=@:5432/giteasslmode=false&host=/tmp/pg.sock", + }, + { + Host: "localhost", + Port: "1234", + User: "pgsqlusername", + Passwd: "I love Gitea!", + Name: "gitea", + Param: "", + SSLMode: "true", + Output: "postgres://pgsqlusername:I%20love%20Gitea%21@localhost:5432/giteasslmode=true", + }, + } + + for _, test := range tests { + connStr := getPostgreSQLConnectionString(test.Host, test.User, test.Passwd, test.Name, test.Param, test.SSLMode) + assert.Equal(t, test.Output, connStr) + } +} |