-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test to auth_grpc_client.go file in grpc package
Signed-off-by: punithnayak <[email protected]>
- Loading branch information
1 parent
28f9079
commit d65f743
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
chaoscenter/graphql/server/pkg/grpc/auth_grpc_client_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/protos" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type MockAuthRpcServiceClient struct{} | ||
|
||
func (m *MockAuthRpcServiceClient) ValidateRequest(ctx context.Context, req *protos.ValidationRequest, opts ...grpc.CallOption) (*protos.ValidationResponse, error) { | ||
// You can implement custom logic here for the mock, based on the input req | ||
if req.Invitation == "invalid-invitation" { | ||
return &protos.ValidationResponse{ | ||
IsValid: false, | ||
Error: "Invalid invitation", | ||
}, nil | ||
} | ||
return &protos.ValidationResponse{ | ||
IsValid: true, | ||
}, nil | ||
} | ||
|
||
func (m *MockAuthRpcServiceClient) GetProjectById(ctx context.Context, req *protos.GetProjectByIdRequest, opts ...grpc.CallOption) (*protos.GetProjectByIdResponse, error) { | ||
// Mock implementation for GetProjectById if needed | ||
return nil, nil | ||
} | ||
|
||
func (m *MockAuthRpcServiceClient) GetUserById(ctx context.Context, req *protos.GetUserByIdRequest, opts ...grpc.CallOption) (*protos.GetUserByIdResponse, error) { | ||
// Mock implementation for GetUserById if needed | ||
return nil, nil | ||
} | ||
|
||
func TestValidatorGRPCRequest_Valid(t *testing.T) { | ||
// Create a mock client | ||
mockClient := &MockAuthRpcServiceClient{} | ||
|
||
// Call the ValidatorGRPCRequest function with the mock client | ||
err := ValidatorGRPCRequest(mockClient, "mock-jwt", "mock-project-id", []string{"role1", "role2"}, "invitation") | ||
assert.NoError(t, err, "Expected no error when validation is successful") | ||
} | ||
|
||
func TestValidatorGRPCRequest_Invalid(t *testing.T) { | ||
// Create a mock client | ||
mockClient := &MockAuthRpcServiceClient{} | ||
|
||
// Call the ValidatorGRPCRequest function with the mock client, making it fail | ||
err := ValidatorGRPCRequest(mockClient, "mock-jwt", "mock-project-id", []string{"role1", "role2"}, "invalid-invitation") | ||
assert.Error(t, err, "Expected an error when validation fails") | ||
} | ||
|
||
// Additional tests can be written for other functions in the grpc package if required. |