Skip to content

Commit

Permalink
fix: lint and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ffforest committed Nov 12, 2024
1 parent e43153e commit 5535fab
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 16 deletions.
6 changes: 4 additions & 2 deletions pkg/domain/constant/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"fmt"
)

type RunType string
type RunStatus string
type (
RunType string
RunStatus string
)

const (
RunTypeGenerate RunType = "Generate"
Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/entity/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ func (r *Run) Validate() error {
return nil
}

func (s *Run) Summary() string {
return fmt.Sprintf("[%s][%s]", string(s.Type), string(s.Status))
func (r *Run) Summary() string {
return fmt.Sprintf("[%s][%s]", string(r.Type), string(r.Status))
}
1 change: 1 addition & 0 deletions pkg/infra/persistence/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestProjectRepository(t *testing.T) {
Name: "mockedProject",
Source: &entity.Source{
ID: 1,
Name: "mockedSource",
SourceProvider: constant.SourceProviderTypeGithub,
Remote: mockRemoteURL,
},
Expand Down
1 change: 1 addition & 0 deletions pkg/infra/persistence/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestSourceRepository(t *testing.T) {
var (
expectedID, expectedRows uint = 1, 1
actual = entity.Source{
Name: "mockedSource",
SourceProvider: constant.SourceProviderTypeOCI,
Remote: mockRemoteURL,
Description: "i am a description",
Expand Down
1 change: 1 addition & 0 deletions pkg/infra/persistence/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestStackRepository(t *testing.T) {
Path: "/path/to/project",
Source: &entity.Source{
ID: 1,
Name: "mockedSource",
SourceProvider: constant.SourceProviderTypeGithub,
Remote: mockRemoteURL,
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/handler/project/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func TestProjectHandler(t *testing.T) {
req.Header.Add("Content-Type", "application/json")

sqlMock.ExpectQuery("SELECT").
WillReturnRows(sqlmock.NewRows([]string{"id", "remote", "source_provider"}).
AddRow(1, "https://github.com/test/repo", constant.SourceProviderTypeGithub))
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "remote", "source_provider"}).
AddRow(1, "test-source", "https://github.com/test/repo", constant.SourceProviderTypeGithub))
sqlMock.ExpectQuery("SELECT").
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "owners"}).
AddRow(1, "test-org", owners))
Expand Down Expand Up @@ -170,8 +170,8 @@ func TestProjectHandler(t *testing.T) {
req.Header.Add("Content-Type", "application/json")

sqlMock.ExpectQuery("SELECT").
WillReturnRows(sqlmock.NewRows([]string{"id", "remote", "source_provider"}).
AddRow(1, "https://github.com/test/repo", constant.SourceProviderTypeGithub))
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "remote", "source_provider"}).
AddRow(1, "test-source", "https://github.com/test/repo", constant.SourceProviderTypeGithub))
sqlMock.ExpectQuery("SELECT").
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "owners"}).
AddRow(1, "test-org", owners))
Expand Down
1 change: 1 addition & 0 deletions pkg/server/handler/source/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestSourceHandler(t *testing.T) {
// Set request body
requestPayload := request.CreateSourceRequest{
// Set your request payload fields here
Name: "test-source",
SourceProvider: string(constant.SourceProviderTypeGithub),
Remote: "https://github.com/test/remote",
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/handler/stack/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func TestStackHandler(t *testing.T) {
req.Header.Add("Content-Type", "application/json")

sqlMock.ExpectQuery("SELECT").
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "path", "Organization__id", "Organization__name", "Organization__owners", "Source__id", "Source__remote", "Source__source_provider"}).
AddRow(1, projectName, projectPath, 1, "test-org", owners, 1, "https://github.com/test/repo", constant.SourceProviderTypeGithub))
WillReturnRows(sqlmock.NewRows([]string{"id", "name", "path", "Organization__id", "Organization__name", "Organization__owners", "Source__id", "Source__name", "Source__remote", "Source__source_provider"}).
AddRow(1, projectName, projectPath, 1, "test-org", owners, 1, "test-source", "https://github.com/test/repo", constant.SourceProviderTypeGithub))
sqlMock.ExpectBegin()
sqlMock.ExpectExec("INSERT").
WillReturnResult(sqlmock.NewResult(int64(1), int64(1)))
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/handler/stack/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func (h *Handler) GetRunResult() http.HandlerFunc {
handler.HandleResult(w, r, ctx, err, existingEntity)
return
}
var resultJson any
err = json.Unmarshal([]byte(existingEntity.Result), &resultJson)
handler.HandleResult(w, r, ctx, err, resultJson)
var resultJSON any
err = json.Unmarshal([]byte(existingEntity.Result), &resultJSON)
handler.HandleResult(w, r, ctx, err, resultJSON)
}
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/server/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
)

// APILoggerKey is a context key used for associating a logger with a request.
var APILoggerKey = &contextKey{"logger"}
var RunLoggerKey = &contextKey{"runLogger"}
var RunLoggerBufferKey = &contextKey{"runLoggerBuffer"}
var (
APILoggerKey = &contextKey{"logger"}
RunLoggerKey = &contextKey{"runLogger"}
RunLoggerBufferKey = &contextKey{"runLoggerBuffer"}
)

func InitLogger(logFilePath string, name string) *httplog.Logger {
logWriter, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
Expand Down

0 comments on commit 5535fab

Please sign in to comment.