Skip to content

Commit

Permalink
remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed Aug 8, 2024
1 parent 892c72d commit 85fea92
Showing 1 changed file with 2 additions and 180 deletions.
182 changes: 2 additions & 180 deletions mail/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mail

import (
"context"
"fmt"
"os"
"testing"
"time"
Expand All @@ -11,14 +10,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"

"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/log"
"github.com/goravel/framework/contracts/mail"
queuecontract "github.com/goravel/framework/contracts/queue"
configmock "github.com/goravel/framework/mocks/config"
logmock "github.com/goravel/framework/mocks/log"
"github.com/goravel/framework/queue"
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/support/color"
testingdocker "github.com/goravel/framework/support/docker"
"github.com/goravel/framework/support/env"
Expand Down Expand Up @@ -130,7 +126,7 @@ func (s *ApplicationTestSuite) TestQueueMail() {

func (s *ApplicationTestSuite) TestQueueMailWithConnection() {
mockConfig := mockConfig(587, s.redisPort)
mockLog := NewTestLog()
mockLog := &logmock.Log{}

queueFacade := queue.NewApplication(mockConfig, mockLog)
queueFacade.Register([]queuecontract.Job{
Expand Down Expand Up @@ -190,7 +186,7 @@ func (s *ApplicationTestSuite) TestQueueMailWithMailable() {
func mockConfig(mailPort, redisPort int) *configmock.Config {
mockConfig := &configmock.Config{}
mockConfig.On("GetString", "app.name").Return("goravel")
mockConfig.On("GetBool", "app.debug").Return(true)
mockConfig.On("GetBool", "app.debug").Return(false)
mockConfig.On("GetString", "queue.default").Return("redis")
mockConfig.On("GetString", "queue.connections.sync.driver").Return("sync")
mockConfig.On("GetString", "queue.connections.redis.driver").Return("redis")
Expand Down Expand Up @@ -275,177 +271,3 @@ func (m *TestMailable) Envelope() *mail.Envelope {
func (m *TestMailable) Queue() *mail.Queue {
return &mail.Queue{}
}

type TestLog struct {
*TestLogWriter
}

func NewTestLog() log.Log {
return &TestLog{
TestLogWriter: NewTestLogWriter(),
}
}

func (r *TestLog) WithContext(ctx context.Context) log.Writer {
return NewTestLogWriter()
}

func (r *TestLog) Channel(channel string) log.Writer {
return NewTestLogWriter()
}

func (r *TestLog) Stack(channels []string) log.Writer {
return NewTestLogWriter()
}

type TestLogWriter struct {
data map[string]any
}

func NewTestLogWriter() *TestLogWriter {
return &TestLogWriter{
data: make(map[string]any),
}
}

func (r *TestLogWriter) Debug(args ...any) {
fmt.Print(prefix("debug"))
fmt.Println(args...)
r.printData()
}

func (r *TestLogWriter) Debugf(format string, args ...any) {
fmt.Print(prefix("debug"))
fmt.Printf(format+"\n", args...)
r.printData()
}

func (r *TestLogWriter) Info(args ...any) {
fmt.Print(prefix("info"))
fmt.Println(args...)
r.printData()
}

func (r *TestLogWriter) Infof(format string, args ...any) {
fmt.Print(prefix("info"))
fmt.Printf(format+"\n", args...)
r.printData()
}

func (r *TestLogWriter) Warning(args ...any) {
fmt.Print(prefix("warning"))
fmt.Println(args...)
r.printData()
}

func (r *TestLogWriter) Warningf(format string, args ...any) {
fmt.Print(prefix("warning"))
fmt.Printf(format+"\n", args...)
r.printData()
}

func (r *TestLogWriter) Error(args ...any) {
fmt.Print(prefix("error"))
fmt.Println(args...)
r.printData()
}

func (r *TestLogWriter) Errorf(format string, args ...any) {
fmt.Print(prefix("error"))
fmt.Printf(format+"\n", args...)
r.printData()
}

func (r *TestLogWriter) Fatal(args ...any) {
fmt.Print(prefix("fatal"))
fmt.Println(args...)
r.printData()
}

func (r *TestLogWriter) Fatalf(format string, args ...any) {
fmt.Print(prefix("fatal"))
fmt.Printf(format+"\n", args...)
r.printData()
}

func (r *TestLogWriter) Panic(args ...any) {
fmt.Print(prefix("panic"))
fmt.Println(args...)
r.printData()
}

func (r *TestLogWriter) Panicf(format string, args ...any) {
fmt.Print(prefix("panic"))
fmt.Printf(format+"\n", args...)
r.printData()
}

func (r *TestLogWriter) User(user any) log.Writer {
r.data["user"] = user

return r
}

func (r *TestLogWriter) Owner(owner any) log.Writer {
r.data["owner"] = owner

return r
}

func (r *TestLogWriter) Hint(hint string) log.Writer {
r.data["hint"] = hint

return r
}

func (r *TestLogWriter) Code(code string) log.Writer {
r.data["code"] = code

return r
}

func (r *TestLogWriter) With(data map[string]any) log.Writer {
r.data["with"] = data

return r
}

func (r *TestLogWriter) Tags(tags ...string) log.Writer {
r.data["tags"] = tags

return r
}

func (r *TestLogWriter) WithTrace() log.Writer {
return r
}

func (r *TestLogWriter) Request(req http.ContextRequest) log.Writer {
r.data["request"] = req

return r
}

func (r *TestLogWriter) Response(res http.ContextResponse) log.Writer {
r.data["response"] = res

return r
}

func (r *TestLogWriter) In(domain string) log.Writer {
r.data["in"] = domain

return r
}

func (r *TestLogWriter) printData() {
if len(r.data) > 0 {
fmt.Println(r.data)
}
}

func prefix(model string) string {
timestamp := carbon.Now().ToDateTimeString()

return fmt.Sprintf("[%s] %s.%s: ", timestamp, "test", model)
}

0 comments on commit 85fea92

Please sign in to comment.