forked from metalogical/BigFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add: supplementary-unit-testing add config_test.go add validate_test.go 补充单元测试 * edit: 修改不存在的配置文件的名称 不存在的配置文件的名称修改为missing_config.yml
- Loading branch information
Showing
5 changed files
with
189 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
LFS_BUCKET: "***********" | ||
CDN_DOMAIN: "***********" | ||
OBS_REGION: "***********" | ||
OBS_ACCESS_KEY_ID: "***********" | ||
OBS_SECRET_ACCESS_KEY: "***********" | ||
CLIENT_ID: "***********" | ||
CLIENT_SECRET: "***********" | ||
PATH_PREFIX: "***********" | ||
DEFAULT_TOKEN: "***********" | ||
VALIDATE_REGEXP: | ||
OWNER_REGEXP: "^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$" | ||
REPONAME_REGEXP: "^[a-zA-Z0-9_.-]{1,189}[a-zA-Z0-9]$" | ||
USERNAME_REGEXP: "^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$" | ||
PASSWORD_REGEXP: "^[a-zA-Z0-9!@_#$%^&*()\\-=+,?.,]*$" | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package config | ||
|
||
import "testing" | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
type args struct { | ||
path string | ||
cfg *Config | ||
remove bool | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "TestLoadConfig success", | ||
args: args{ | ||
path: "../config.example.yml", | ||
cfg: &Config{}, | ||
remove: false, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "TestLoadConfig fail", | ||
args: args{ | ||
path: "../missing_config.yml", | ||
cfg: &Config{}, | ||
remove: false, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "TestLoadConfig fail and remove LocalFile", | ||
args: args{ | ||
path: "../missing_config.yml", | ||
cfg: &Config{}, | ||
remove: true, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := LoadConfig(tt.args.path, tt.args.cfg, tt.args.remove); (err != nil) != tt.wantErr { | ||
t.Errorf("LoadConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/metalogical/BigFiles/config" | ||
"testing" | ||
) | ||
|
||
func TestInit(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
args config.ValidateConfig | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "compile owner regexp failed", | ||
args: config.ValidateConfig{ | ||
OwnerRegexp: `^[\\-?]$`, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "compile repo regexp failed", | ||
args: config.ValidateConfig{ | ||
OwnerRegexp: `^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$`, | ||
RepoNameRegexp: `^[\\-?]$`, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "compile username regexp failed", | ||
args: config.ValidateConfig{ | ||
OwnerRegexp: `^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$`, | ||
RepoNameRegexp: `^[a-zA-Z0-9_.-]{1,189}[a-zA-Z0-9]$`, | ||
UsernameRegexp: `^[\\-?]$`, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "compile password regexp failed", | ||
args: config.ValidateConfig{ | ||
OwnerRegexp: `^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$`, | ||
RepoNameRegexp: `^[a-zA-Z0-9_.-]{1,189}[a-zA-Z0-9]$`, | ||
UsernameRegexp: `^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$`, | ||
PasswordRegexp: `^[\\-?]$`, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "compile regexp success", | ||
args: config.ValidateConfig{ | ||
OwnerRegexp: `^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$`, | ||
RepoNameRegexp: `^[a-zA-Z0-9_.-]{1,189}[a-zA-Z0-9]$`, | ||
UsernameRegexp: `^[a-zA-Z]([-_.]?[a-zA-Z0-9]+)*$`, | ||
PasswordRegexp: `^[a-zA-Z0-9!@_#$%^&*()-=+,?.,]*$`, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := Init(tt.args); (err != nil) != tt.wantErr { | ||
t.Errorf("Init() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestLoadFromYaml(t *testing.T) { | ||
type ValidateConfig struct { | ||
OwnerRegexp string `json:"OWNER_REGEXP" required:"true"` | ||
RepoNameRegexp string `json:"REPONAME_REGEXP" required:"true"` | ||
UsernameRegexp string `json:"USERNAME_REGEXP" required:"true"` | ||
PasswordRegexp string `json:"PASSWORD_REGEXP" required:"true"` | ||
} | ||
type Config struct { | ||
Prefix string `json:"PATH_PREFIX"` | ||
LfsBucket string `json:"LFS_BUCKET"` | ||
ClientId string `json:"CLIENT_ID"` | ||
ClientSecret string `json:"CLIENT_SECRET"` | ||
CdnDomain string `json:"CDN_DOMAIN"` | ||
ObsRegion string `json:"OBS_REGION"` | ||
ObsAccessKeyId string `json:"OBS_ACCESS_KEY_ID"` | ||
ObsSecretAccessKey string `json:"OBS_SECRET_ACCESS_KEY"` | ||
ValidateConfig ValidateConfig `json:"VALIDATE_REGEXP"` | ||
DefaultToken string `json:"DEFAULT_TOKEN"` | ||
} | ||
type args struct { | ||
path string | ||
cfg Config | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "TestLoadFromYaml success", | ||
args: args{ | ||
path: "../config.example.yml", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "TestLoadFromYaml fail", | ||
args: args{ | ||
path: "../missing_config.yml", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := LoadFromYaml(tt.args.path, tt.args.cfg); (err != nil) != tt.wantErr { | ||
t.Errorf("LoadFromYaml() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |