Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Trojan295 committed Sep 24, 2024
1 parent 570d909 commit 1974b6e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 73 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module cloud-proxy
go 1.23.1

require (
cloud.google.com/go/compute v1.28.0
cloud.google.com/go/container v1.39.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -56,7 +55,6 @@ require (
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ cloud.google.com/go/auth v0.9.3 h1:VOEUIAADkkLtyfr3BLa3R8Ed/j6w1jTBmARx+wb5w5U=
cloud.google.com/go/auth v0.9.3/go.mod h1:7z6VY+7h3KUdRov5F1i8NDP5ZzWKYmEPO842BgCsmTk=
cloud.google.com/go/auth/oauth2adapt v0.2.4 h1:0GWE/FUsXhf6C+jAkWgYm7X9tK8cuEIfy19DBn6B6bY=
cloud.google.com/go/auth/oauth2adapt v0.2.4/go.mod h1:jC/jOpwFP6JBxhB3P5Rr0a9HLMC/Pe3eaL4NmdvqPtc=
cloud.google.com/go/compute v1.28.0 h1:OPtBxMcheSS+DWfci803qvPly3d4w7Eu5ztKBcFfzwk=
cloud.google.com/go/compute v1.28.0/go.mod h1:DEqZBtYrDnD5PvjsKwb3onnhX+qjdCVM7eshj1XdjV4=
cloud.google.com/go/compute/metadata v0.5.0 h1:Zr0eK8JbFv6+Wi4ilXAR8FJ3wyNdpxHKJNPos6LTZOY=
cloud.google.com/go/compute/metadata v0.5.0/go.mod h1:aHnloV2TPI38yx4s9+wAZhHykWvVCfu7hQbF+9CWoiY=
cloud.google.com/go/container v1.39.0 h1:Q1oW01ENxkkG3uf1oYoTmHPdvP+yhFCIuCJ4mk2RwkQ=
Expand Down Expand Up @@ -201,8 +199,6 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eYDVe+YvyR7Yc2vJGkO5/0UxD0/jZU=
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:hL97c3SYopEHblzpxRL4lSs523++l8DYxGM1FQiYmb4=
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed h1:3RgNmBoI9MZhsj3QxC+AP/qQhNwpCLOvYDYYsFrhFt0=
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
Expand Down
135 changes: 68 additions & 67 deletions internal/proxy/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestClient_handleMessage(t *testing.T) {
// wantKeepAlive: int64(config.KeepAliveDefault),
// wantKeepAliveTimeout: int64(config.KeepAliveTimeoutDefault),
// wantErrCount: 1,
//},
//}.
}
for _, tt := range tests {
tt := tt
Expand Down Expand Up @@ -354,72 +354,73 @@ func TestClient_processHttpRequest(t *testing.T) {
}
}

func TestClient_sendKeepAlive(t *testing.T) {
t.Parallel()

type args struct {
tuneMockStream func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient)
keepAlive int64
keepAliveTimeout int64
}
tests := []struct {
name string
args args
isLastSeenZero bool
}{
//{
// name: "end of ticker",
// args: args{
// keepAlive: 0,
// tuneMockStream: func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient) {
// m.EXPECT().Send(gomock.Any()).Return(nil).AnyTimes()
// m.EXPECT().Context().Return(context.Background()).AnyTimes()
// },
// },
//},
//{
// name: "send returned error, should exit",
// args: args{
// tuneMockStream: func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient) {
// m.EXPECT().Send(gomock.Any()).Return(fmt.Errorf("error"))
// m.EXPECT().Context().Return(context.Background()).AnyTimes()
// },
// keepAlive: int64(time.Second),
// keepAliveTimeout: int64(10 * time.Minute),
// },
// isLastSeenZero: true,
//},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
defer ctrl.Finish()

c := New(nil, nil, logrus.New(), "podName", "clusterID",
"version", "apiKey", config.KeepAliveDefault, config.KeepAliveTimeoutDefault)
c.keepAlive.Store(tt.args.keepAlive)
c.keepAliveTimeout.Store(tt.args.keepAliveTimeout)

stream := mock_proxy.NewMockCloudProxyAPI_StreamCloudProxyClient(ctrl)
if tt.args.tuneMockStream != nil {
tt.args.tuneMockStream(stream)
}
c.lastSeen.Store(time.Now().UnixNano())

kaCh := make(chan *cloudproxyv1alpha.StreamCloudProxyRequest)
go func() {
for {
<-kaCh
}
}()

c.sendKeepAlive(stream, kaCh)
require.Equal(t, tt.isLastSeenZero, c.lastSeen.Load() == 0, "lastSeen: %v", c.lastSeen.Load())
})
}
}
// nolint
//func TestClient_sendKeepAlive(t *testing.T) {
// t.Parallel()
//
// type args struct {
// tuneMockStream func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient)
// keepAlive int64
// keepAliveTimeout int64
// }
// tests := []struct {
// name string
// args args
// isLastSeenZero bool
// }{
// {
// name: "end of ticker",
// args: args{
// keepAlive: 0,
// tuneMockStream: func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient) {
// m.EXPECT().Send(gomock.Any()).Return(nil).AnyTimes()
// m.EXPECT().Context().Return(context.Background()).AnyTimes()
// },
// },
// },
// {
// name: "send returned error, should exit",
// args: args{
// tuneMockStream: func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient) {
// m.EXPECT().Send(gomock.Any()).Return(fmt.Errorf("error"))
// m.EXPECT().Context().Return(context.Background()).AnyTimes()
// },
// keepAlive: int64(time.Second),
// keepAliveTimeout: int64(10 * time.Minute),
// },
// isLastSeenZero: true,
// },
// }
// for _, tt := range tests {
// tt := tt
// t.Run(tt.name, func(t *testing.T) {
// t.Parallel()
// ctrl := gomock.NewController(t)
// defer ctrl.Finish()
//
// c := New(nil, nil, logrus.New(), "podName", "clusterID",
// "version", "apiKey", config.KeepAliveDefault, config.KeepAliveTimeoutDefault)
// c.keepAlive.Store(tt.args.keepAlive)
// c.keepAliveTimeout.Store(tt.args.keepAliveTimeout)
//
// stream := mock_proxy.NewMockCloudProxyAPI_StreamCloudProxyClient(ctrl)
// if tt.args.tuneMockStream != nil {
// tt.args.tuneMockStream(stream)
// }
// c.lastSeen.Store(time.Now().UnixNano())
//
// kaCh := make(chan *cloudproxyv1alpha.StreamCloudProxyRequest)
// go func() {
// for {
// <-kaCh
// }
// }()
//
// c.sendKeepAlive(stream, kaCh)
// require.Equal(t, tt.isLastSeenZero, c.lastSeen.Load() == 0, "lastSeen: %v", c.lastSeen.Load())
// })
// }
//}.

func TestClient_run(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 1974b6e

Please sign in to comment.