forked from pipe-cd/pipecd
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display MySQL user defined error in API Key UI (pipe-cd#4590)
* Display MySQL user defined error in UI Signed-off-by: Kenta Kozuka <kenta.kozuka@gmail.com> * Fix Unexpected empty arrow function Signed-off-by: Kenta Kozuka <kenta.kozuka@gmail.com> * Add tests Signed-off-by: Kenta Kozuka <kenta.kozuka@gmail.com> * Run subtests in parallel Signed-off-by: Kenta Kozuka <kenta.kozuka@gmail.com> --------- Signed-off-by: Kenta Kozuka <kenta.kozuka@gmail.com>
- Loading branch information
1 parent
246308b
commit df22fb0
Showing
6 changed files
with
125 additions
and
14 deletions.
There are no files selected for viewing
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
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,92 @@ | ||
// Copyright 2023 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package grpcapi | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/pipe-cd/pipecd/pkg/datastore" | ||
"github.com/pipe-cd/pipecd/pkg/filestore" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func TestGRPCStoreError(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
inputErr error | ||
inputMsg string | ||
expected error | ||
}{ | ||
{ | ||
name: "datastore not found error", | ||
inputErr: datastore.ErrNotFound, | ||
inputMsg: "datastore", | ||
expected: status.Error(codes.NotFound, "Entity was not found to datastore"), | ||
}, | ||
{ | ||
name: "filestore not found error", | ||
inputErr: filestore.ErrNotFound, | ||
inputMsg: "filestore", | ||
expected: status.Error(codes.NotFound, "Entity was not found to filestore"), | ||
}, | ||
{ | ||
name: "stagelogstore not found error", | ||
inputErr: filestore.ErrNotFound, | ||
inputMsg: "stagelogstore", | ||
expected: status.Error(codes.NotFound, "Entity was not found to stagelogstore"), | ||
}, | ||
{ | ||
name: "datastore invalid argument error", | ||
inputErr: datastore.ErrInvalidArgument, | ||
inputMsg: "datastore", | ||
expected: status.Error(codes.InvalidArgument, "Invalid argument to datastore"), | ||
}, | ||
{ | ||
name: "datastore already exists error", | ||
inputErr: datastore.ErrAlreadyExists, | ||
inputMsg: "datastore", | ||
expected: status.Error(codes.AlreadyExists, "Entity already exists to datastore"), | ||
}, | ||
{ | ||
name: "user defined error", | ||
inputErr: datastore.ErrUserDefined, | ||
expected: status.Error(codes.FailedPrecondition, "user defined error"), | ||
}, | ||
{ | ||
name: "user defined error with message", | ||
inputErr: fmt.Errorf("%w: %s", datastore.ErrUserDefined, "test"), | ||
expected: status.Error(codes.FailedPrecondition, "user defined error: test"), | ||
}, | ||
{ | ||
name: "internal error", | ||
inputErr: errors.New("internal error"), | ||
inputMsg: "test", | ||
expected: status.Error(codes.Internal, "Failed to test"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
err := gRPCStoreError(tt.inputErr, tt.inputMsg) | ||
assert.Equal(t, tt.expected, err) | ||
}) | ||
} | ||
} |
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
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
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
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