package main
import (
"net/http"
"sync"
"time"
)
type SessionInterface1 interface {
doLoginAndReadDestinations1() bool
}
type Session1 struct {
sessionCookie string
mux sync.Mutex
sessionTime time.Time
targetAddress string
currentJwt string
transport *http.Transport
}
var currentSession1 Session1
func main() {
currentSession1.verifyLogin1()
}
func (s *Session1) doLoginAndReadDestinations1() bool {
..logic...
... for example return true
}
func callDest1(si SessionInterface1) bool {
return si.doLoginAndReadDestinations1()
}
func (s *Session1) verifyLogin1() bool {
return callDest1(s)
}
我想创建单元测试并模拟 doLoginAndReadDestinations1 我尝试为此方法创建接口并创建测试
func test1(t *testing.T) {
type args struct {
}
tests := []struct {
name string
args args
want bool
}{{
name: "test",
args: args{},
want: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var s1 *Session1
count := 10
s1 = &Session1{"", sync.Mutex{}, time.Now(), "", "", nil}
var got1 = s1.verifyLogin()
if got1 != tt.want {
t.Errorf("getJwt() = %v, want %v", got, tt.want)
}
})
}
}
我不知道如何在测试中更改函数 doLoginAndReadDestinations1 的逻辑并更改第一个 main 中的逻辑
跃然一笑
相关分类