Skip to content

Commit

Permalink
updated broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Jun 8, 2023
1 parent 3cf3e04 commit ebd6891
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions apis/api_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func TestNewApiErrorWithValidationData(t *testing.T) {
300,
"message_test",
validation.Errors{
"err1": errors.New("test error"),
"err1": errors.New("test error"), // should be normalized
"err2": validation.ErrRequired,
"err3": validation.Errors{
"sub1": errors.New("test error"),
"sub1": errors.New("test error"), // should be normalized
"sub2": validation.ErrRequired,
"sub3": validation.Errors{
"sub11": validation.ErrRequired,
Expand All @@ -50,10 +50,10 @@ func TestNewApiErrorWithValidationData(t *testing.T) {
)

result, _ := json.Marshal(e)
expected := `{"code":300,"message":"Message_test.","data":{"err1":{"code":"validation_invalid_value","message":"Test error."},"err2":{"code":"validation_required","message":"Cannot be blank."},"err3":{"sub1":{"code":"validation_invalid_value","message":"Test error."},"sub2":{"code":"validation_required","message":"Cannot be blank."},"sub3":{"sub11":{"code":"validation_required","message":"Cannot be blank."}}}}}`
expected := `{"code":300,"message":"Message_test.","data":{"err1":{"code":"validation_invalid_value","message":"Invalid value."},"err2":{"code":"validation_required","message":"Cannot be blank."},"err3":{"sub1":{"code":"validation_invalid_value","message":"Invalid value."},"sub2":{"code":"validation_required","message":"Cannot be blank."},"sub3":{"sub11":{"code":"validation_required","message":"Cannot be blank."}}}}}`

if string(result) != expected {
t.Errorf("Expected %v, got %v", expected, string(result))
t.Errorf("Expected \n%v, \ngot \n%v", expected, string(result))
}

if e.Error() != "Message_test." {
Expand All @@ -73,15 +73,15 @@ func TestNewNotFoundError(t *testing.T) {
}{
{"", nil, `{"code":404,"message":"The requested resource wasn't found.","data":{}}`},
{"demo", "rawData_test", `{"code":404,"message":"Demo.","data":{}}`},
{"demo", validation.Errors{"err1": errors.New("test error")}, `{"code":404,"message":"Demo.","data":{"err1":{"code":"validation_invalid_value","message":"Test error."}}}`},
{"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"code":404,"message":"Demo.","data":{"err1":{"code":"test_code","message":"Test_message."}}}`},
}

for i, scenario := range scenarios {
e := apis.NewNotFoundError(scenario.message, scenario.data)
result, _ := json.Marshal(e)

if string(result) != scenario.expected {
t.Errorf("(%d) Expected %v, got %v", i, scenario.expected, string(result))
t.Errorf("(%d) Expected \n%v, \ngot \n%v", i, scenario.expected, string(result))
}
}
}
Expand All @@ -94,15 +94,15 @@ func TestNewBadRequestError(t *testing.T) {
}{
{"", nil, `{"code":400,"message":"Something went wrong while processing your request.","data":{}}`},
{"demo", "rawData_test", `{"code":400,"message":"Demo.","data":{}}`},
{"demo", validation.Errors{"err1": errors.New("test error")}, `{"code":400,"message":"Demo.","data":{"err1":{"code":"validation_invalid_value","message":"Test error."}}}`},
{"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"code":400,"message":"Demo.","data":{"err1":{"code":"test_code","message":"Test_message."}}}`},
}

for i, scenario := range scenarios {
e := apis.NewBadRequestError(scenario.message, scenario.data)
result, _ := json.Marshal(e)

if string(result) != scenario.expected {
t.Errorf("(%d) Expected %v, got %v", i, scenario.expected, string(result))
t.Errorf("(%d) Expected \n%v, \ngot \n%v", i, scenario.expected, string(result))
}
}
}
Expand All @@ -115,15 +115,15 @@ func TestNewForbiddenError(t *testing.T) {
}{
{"", nil, `{"code":403,"message":"You are not allowed to perform this request.","data":{}}`},
{"demo", "rawData_test", `{"code":403,"message":"Demo.","data":{}}`},
{"demo", validation.Errors{"err1": errors.New("test error")}, `{"code":403,"message":"Demo.","data":{"err1":{"code":"validation_invalid_value","message":"Test error."}}}`},
{"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"code":403,"message":"Demo.","data":{"err1":{"code":"test_code","message":"Test_message."}}}`},
}

for i, scenario := range scenarios {
e := apis.NewForbiddenError(scenario.message, scenario.data)
result, _ := json.Marshal(e)

if string(result) != scenario.expected {
t.Errorf("(%d) Expected %v, got %v", i, scenario.expected, string(result))
t.Errorf("(%d) Expected \n%v, \ngot \n%v", i, scenario.expected, string(result))
}
}
}
Expand All @@ -136,15 +136,15 @@ func TestNewUnauthorizedError(t *testing.T) {
}{
{"", nil, `{"code":401,"message":"Missing or invalid authentication token.","data":{}}`},
{"demo", "rawData_test", `{"code":401,"message":"Demo.","data":{}}`},
{"demo", validation.Errors{"err1": errors.New("test error")}, `{"code":401,"message":"Demo.","data":{"err1":{"code":"validation_invalid_value","message":"Test error."}}}`},
{"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"code":403,"message":"Demo.","data":{"err1":{"code":"test_code","message":"Test_message."}}}`},
}

for i, scenario := range scenarios {
e := apis.NewUnauthorizedError(scenario.message, scenario.data)
result, _ := json.Marshal(e)

if string(result) != scenario.expected {
t.Errorf("(%d) Expected %v, got %v", i, scenario.expected, string(result))
t.Errorf("(%d) Expected \n%v, \ngot \n%v", i, scenario.expected, string(result))
}
}
}
12 changes: 6 additions & 6 deletions core/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestNewBaseApp(t *testing.T) {
const testDataDir = "./pb_base_app_test_data_dir/"
defer os.RemoveAll(testDataDir)

app := NewBaseApp(&BaseAppConfig{
app := NewBaseApp(BaseAppConfig{
DataDir: testDataDir,
EncryptionEnv: "test_env",
IsDebug: true,
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestBaseAppBootstrap(t *testing.T) {
const testDataDir = "./pb_base_app_test_data_dir/"
defer os.RemoveAll(testDataDir)

app := NewBaseApp(&BaseAppConfig{
app := NewBaseApp(BaseAppConfig{
DataDir: testDataDir,
EncryptionEnv: "pb_test_env",
IsDebug: false,
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestBaseAppGetters(t *testing.T) {
const testDataDir = "./pb_base_app_test_data_dir/"
defer os.RemoveAll(testDataDir)

app := NewBaseApp(&BaseAppConfig{
app := NewBaseApp(BaseAppConfig{
DataDir: testDataDir,
EncryptionEnv: "pb_test_env",
IsDebug: false,
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestBaseAppNewMailClient(t *testing.T) {
const testDataDir = "./pb_base_app_test_data_dir/"
defer os.RemoveAll(testDataDir)

app := NewBaseApp(&BaseAppConfig{
app := NewBaseApp(BaseAppConfig{
DataDir: testDataDir,
EncryptionEnv: "pb_test_env",
IsDebug: false,
Expand All @@ -211,7 +211,7 @@ func TestBaseAppNewFilesystem(t *testing.T) {
const testDataDir = "./pb_base_app_test_data_dir/"
defer os.RemoveAll(testDataDir)

app := NewBaseApp(&BaseAppConfig{
app := NewBaseApp(BaseAppConfig{
DataDir: testDataDir,
EncryptionEnv: "pb_test_env",
IsDebug: false,
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestBaseAppNewBackupsFilesystem(t *testing.T) {
const testDataDir = "./pb_base_app_test_data_dir/"
defer os.RemoveAll(testDataDir)

app := NewBaseApp(&BaseAppConfig{
app := NewBaseApp(BaseAppConfig{
DataDir: testDataDir,
EncryptionEnv: "pb_test_env",
IsDebug: false,
Expand Down
10 changes: 5 additions & 5 deletions plugins/migratecmd/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func init() {

migrationsDir := filepath.Join(app.DataDir(), "_test_migrations")

migratecmd.MustRegister(app, nil, &migratecmd.Options{
migratecmd.MustRegister(app, nil, migratecmd.Config{
TemplateLang: s.lang,
Automigrate: true,
Dir: migrationsDir,
Expand Down Expand Up @@ -306,7 +306,7 @@ func init() {

migrationsDir := filepath.Join(app.DataDir(), "_test_migrations")

migratecmd.MustRegister(app, nil, &migratecmd.Options{
migratecmd.MustRegister(app, nil, migratecmd.Config{
TemplateLang: s.lang,
Automigrate: true,
Dir: migrationsDir,
Expand Down Expand Up @@ -630,7 +630,7 @@ func init() {

migrationsDir := filepath.Join(app.DataDir(), "_test_migrations")

migratecmd.MustRegister(app, nil, &migratecmd.Options{
migratecmd.MustRegister(app, nil, migratecmd.Config{
TemplateLang: s.lang,
Automigrate: true,
Dir: migrationsDir,
Expand Down Expand Up @@ -749,7 +749,7 @@ func TestAutomigrateCollectionNoChanges(t *testing.T) {

migrationsDir := filepath.Join(app.DataDir(), "_test_migrations")

migratecmd.MustRegister(app, nil, &migratecmd.Options{
migratecmd.MustRegister(app, nil, migratecmd.Config{
TemplateLang: s.lang,
Automigrate: true,
Dir: migrationsDir,
Expand Down Expand Up @@ -786,7 +786,7 @@ func TestInitialAutoSnapshot(t *testing.T) {

migrationsDir := filepath.Join(app.DataDir(), "_test_auto_snapshot_")

migratecmd.MustRegister(app, nil, &migratecmd.Options{
migratecmd.MustRegister(app, nil, migratecmd.Config{
TemplateLang: migratecmd.TemplateLangJS,
Automigrate: true,
Dir: migrationsDir,
Expand Down

0 comments on commit ebd6891

Please sign in to comment.