Skip to content

Commit

Permalink
few side adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
vsimakhin committed Jan 29, 2025
1 parent 3bda7a3 commit e68cbe5
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 279 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- name: go vet
run: go vet ./...

- name: go fmt
run: go fmt ./...
- name: build
run: make build_ui build_backend

- name: Test
run: go test -v ./...
- name: test
run: make test
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ jobs:
push: true
tags: |
vsimakhin/web-logbook:${{ env.TAG }}
vsimakhin/web-logbook:latest
vsimakhin/web-logbook:3
# vsimakhin/web-logbook:latest
34 changes: 20 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,78 @@ clean:
fmt:
@go fmt ./...

## build ui
build_ui:
@echo "Building UI..."
@cd app/ui && npm run build
@cd ../../

## tests
test: fmt
@go test -v ./... -coverpkg=./...

## build: builds the binaty
build: clean
## build: builds the binary
build_backend: clean
@echo "Building..."
@go build -ldflags="-s -w" -o dist/web-logbook ./app
@echo "Web-logbook built!"

## start: starts the web-logbook
start: build
start: build_ui build_backend
@echo "Starting the app..."
@env ./dist/web-logbook -port=${PORT} -env="${ENV}"

start_tls: build
@echo "Starting the app with https enabled..."
@env ./dist/web-logbook -port=${PORT} -env="${ENV}" -enable-https
start_backend: clean build_backend
@echo "Starting the app..."
@env ./dist/web-logbook -port=${PORT} -env="${ENV}"

build_linux_amd64:
build_linux_amd64: build_ui
@OS=linux; ARCH=amd64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_linux_arm64:
build_linux_arm64: build_ui
@OS=linux; ARCH=arm64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_linux_arm_6:
build_linux_arm_6: build_ui
@OS=linux; ARCH=arm; ARM=6; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH GOARM=$$ARM \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH-$$ARM.tar.gz $(BINARY_NAME)-$$OS-$$ARCH-$$ARM;

build_linux_arm_7:
build_linux_arm_7: build_ui
@OS=linux; ARCH=arm; ARM=7; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH GOARM=$$ARM \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH-$$ARM/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH-$$ARM.tar.gz $(BINARY_NAME)-$$OS-$$ARCH-$$ARM;

build_darwin_amd64:
build_darwin_amd64: build_ui
@OS=darwin; ARCH=amd64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_darwin_arm64:
build_darwin_arm64: build_ui
@OS=darwin; ARCH=arm64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); tar czf $(BINARY_NAME)-$$OS-$$ARCH.tar.gz $(BINARY_NAME)-$$OS-$$ARCH;

build_windows_amd64:
build_windows_amd64: build_ui
@OS=windows; ARCH=amd64; \
echo Building $$OS/$$ARCH to $(BIN)/$(BINARY_NAME)-$$OS-$$ARCH; \
CGO_ENABLED=0 GOOS=$$OS GOARCH=$$ARCH \
go build $(OPTIONS) -o=$(BIN)/$(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) ./app; \
cd $(BIN); mv $(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME) $(BINARY_NAME)-$$OS-$$ARCH/$(BINARY_NAME).exe; zip -r $(BINARY_NAME)-$$OS-$$ARCH.zip $(BINARY_NAME)-$$OS-$$ARCH;

build_all: test clean build_linux_amd64 build_linux_arm64 build_linux_arm_6 build_linux_arm_7 build_darwin_amd64 build_darwin_arm64 build_windows_amd64
build_all: test clean build_ui build_linux_amd64 build_linux_arm64 build_linux_arm_6 build_linux_arm_7 build_darwin_amd64 build_darwin_arm64 build_windows_amd64
109 changes: 0 additions & 109 deletions app/handlers_licensing_test.go
Original file line number Diff line number Diff line change
@@ -1,110 +1 @@
package main

import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/vsimakhin/web-logbook/internal/models"
)

