Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Fixed unit tests and lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Prafulla Mahindrakar <[email protected]>
  • Loading branch information
pmahindrakar-oss committed Apr 27, 2021
1 parent 08ff527 commit bde6840
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/create/execution_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
func createExecutionUtilSetup() {
ctx = testutils.Ctx
cmdCtx = testutils.CmdCtx
mockClient = testutils.MockClient
mockClient = testutils.MockAdminClient
relaunchExecResponse = &admin.ExecutionCreateResponse{
Id: &core.WorkflowExecutionIdentifier{
Project: "flytesnacks",
Expand Down
11 changes: 4 additions & 7 deletions cmd/testutils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
Err error
Ctx context.Context
MockAdminClient *mocks.AdminServiceClient
MockAuthClient *mocks.AuthServiceClient
MockAuthClient *mocks.AuthMetadataServiceClient
mockOutStream io.Writer
CmdCtx cmdCore.CommandContext
stdOut *os.File
Expand All @@ -45,12 +45,9 @@ func Setup() {
os.Stdout = writer
os.Stderr = writer
log.SetOutput(writer)
MockAdminClient = new(mocks.AdminServiceClient)
MockAuthClient = new(mocks.AuthServiceClient)
clientSet := &admin.Clientset{
AdminServiceClient: MockAdminClient,
AuthServiceClient: MockAuthClient,
}
clientSet := admin.InitializeMockClientset()
MockAdminClient = clientSet.AdminClient().(*mocks.AdminServiceClient)
MockAuthClient = clientSet.AuthMetadataClient().(*mocks.AuthMetadataServiceClient)
mockOutStream = writer
CmdCtx = cmdCore.NewCommandContext(clientSet, mockOutStream)
config.GetConfig().Project = projectValue
Expand Down
12 changes: 5 additions & 7 deletions cmd/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ package version
import (
"context"
"fmt"
"io"
"testing"

cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/clients/go/admin/mocks"
"github.com/flyteorg/flytectl/cmd/testutils"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/stretchr/testify/assert"
)

func TestListExecutionFunc(t *testing.T) {
func TestGetVesionFunc(t *testing.T) {
testutils.Setup()
ctx := context.Background()
var args []string
mockClient := new(mocks.AdminServiceClient)
mockOutStream := new(io.Writer)
cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream)
mockClient := testutils.MockAdminClient
cmdCtx := testutils.CmdCtx
versionRequest := &admin.GetVersionRequest{}
versionResponse := &admin.GetVersionResponse{
ControlPlaneVersion: &admin.Version{
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ require (
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.2.0
)

replace github.com/flyteorg/flyteidl => github.com/flyteorg/flyteidl v0.18.33-0.20210423201418-1de143785fd8
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ github.com/coocood/freecache v1.1.1 h1:uukNF7QKCZEdZ9gAV7WQzvh0SbjwdMF6m3x3rxEka
github.com/coocood/freecache v1.1.1/go.mod h1:OKrEjkGVoxZhyWAJoeFi5BMLUJm2Tit0kpGkIr7NGYY=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-oidc v2.1.0+incompatible h1:sdJrfw8akMnCuUlaZU3tE/uYXFgfqom8DBE9so9EBsM=
github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down Expand Up @@ -175,8 +173,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/flyteorg/flyteidl v0.18.33-0.20210412051034-809716b9461b h1:VegXFZO3vmGNzi7pV4uN0UCU1BKxZ3XfOGuXDHaf2RE=
github.com/flyteorg/flyteidl v0.18.33-0.20210412051034-809716b9461b/go.mod h1:b5Fq4Z8a5b0mF6pEwTd48ufvikUGVkWSjZiMT0ZtqKI=
github.com/flyteorg/flyteidl v0.18.33-0.20210423201418-1de143785fd8 h1:HEe+GZaUcXslKsY7fa+rbDMIwtGSC79I4QUa1T6XX7A=
github.com/flyteorg/flyteidl v0.18.33-0.20210423201418-1de143785fd8/go.mod h1:JjfUhaEeOJJ2ozVdjgj+X0zqWoI9ULEb60do3+2R1fo=
github.com/flyteorg/flytestdlib v0.3.13/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220=
github.com/flyteorg/flytestdlib v0.3.15 h1:vzsfqriENyavv6EBwsIm55di2wC+j0jkmjw30JGHAkM=
github.com/flyteorg/flytestdlib v0.3.15/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220=
Expand Down Expand Up @@ -480,8 +478,6 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/pquerna/ffjson v0.0.0-20190813045741-dac163c6c0a9/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
Expand Down Expand Up @@ -990,8 +986,6 @@ gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/kothar/go-backblaze.v0 v0.0.0-20190520213052-702d4e7eb465/go.mod h1:zJ2QpyDCYo1KvLXlmdnFlQAyF/Qfth0fB8239Qg7BIE=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/square/go-jose.v2 v2.4.1 h1:H0TmLt7/KmzlrDOpa1F+zr0Tk90PbJYBfsVUmRLrf9Y=
gopkg.in/square/go-jose.v2 v2.4.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
Expand Down
20 changes: 12 additions & 8 deletions pkg/auth/admin_grpc_call_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/flyteorg/flytectl/cmd/testutils"
"github.com/flyteorg/flytectl/pkg/auth/interfaces/mocks"
"github.com/flyteorg/flyteidl/clients/go/admin"
adminMocks "github.com/flyteorg/flyteidl/clients/go/admin/mocks"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service"

"github.com/stretchr/testify/assert"
Expand All @@ -24,7 +25,7 @@ var setup = testutils.Setup

var (
ctx context.Context
authClient service.AuthServiceClient
authMetadataClient *adminMocks.AuthMetadataServiceClient
grpcAPICallContext AdminGrpcAPICallContext
callOptions []grpc.CallOption
useAuth bool
Expand All @@ -33,19 +34,22 @@ var (

func GrpcCallUtilSetup() {
ctx = testutils.Ctx
authClient = testutils.MockAuthClient
authMetadataClient = testutils.MockAuthClient
useAuth = false
mockTokenOrchestrator = &mocks.FetchTokenOrchestrator{}
defaultTokenOrchestrator = mockTokenOrchestrator
grpcAPICallContext = func(ctx context.Context, callOptions []grpc.CallOption) error {
return nil
}
authMetadataClient.OnFlyteClientMatch(mock.Anything, mock.Anything).Return(&service.FlyteClientResponse{
AuthorizationMetadataKey: "flyte_authorization",
}, nil)
}

func TestDo(t *testing.T) {
setup()
GrpcCallUtilSetup()
err := Do(ctx, authClient, grpcAPICallContext, callOptions)
err := Do(ctx, authMetadataClient, grpcAPICallContext, callOptions)
assert.Nil(t, err)
}

Expand All @@ -55,7 +59,7 @@ func TestDoWithNonAuthError(t *testing.T) {
grpcAPICallContext = func(ctx context.Context, callOptions []grpc.CallOption) error {
return fmt.Errorf("nonAuthError")
}
err := Do(ctx, authClient, grpcAPICallContext, callOptions)
err := Do(ctx, authMetadataClient, grpcAPICallContext, callOptions)
assert.NotNil(t, err)
assert.Equal(t, err, fmt.Errorf("nonAuthError"))
}
Expand All @@ -66,7 +70,7 @@ func TestDoWithAuthErrorWithClientAuthDisabled(t *testing.T) {
grpcAPICallContext = func(ctx context.Context, callOptions []grpc.CallOption) error {
return status.New(codes.Unauthenticated, "empty identity").Err()
}
err := Do(ctx, authClient, grpcAPICallContext, callOptions)
err := Do(ctx, authMetadataClient, grpcAPICallContext, callOptions)
assert.NotNil(t, err)
s, ok := status.FromError(err)
assert.True(t, ok)
Expand All @@ -88,7 +92,7 @@ func TestDoWithAuthErrorWithClientAuthEnabled(t *testing.T) {
mockTokenOrchestrator.OnFetchTokenFromAuthFlowMatch(mock.Anything, mock.Anything, mock.Anything).Return(token, nil)
mockTokenOrchestrator.OnFetchTokenFromCacheOrRefreshItMatch(mock.Anything, mock.Anything).Return(token)
mockTokenOrchestrator.OnRefreshTheTokenMatch(mock.Anything, mock.Anything, mock.Anything).Return(token)
err := Do(ctx, authClient, grpcAPICallContext, callOptions)
err := Do(ctx, authMetadataClient, grpcAPICallContext, callOptions)
assert.NotNil(t, err)
assert.Equal(t, err, status.New(codes.Unauthenticated, "empty identity").Err())
}
Expand All @@ -104,7 +108,7 @@ func TestDoWithAuthErrorWithClientAuthEnabledAndError(t *testing.T) {
mockTokenOrchestrator.OnFetchTokenFromAuthFlowMatch(mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("failed to fetch token using auth flow"))
mockTokenOrchestrator.OnFetchTokenFromCacheOrRefreshItMatch(mock.Anything, mock.Anything).Return(nil)
mockTokenOrchestrator.OnRefreshTheTokenMatch(mock.Anything, mock.Anything, mock.Anything).Return(nil)
err := Do(ctx, authClient, grpcAPICallContext, callOptions)
err := Do(ctx, authMetadataClient, grpcAPICallContext, callOptions)
assert.NotNil(t, err)
assert.Equal(t, err, errors.New("failed to fetch token using auth flow"))
}
Expand All @@ -124,7 +128,7 @@ func TestDoWithAuthErrorWithClientAuthEnabledInsecureCreds(t *testing.T) {
mockTokenOrchestrator.OnFetchTokenFromAuthFlowMatch(mock.Anything, mock.Anything, mock.Anything).Return(token, nil)
mockTokenOrchestrator.OnFetchTokenFromCacheOrRefreshItMatch(mock.Anything, mock.Anything).Return(token)
mockTokenOrchestrator.OnRefreshTheTokenMatch(mock.Anything, mock.Anything, mock.Anything).Return(token)
err := Do(ctx, authClient, grpcAPICallContext, callOptions)
err := Do(ctx, authMetadataClient, grpcAPICallContext, callOptions)
assert.NotNil(t, err)
assert.Equal(t, err, status.New(codes.Unauthenticated, "empty identity").Err())
}
32 changes: 16 additions & 16 deletions pkg/auth/interfaces/mocks/fetch_token_orchestrator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bde6840

Please sign in to comment.