gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

validate_test.go (4010B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package config_test
     19 
     20 import (
     21 	"testing"
     22 
     23 	"github.com/stretchr/testify/suite"
     24 	"github.com/superseriousbusiness/gotosocial/internal/config"
     25 	"github.com/superseriousbusiness/gotosocial/testrig"
     26 )
     27 
     28 type ConfigValidateTestSuite struct {
     29 	suite.Suite
     30 }
     31 
     32 func (suite *ConfigValidateTestSuite) TestValidateConfigOK() {
     33 	testrig.InitTestConfig()
     34 
     35 	err := config.Validate()
     36 	suite.NoError(err)
     37 }
     38 
     39 func (suite *ConfigValidateTestSuite) TestValidateConfigNoHost() {
     40 	testrig.InitTestConfig()
     41 
     42 	config.SetHost("")
     43 
     44 	err := config.Validate()
     45 	suite.EqualError(err, "host must be set")
     46 }
     47 
     48 func (suite *ConfigValidateTestSuite) TestValidateAccountDomainOK1() {
     49 	testrig.InitTestConfig()
     50 
     51 	err := config.Validate()
     52 	suite.NoError(err)
     53 
     54 	suite.Equal(config.GetHost(), config.GetAccountDomain())
     55 }
     56 
     57 func (suite *ConfigValidateTestSuite) TestValidateAccountDomainOK2() {
     58 	testrig.InitTestConfig()
     59 
     60 	config.SetAccountDomain("localhost:8080")
     61 
     62 	err := config.Validate()
     63 	suite.NoError(err)
     64 }
     65 
     66 func (suite *ConfigValidateTestSuite) TestValidateAccountDomainOK3() {
     67 	testrig.InitTestConfig()
     68 
     69 	config.SetHost("gts.example.org")
     70 	config.SetAccountDomain("example.org")
     71 
     72 	err := config.Validate()
     73 	suite.NoError(err)
     74 }
     75 
     76 func (suite *ConfigValidateTestSuite) TestValidateAccountDomainNotSubdomain1() {
     77 	testrig.InitTestConfig()
     78 
     79 	config.SetHost("gts.example.org")
     80 	config.SetAccountDomain("example.com")
     81 
     82 	err := config.Validate()
     83 	suite.EqualError(err, "host was gts.example.org and account-domain was example.com, but gts.example.org is not a valid subdomain of example.com")
     84 }
     85 
     86 func (suite *ConfigValidateTestSuite) TestValidateAccountDomainNotSubdomain2() {
     87 	testrig.InitTestConfig()
     88 
     89 	config.SetHost("example.org")
     90 	config.SetAccountDomain("gts.example.org")
     91 
     92 	err := config.Validate()
     93 	suite.EqualError(err, "host was example.org and account-domain was gts.example.org, but example.org is not a valid subdomain of gts.example.org")
     94 }
     95 
     96 func (suite *ConfigValidateTestSuite) TestValidateConfigNoProtocol() {
     97 	testrig.InitTestConfig()
     98 
     99 	config.SetProtocol("")
    100 
    101 	err := config.Validate()
    102 	suite.EqualError(err, "protocol must be set")
    103 }
    104 
    105 func (suite *ConfigValidateTestSuite) TestValidateConfigNoWebAssetBaseDir() {
    106 	testrig.InitTestConfig()
    107 
    108 	config.SetWebAssetBaseDir("")
    109 
    110 	err := config.Validate()
    111 	suite.EqualError(err, "web-asset-base-dir must be set")
    112 }
    113 
    114 func (suite *ConfigValidateTestSuite) TestValidateConfigNoProtocolOrHost() {
    115 	testrig.InitTestConfig()
    116 
    117 	config.SetHost("")
    118 	config.SetProtocol("")
    119 
    120 	err := config.Validate()
    121 	suite.EqualError(err, "host must be set; protocol must be set")
    122 }
    123 
    124 func (suite *ConfigValidateTestSuite) TestValidateConfigBadProtocol() {
    125 	testrig.InitTestConfig()
    126 
    127 	config.SetProtocol("foo")
    128 
    129 	err := config.Validate()
    130 	suite.EqualError(err, "protocol must be set to either http or https, provided value was foo")
    131 }
    132 
    133 func (suite *ConfigValidateTestSuite) TestValidateConfigBadProtocolNoHost() {
    134 	testrig.InitTestConfig()
    135 
    136 	config.SetHost("")
    137 	config.SetProtocol("foo")
    138 
    139 	err := config.Validate()
    140 	suite.EqualError(err, "host must be set; protocol must be set to either http or https, provided value was foo")
    141 }
    142 
    143 func TestConfigValidateTestSuite(t *testing.T) {
    144 	suite.Run(t, &ConfigValidateTestSuite{})
    145 }