Skip to content

Commit

Permalink
chore: enable goconst (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx authored Dec 13, 2024
1 parent 2d4b7e2 commit 6d29163
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 30 deletions.
7 changes: 6 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ linters:
- exhaustruct # TODO
- gci # TODO
- gocognit # TODO
- goconst # TODO
- gocyclo # TODO
- godox # TODO
- nestif # TODO
Expand All @@ -43,3 +42,9 @@ linters:
- stylecheck # TODO
- tagliatelle # TODO
- testpackage # TODO

linters-settings:
goconst:
ignore-tests: true
min-occurrences: 2
ignore-strings: '(true|false)' # regex
6 changes: 4 additions & 2 deletions libs/common/hwgrpc/panic_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type recoveryAssertService struct {
testpb.TestServiceServer
}

const PanicValue = "panic"

func (s *recoveryAssertService) Ping(ctx context.Context, ping *testpb.PingRequest) (*testpb.PingResponse, error) {
if ping.GetValue() == "panic" {
if ping.GetValue() == PanicValue {
panic("very bad thing happened")
}
return s.TestServiceServer.Ping(ctx, ping)
}

func (s *recoveryAssertService) PingList(ping *testpb.PingListRequest, stream testpb.TestService_PingListServer) error {
if ping.Value == "panic" {
if ping.Value == PanicValue {
panic("very bad thing happened")
}
return s.TestServiceServer.PingList(ping, stream)
Expand Down
12 changes: 6 additions & 6 deletions services/tasks-svc/internal/patient/aggregate/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestPatientAggregate_CreatePatient(t *testing.T) {

patientID := uuid.New()

patientHumanReadableIdentifier := "tester"
patientHumanReadableIdentifier := t.Name()
patientNotes := "test-notes"

patientAggregate := aggregate.NewPatientAggregate(patientID)
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestPatientAggregate_UpdateNotes(t *testing.T) {

patientID := uuid.New()

patientHumanReadableIdentifier := "tester"
patientHumanReadableIdentifier := t.Name()
initialPatientNotes := "test notes"
updatedPatientNotes := "test notes updated"

Expand Down Expand Up @@ -100,8 +100,8 @@ func TestPatientAggregate_UpdateHumanReadableIdentifier(t *testing.T) {

patientID := uuid.New()

initialPatientHumanReadableIdentifier := "tester"
updatedPatientHumanReadableIdentifier := "tester updated"
initialPatientHumanReadableIdentifier := t.Name()
updatedPatientHumanReadableIdentifier := t.Name() + " updated"

patientAggregate := aggregate.NewPatientAggregate(patientID)

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestPatientAggregate_DischargeReadmitPatient(t *testing.T) {
ctx = auth.ContextWithOrganizationID(ctx, uuid.New())

patientID := uuid.New()
patientHumanReadableIdentifier := "tester"
patientHumanReadableIdentifier := t.Name()
patientAggregate := aggregate.NewPatientAggregate(patientID)

MustApplyEvent(t, patientAggregate, func() (hwes.Event, error) {
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestPatientAggregate_AssignUnassignBed(t *testing.T) {
patientID := uuid.New()

newBedID := uuid.New()
patientHumanReadableIdentifier := "tester"
patientHumanReadableIdentifier := t.Name()
patientAggregate := aggregate.NewPatientAggregate(patientID)

MustApplyEvent(t, patientAggregate, func() (hwes.Event, error) {
Expand Down
6 changes: 3 additions & 3 deletions services/tasks-svc/internal/patient/api/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func TestPatientGrpcService_CreatePatient(t *testing.T) {
defer teardown()

// First, create a new Patient
humanReadableIdentifier := "Test patient"
notes := "notes"
humanReadableIdentifier := t.Name() + " patient"
notes := t.Name()

createPatientResponse, err := client.CreatePatient(ctx, &pb.CreatePatientRequest{
HumanReadableIdentifier: humanReadableIdentifier,
Expand All @@ -117,7 +117,7 @@ func TestPatientGrpcService_UpdatePatient(t *testing.T) {

// Initial values
humanReadableIdentifier1 := "Test patient"
notes1 := "notes"
notes1 := t.Name()

// First, create a new patient
createPatientResponse, err := client.CreatePatient(ctx,
Expand Down
18 changes: 9 additions & 9 deletions services/tasks-svc/internal/task/aggregate/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestTaskAggregate_UpdateName(t *testing.T) {
taskID := uuid.New()
patientID := uuid.New()

initialTaskName := "Test Task"
updatedTaskName := "Test Task Updated"
initialTaskName := t.Name()
updatedTaskName := t.Name() + " Updated"

taskAggregate := aggregate.NewTaskAggregate(taskID)

Expand Down Expand Up @@ -72,7 +72,7 @@ func TestTaskAggregate_UpdateDescription(t *testing.T) {
patientID := uuid.New()

initialTaskDescription := ""
updatedTaskDescription := "Text text"
updatedTaskDescription := t.Name()

taskAggregate := aggregate.NewTaskAggregate(taskID)

Expand All @@ -81,7 +81,7 @@ func TestTaskAggregate_UpdateDescription(t *testing.T) {
ctx,
taskAggregate,
taskID,
"Test task",
t.Name(),
patientID,
pb.TaskStatus_TASK_STATUS_TODO,
)
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestTaskAggregate_UpdateSubtaskName(t *testing.T) {
ctx,
taskAggregate,
taskID,
"Test task",
t.Name(),
patientID,
pb.TaskStatus_TASK_STATUS_TODO,
)
Expand Down Expand Up @@ -155,8 +155,8 @@ func TestTaskAggregate_CompleteSubtask(t *testing.T) {
subtaskID := uuid.New()
patientID := uuid.New()

taskName := "Test Task"
subtaskName := "Test Subtask"
taskName := t.Name()
subtaskName := t.Name() + " Subtask"

taskAggregate := aggregate.NewTaskAggregate(taskID)

Expand Down Expand Up @@ -206,7 +206,7 @@ func TestTaskAggregate_AssignTask(t *testing.T) {
taskID := uuid.New()
patientID := uuid.New()

taskName := "Test Task"
taskName := t.Name()

taskAggregate := aggregate.NewTaskAggregate(taskID)

Expand Down Expand Up @@ -239,7 +239,7 @@ func TestTaskAggregate_DeleteTask(t *testing.T) {
taskID := uuid.New()
patientID := uuid.New()

taskName := "Test Task"
taskName := t.Name()

taskAggregate := aggregate.NewTaskAggregate(taskID)

Expand Down
2 changes: 1 addition & 1 deletion services/tasks-svc/internal/task/api/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestTaskGrpcService_CreateTask_Validation(t *testing.T) {
ctx, client, teardown := setup()
defer teardown()

taskName := "Test task"
taskName := t.Name()

// patientID empty -> Error
_, err := client.CreateTask(ctx, &pb.CreateTaskRequest{
Expand Down
11 changes: 7 additions & 4 deletions services/tasks-svc/stories/PatientCRUD_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,20 @@ func TestGetPatientList(t *testing.T) {
// Create tasks
//

ST1 := "ST 1"
ST2 := "ST 2"

task1Res, err := taskClient.CreateTask(ctx, &pb.CreateTaskRequest{
Name: t.Name() + " task 1",
PatientId: patient1Id,
Public: hwutil.PtrTo(true),
Subtasks: []*pb.CreateTaskRequest_SubTask{
{
Name: "ST 1",
Name: ST1,
Done: hwutil.PtrTo(true),
},
{
Name: "ST 2",
Name: ST2,
},
},
})
Expand Down Expand Up @@ -482,11 +485,11 @@ func TestGetPatientList(t *testing.T) {
assert.Len(t, patient.Tasks[0].Subtasks, 2)
f := 0
for _, st := range patient.Tasks[0].Subtasks {
if st.Name == "ST 1" {
if st.Name == ST1 {
f++
assert.True(t, st.Done)
}
if st.Name == "ST 2" {
if st.Name == ST2 {
f++
assert.False(t, st.Done)
}
Expand Down
12 changes: 8 additions & 4 deletions services/tasks-svc/stories/TaskCRUD_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestCreateUpdateGetTask(t *testing.T) {
//
// create new task
//

ST1 := "SubTask 1"
ST2 := "SubTask 2"

createReq := &pb.CreateTaskRequest{
Name: t.Name() + " task",
Description: hwutil.PtrTo("Some Description"),
Expand All @@ -39,8 +43,8 @@ func TestCreateUpdateGetTask(t *testing.T) {
InitialStatus: nil,
AssignedUserId: nil,
Subtasks: []*pb.CreateTaskRequest_SubTask{
{Name: "ST 1"},
{Name: "ST 2", Done: hwutil.PtrTo(true)},
{Name: ST1},
{Name: ST2, Done: hwutil.PtrTo(true)},
},
}
createRes, err := taskClient.CreateTask(ctx, createReq)
Expand Down Expand Up @@ -70,12 +74,12 @@ func TestCreateUpdateGetTask(t *testing.T) {
assert.Len(t, task.GetSubtasks(), 2)
found := 0
for _, st := range task.GetSubtasks() {
if st.Name == "ST 1" {
if st.Name == ST1 {
found++
assert.False(t, st.GetDone())
assert.Equal(t, hwtesting.FakeTokenUser, st.GetCreatedBy())
}
if st.Name == "ST 2" {
if st.Name == ST2 {
found++
assert.True(t, st.GetDone())
assert.Equal(t, hwtesting.FakeTokenUser, st.GetCreatedBy())
Expand Down

0 comments on commit 6d29163

Please sign in to comment.