Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ install:
- go mod tidy

script:
- go build -o bin/crasher cmd/crasher/main.go
- go test -v -race ./...
- golangci-lint run ./...
- make all

17 changes: 11 additions & 6 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ BINARY_NAME=crasher
BIN_PATH=bin/
LINTER=golangci-lint

.ONESHELL: test build lint all
.PHONY: test build lint all
.ONESHELL: test build lint all run
.PHONY: test build lint all run

all: test build lint

test:
@go test ./...
all: build test lint

build:
@go build -o $(BIN_PATH)$(BINARY_NAME) cmd/crasher/main.go

test:
@go test -v -race -cover ./...

lint:
@$(LINTER) run ./...

run:
@export CRASHER_SERVER_ADDRESS=:8080
@go run cmd/crasher/main.go

13 changes: 11 additions & 2 deletions server/cmd/crasher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"server/internal/app/controllers"
"server/internal/app/repositories/mongodb_repository"
"server/internal/app/services"
"strconv"

"github.com/gorilla/mux"
"go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -45,8 +46,16 @@ func main() {
}
}()

appsRepo := mongodb_repositories.NewApplicationsRepository(dbClient, logger)
coreDumpsRepo := mongodb_repositories.NewCoreDumpsRepository(dbClient, logger)
timeout, err := strconv.Atoi(app.CtxTimeout)
if err != nil {
logger.Fatal(
"failed to parse timeout env",
zap.Error(err),
)
}

appsRepo := mongodb_repository.NewApplicationsRepository(dbClient, logger, timeout)
coreDumpsRepo := mongodb_repository.NewCoreDumpsRepository(dbClient, logger,timeout)

appsService := services.NewApplicationsService(appsRepo, logger)
coreDumpsService := services.NewCoreDumpsService(coreDumpsRepo, logger)
Expand Down
25 changes: 19 additions & 6 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ module server
go 1.19

