Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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

16 changes: 10 additions & 6 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ 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
4 changes: 2 additions & 2 deletions server/cmd/crasher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func main() {
}
}()

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

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 = os.Getenv("CRASHER_DATABASE_TIMEOUTgit")
Copy link
Contributor

Choose a reason for hiding this comment

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

git - что-то лишнее)
И давай название переменной сделаем DatabaseTimeout

Copy link
Contributor Author

@srjchsv srjchsv Sep 18, 2022

Choose a reason for hiding this comment

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

Right)
CRASHER_DATABASE_TIMEOUT or DATABASE_TIMEOUT?

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())
}
53 changes: 32 additions & 21 deletions server/internal/app/entities/core_dump.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package entities

import "time"
import (
"time"

"go.mongodb.org/mongo-driver/bson/primitive"
)

type CoreDumpStatus int

Expand All @@ -12,53 +16,60 @@ const (
)

type CoreDump struct {
osInfo *OSInfo
appInfo *AppInfo
status CoreDumpStatus
data string
timestamp time.Time
ID primitive.ObjectID
Copy link
Contributor

Choose a reason for hiding this comment

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

entity - ничего не должен знать о БД, в будущем замена БД должна быть бесшовной

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what type for ID then? int?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed ID to string type as its in the method parameter and API scheme.
How to set a unique ID when creating a dump? We are missing a string ID setter...

OsInfo *OSInfo
AppInfo *AppInfo
Status CoreDumpStatus
Data string
Timestamp time.Time
Extensions []Extensions
Copy link
Contributor

Choose a reason for hiding this comment

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

Геттер и сеттер еще только давай сделаем

Copy link
Contributor Author

Choose a reason for hiding this comment

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

allright

}

type Extensions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Extension давай только, а вот выше давай так оставим Extensions []Extension

Copy link
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) AppInfo() *AppInfo {
return c.appInfo
func (c *CoreDump) GetAppInfo() *AppInfo {
return c.AppInfo
}

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

func (c *CoreDump) Data() string {
return c.data
func (c *CoreDump) GetData() string {
return c.Data
}

func (c *CoreDump) Timestamp() time.Time {
return c.timestamp
func (c *CoreDump) GetTimestamp() time.Time {
return c.Timestamp
}

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
}
20 changes: 10 additions & 10 deletions server/internal/app/entities/core_dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ 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()
Expand All @@ -28,9 +28,9 @@ func TestCoreDump(t *testing.T) {
coreDump.SetStatus(status)
coreDump.SetData(data)

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())
}
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
}
12 changes: 6 additions & 6 deletions server/internal/app/entities/os_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

func TestOSInfo(t *testing.T) {
osInfo := NewOSInfo()
require.Equal(t, 0, len(osInfo.Name()))
require.Equal(t, 0, len(osInfo.Version()))
require.Equal(t, 0, len(osInfo.Architecture()))
require.Equal(t, 0, len(osInfo.GetName()))
require.Equal(t, 0, len(osInfo.GetVersion()))
require.Equal(t, 0, len(osInfo.GetArchitecture()))

name := "windows"
version := "10"
Expand All @@ -21,7 +21,7 @@ func TestOSInfo(t *testing.T) {
osInfo.SetVersion(version)
osInfo.SetArchitecture(architecture)

assert.Equal(t, name, osInfo.Name())
assert.Equal(t, version, osInfo.Version())
assert.Equal(t, architecture, osInfo.Architecture())
assert.Equal(t, name, osInfo.GetName())
assert.Equal(t, version, osInfo.GetVersion())
assert.Equal(t, architecture, osInfo.GetArchitecture())
}
Loading