func TestHandlerLicensing(t *testing.T) {

app, mock := initTestApplication()

models.InitMock(mock, "GetSettings")
models.InitMock(mock, "GetLicenses")

srv := httptest.NewServer(app.routes())
defer srv.Close()

resp, _ := http.Get(fmt.Sprintf("%s%s", srv.URL, APILicensing))
responseBody, _ := io.ReadAll(resp.Body)

assert.Equal(t, http.StatusOK, resp.StatusCode)

// need to have datatables css and js
assert.Contains(t, string(responseBody), `<script type="text/javascript" src="/static/js/datatables.min.js"></script>`)

}

func TestHandlerLicensingRecordsData(t *testing.T) {

app, mock := initTestApplication()

models.InitMock(mock, "GetLicenses")

srv := httptest.NewServer(app.routes())
defer srv.Close()

resp, _ := http.Get(fmt.Sprintf("%s%s", srv.URL, APILicensingData))
responseBody, _ := io.ReadAll(resp.Body)

assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, `{"data":[["category","uuid","name","number","issued","01/01/2022","01/01/2022","Expired!","uuid"]]}`, string(responseBody))
}

func TestHandlerLicensingRecordByID(t *testing.T) {

app, mock := initTestApplication()

models.InitMock(mock, "GetSettings")
models.InitMock(mock, "GetLicenseRecordByID")
models.InitMock(mock, "GetLicensesCategory")

srv := httptest.NewServer(app.routes())
defer srv.Close()

resp, _ := http.Get(fmt.Sprintf("%s%s", srv.URL, strings.ReplaceAll(APILicensingUUID, "{uuid}", "uuid")))
responseBody, _ := io.ReadAll(resp.Body)

assert.Equal(t, http.StatusOK, resp.StatusCode)

assert.Contains(t, string(responseBody), `<label for="category" class="form-label">Category</label>`)
assert.Contains(t, string(responseBody), `<label for="name" class="form-label">Name</label>`)
assert.Contains(t, string(responseBody), `<label for="number" class="form-label">Number</label>`)

}

func TestHandlerLicensingDownload(t *testing.T) {

app, mock := initTestApplication()

models.InitMock(mock, "GetLicenseRecordByID")

srv := httptest.NewServer(app.routes())
defer srv.Close()

resp, _ := http.Get(fmt.Sprintf("%s%s", srv.URL, strings.ReplaceAll(APILicensingDownloadUUID, "{uuid}", "uuid")))
responseBody, _ := io.ReadAll(resp.Body)

assert.Equal(t, http.StatusOK, resp.StatusCode)

assert.Contains(t, string(responseBody), `document`)

}

func TestHandlerLicensingRecordNew(t *testing.T) {

app, mock := initTestApplication()

models.InitMock(mock, "GetSettings")
models.InitMock(mock, "GetLicensesCategory")

srv := httptest.NewServer(app.routes())
defer srv.Close()

resp, _ := http.Get(fmt.Sprintf("%s%s", srv.URL, APILicensingNew))
responseBody, _ := io.ReadAll(resp.Body)

assert.Equal(t, http.StatusOK, resp.StatusCode)

assert.Contains(t, string(responseBody), `<label for="category" class="form-label">Category</label>`)
assert.Contains(t, string(responseBody), `<label for="name" class="form-label">Name</label>`)
assert.Contains(t, string(responseBody), `<label for="number" class="form-label">Number</label>`)

}
2 changes: 0 additions & 2 deletions app/renders.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func (app *application) addDefaultData(td *templateData, req *http.Request) *tem
td.Version = app.version
td.NewVersion = app.isNewVersion

td.License.Expired, td.License.Warning = app.db.CheckLicenseExpiration()

if td.Data == nil {
td.Data = make(map[string]interface{})
}
Expand Down
Loading

0 comments on commit e68cbe5

Please sign in to comment.