github.com/aliyun/credentials-go@v1.4.7/credentials/credential_updater_test.go (about) 1 package credentials 2 3 import ( 4 "errors" 5 "net/http" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func Test_needUpdateCredential(t *testing.T) { 12 updater := &credentialUpdater{ 13 lastUpdateTimestamp: 100, 14 credentialExpiration: 200, 15 } 16 isNeed := updater.needUpdateCredential() 17 assert.True(t, isNeed) 18 } 19 20 func Test_hookdo(t *testing.T) { 21 fn := func(req *http.Request) (*http.Response, error) { 22 return nil, errors.New("hookdo") 23 } 24 result := hookDo(fn) 25 resp, err := result(nil) 26 assert.Nil(t, resp) 27 assert.Equal(t, "hookdo", err.Error()) 28 }