require (
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.0
github.com/stretchr/testify v1.8.0
go.mongodb.org/mongo-driver v1.8.4
go.uber.org/zap v1.22.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
go.mongodb.org/mongo-driver v1.8.4 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions server/internal/app/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app
import "os"

var (
ServerAddress = os.Getenv("CRASHER_SERVER_ADDRESS")

ServerAddress = os.Getenv("CRASHER_SERVER_ADDRESS")
CtxTimeout = parseEnvOrDefaultValue("CRASHER_DATABASE_TIMEOUT", "5")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Название переменной, как и говорил, давай сделаем DatabaseTimeout

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не надо здесь парсить - парсить будем в main-e

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

DatabaseAddress = os.Getenv("CRASHER_DATABASE_ADDRESS")
DatabaseUsername = os.Getenv("CRASHER_DATABASE_USERNAME")
DatabasePassword = os.Getenv("CRASHER_DATABASE_PASSWORD")
Expand Down
24 changes: 12 additions & 12 deletions server/internal/app/entities/app_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ const (
)

type AppInfo struct {
name string
version string
programmingLanguage ProgrammingLanguage
Name string
Version string
ProgrammingLanguage ProgrammingLanguage
}

func NewAppInfo() *AppInfo {
return &AppInfo{}
}

func (app *AppInfo) Name() string {
return app.name
func (app *AppInfo) GetName() string {
return app.Name
}

func (app *AppInfo) Version() string {
return app.version
func (app *AppInfo) GetVersion() string {
return app.Version
}

func (app *AppInfo) ProgrammingLanguage() ProgrammingLanguage {
return app.programmingLanguage
func (app *AppInfo) GetProgrammingLanguage() ProgrammingLanguage {
return app.ProgrammingLanguage
}

func (app *AppInfo) SetName(name string) {
app.name = name
app.Name = name
}

func (app *AppInfo) SetVersion(version string) {
app.version = version
app.Version = version
}

func (app *AppInfo) SetProgrammingLanguage(language ProgrammingLanguage) {
app.programmingLanguage = language
app.ProgrammingLanguage = language
}
12 changes: 6 additions & 6 deletions server/internal/app/entities/app_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

func TestAppInfo(t *testing.T) {
appInfo := NewAppInfo()
require.Equal(t, 0, len(appInfo.Name()))
require.Equal(t, 0, len(appInfo.Version()))
require.Equal(t, UnknownProgrammingLanguage, appInfo.ProgrammingLanguage())
require.Equal(t, 0, len(appInfo.GetName()))
require.Equal(t, 0, len(appInfo.GetVersion()))
require.Equal(t, UnknownProgrammingLanguage, appInfo.GetProgrammingLanguage())

name := "publisher-app"
version := "v0.0.1"
Expand All @@ -21,7 +21,7 @@ func TestAppInfo(t *testing.T) {
appInfo.SetVersion(version)
appInfo.SetProgrammingLanguage(language)

assert.Equal(t, name, appInfo.Name())
assert.Equal(t, version, appInfo.Version())
assert.Equal(t, language, appInfo.ProgrammingLanguage())
assert.Equal(t, name, appInfo.GetName())
assert.Equal(t, version, appInfo.GetVersion())
assert.Equal(t, language, appInfo.GetProgrammingLanguage())
}
64 changes: 43 additions & 21 deletions server/internal/app/entities/core_dump.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package entities

import "time"
import (
"time"
)

type CoreDumpStatus int

Expand All @@ -12,53 +14,73 @@ const (
)

type CoreDump struct {
osInfo *OSInfo
appInfo *AppInfo
status CoreDumpStatus
data string
timestamp time.Time
ID string
OsInfo *OSInfo
AppInfo *AppInfo
Status CoreDumpStatus
Data string
Timestamp time.Time
Extensions []Extension
}

type Extension struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай назовем CoreDumpExtension

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allright

Key string
Value string
}

func NewCoreDump() *CoreDump {
return &CoreDump{}
}

func (c *CoreDump) OSInfo() *OSInfo {
return c.osInfo
func (c *CoreDump) GetOSInfo() *OSInfo {
return c.OsInfo
}

func (c *CoreDump) GetAppInfo() *AppInfo {
return c.AppInfo
}

func (c *CoreDump) AppInfo() *AppInfo {
return c.appInfo
func (c *CoreDump) GetStatus() CoreDumpStatus {
return c.Status
}

func (c *CoreDump) Status() CoreDumpStatus {
return c.status
func (c *CoreDump) GetData() string {
return c.Data
}

func (c *CoreDump) Data() string {
return c.data
func (c *CoreDump) GetTimestamp() time.Time {
return c.Timestamp
}

func (c *CoreDump) Timestamp() time.Time {
return c.timestamp
func (c *CoreDump) GetExtension(index int) *Extension {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По индекс нам не придется получать

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allright, deleted it

return &c.Extensions[index]
}

func (c *CoreDump) GetExtensions() *[]Extension {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем указатель на слайс?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No pointer, allright.

return &c.Extensions
}

func (c *CoreDump) SetOSInfo(info *OSInfo) {
c.osInfo = info
c.OsInfo = info
}

func (c *CoreDump) SetAppInfo(info *AppInfo) {
c.appInfo = info
c.AppInfo = info
}

func (c *CoreDump) SetStatus(status CoreDumpStatus) {
c.status = status
c.Status = status
}

func (c *CoreDump) SetData(data string) {
c.data = data
c.Data = data
}

func (c *CoreDump) SetTimestamp(timestamp time.Time) {
c.timestamp = timestamp
c.Timestamp = timestamp
}

func (c *CoreDump) SetExtensions(key, value string) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если метод называется SetExtensions он должен устанавливать все расширения, если говорим о добавление - это должно быть AddExtension

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allright

extension := &Extension{Key: key, Value: value}
c.Extensions = append(c.Extensions, *extension)
}
27 changes: 17 additions & 10 deletions server/internal/app/entities/core_dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@ import (

func TestCoreDump(t *testing.T) {
coreDump := NewCoreDump()
require.Nil(t, coreDump.OSInfo())
require.Nil(t, coreDump.AppInfo())
require.Equal(t, ToDoCoreDumpStatus, coreDump.Status())
require.Equal(t, time.Time{}, coreDump.Timestamp())
require.Equal(t, 0, len(coreDump.Data()))
require.Nil(t, coreDump.GetOSInfo())
require.Nil(t, coreDump.GetAppInfo())
require.Equal(t, ToDoCoreDumpStatus, coreDump.GetStatus())
require.Equal(t, time.Time{}, coreDump.GetTimestamp())
require.Equal(t, 0, len(coreDump.GetData()))

osInfo := NewOSInfo()
appInfo := NewAppInfo()
timestamp := time.Now()
status := SolvedCoreDumpStatus
data := "server/internal/app/entities/core_dump_test.go@TestCoreDump:100"
extension := &Extension{
Key: "key",
Value: "value",
}

coreDump.SetOSInfo(osInfo)
coreDump.SetAppInfo(appInfo)
coreDump.SetTimestamp(timestamp)
coreDump.SetStatus(status)
coreDump.SetData(data)
coreDump.SetExtensions(extension.Key, extension.Value)

assert.Equal(t, osInfo, coreDump.OSInfo())
assert.Equal(t, appInfo, coreDump.AppInfo())
assert.Equal(t, timestamp, coreDump.Timestamp())
assert.Equal(t, status, coreDump.Status())
assert.Equal(t, data, coreDump.Data())
assert.Equal(t, osInfo, coreDump.GetOSInfo())
assert.Equal(t, appInfo, coreDump.GetAppInfo())
assert.Equal(t, timestamp, coreDump.GetTimestamp())
assert.Equal(t, status, coreDump.GetStatus())
assert.Equal(t, data, coreDump.GetData())
assert.Equal(t, extension, coreDump.GetExtension(0))
assert.Equal(t, true, len(*coreDump.GetExtensions()) > 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно не длину проверять, а контент внутри

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allright

}
24 changes: 12 additions & 12 deletions server/internal/app/entities/os_info.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package entities

type OSInfo struct {
name string
version string
architecture string
Name string
Version string
Architecture string
}

func NewOSInfo() *OSInfo {
return &OSInfo{}
}

func (os *OSInfo) Name() string {
return os.name
func (os *OSInfo) GetName() string {
return os.Name
}

func (os *OSInfo) Version() string {
return os.version
func (os *OSInfo) GetVersion() string {
return os.Version
}

func (os *OSInfo) Architecture() string {
return os.architecture
func (os *OSInfo) GetArchitecture() string {
return os.Architecture
}

func (os *OSInfo) SetName(name string) {
os.name = name
os.Name = name
}

func (os *OSInfo) SetVersion(version string) {
os.version = version
os.Version = version
}

func (os *OSInfo) SetArchitecture(architecture string) {
os.architecture = architecture
os.Architecture = architecture
}
Loading