diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..6373b749 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,61 @@ +name: Tests + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.22 + + - name: setup .algorun.yaml + run: | + touch .algorun.yaml + echo 'server: http://localhost:8080' >> .algorun.yaml + echo 'token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' >> .algorun.yaml + + - name: Start Docker Compose + run: docker compose up -d + + - name: Install dependencies + run: go get . + + - name: Check formatting + run: | + fmt_files=$(gofmt -l .) + if [ -n "$fmt_files" ]; then + echo "Go code is not formatted. Please run 'go fmt'." + gofmt -d . + exit 1 + fi + + - name: Tidy go.mod and go.sum + run: | + go mod tidy + git diff --exit-code go.mod go.sum + if [ $? -ne 0 ]; then + echo "go.mod or go.sum is not tidy. Please run 'go mod tidy'." + exit 1 + fi + + - name: Run go vet + run: go vet ./... + + - name: Build + run: go build -o bin/algorun *.go + + - name: Test with the Go CLI + run: go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./... + + - name: check test coverage + uses: vladopajic/go-test-coverage@v2 + with: + config: ./.testcoverage.yaml diff --git a/.testcoverage.yaml b/.testcoverage.yaml new file mode 100644 index 00000000..18363129 --- /dev/null +++ b/.testcoverage.yaml @@ -0,0 +1,26 @@ +profile: cover.out + +# (optional; but recommended to set) +# When specified reported file paths will not contain local prefix in the output +local-prefix: "github.com/algorandfoundation/hack-tui" + +# Holds coverage thresholds percentages, values should be in range [0-100] +threshold: + # (optional; default 0) + # The minimum coverage that each file should have + file: 0 + + # (optional; default 0) + # The minimum coverage that each package should have + package: 0 + + # (optional; default 0) + # The minimum total coverage project should have + total: 0 + +# Holds regexp rules which will exclude matched files or packages +# from coverage statistics +exclude: + # Exclude files or packages matching their paths + paths: + - api/if.go diff --git a/README.md b/README.md index 6750639b..4e0418b1 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ --- -Terminal UI for managing Algorand nodes. -Built with [bubbles](https://github.com/charmbracelet/bubbles)/[bubbletea](https://github.com/charmbracelet/bubbletea) +Terminal UI for managing Algorand nodes. +Built with [bubbles](https://github.com/charmbracelet/bubbles)/[bubbletea](https://github.com/charmbracelet/bubbletea) # 🚀 Get Started @@ -52,7 +52,7 @@ Start a participation node docker compose up ``` -Connect to the node +Connect to the node ```bash ./bin/algorun --server http://localhost:8080 --token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa @@ -69,7 +69,7 @@ Configuration is loaded in the following order: 2. Home Directory 3. /etc/algorun/ 2. ENV Configuration - - ALGORUN_* + - ALGORUN\_\* 3. CLI Flag Arguments 4. ALGORAND_DATA parsing @@ -80,24 +80,23 @@ This results in `ALGORAND_DATA` taking precedence in the loading order. Example configuration file: ```yaml -server: "http://localhost:4001" +server: "http://localhost:8080" token: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ``` ### Environment Variables | Name | Example | -|----------------|----------------------------------------------------------------------------------| -| ALGORUN_SERVER | ALGORUN_SERVER="http://localhost:4001" | +| -------------- | -------------------------------------------------------------------------------- | +| ALGORUN_SERVER | ALGORUN_SERVER="http://localhost:8080" | | ALGORUN_TOKEN | ALGORUN_TOKEN="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | - ### Flags The application supports the `server` and `token` flags for configuration. ```bash -algorun --server http://localhost:4001 --token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +algorun --server http://localhost:8080 --token aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ``` ## 🧑‍💻 Commands @@ -122,4 +121,4 @@ Display the usage information for the command ```bash algorun help -``` \ No newline at end of file +``` diff --git a/go.mod b/go.mod index 59ef2490..04ae5768 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/algorandfoundation/algourl v0.0.0-20241023193235-8bbf72ad0b37 github.com/charmbracelet/bubbles v0.20.0 github.com/charmbracelet/bubbletea v1.1.1 - github.com/charmbracelet/lipgloss v0.13.0 + github.com/charmbracelet/lipgloss v0.13.1 github.com/charmbracelet/log v0.4.0 - github.com/charmbracelet/x/exp/teatest v0.0.0-20241004173542-8f764644629a + github.com/charmbracelet/x/exp/teatest v0.0.0-20241022174419-46d9bb99a691 github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 github.com/oapi-codegen/runtime v1.1.1 github.com/spf13/cobra v1.8.1 @@ -28,7 +28,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.2.0 // indirect github.com/charmbracelet/x/ansi v0.3.2 // indirect - github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect + github.com/charmbracelet/x/exp/golden v0.0.0-20241022174419-46d9bb99a691 // indirect github.com/charmbracelet/x/term v0.2.0 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect @@ -48,7 +48,7 @@ require ( github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect diff --git a/go.sum b/go.sum index 9c47bc33..acaa1e37 100644 --- a/go.sum +++ b/go.sum @@ -20,16 +20,16 @@ github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQW github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU= github.com/charmbracelet/bubbletea v1.1.1 h1:KJ2/DnmpfqFtDNVTvYZ6zpPFL9iRCRr0qqKOCvppbPY= github.com/charmbracelet/bubbletea v1.1.1/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4= -github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= -github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= +github.com/charmbracelet/lipgloss v0.13.1 h1:Oik/oqDTMVA01GetT4JdEC033dNzWoQHdWnHnQmXE2A= +github.com/charmbracelet/lipgloss v0.13.1/go.mod h1:zaYVJ2xKSKEnTEEbX6uAHabh2d975RJ+0yfkFpRBz5U= github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= -github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q= -github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= -github.com/charmbracelet/x/exp/teatest v0.0.0-20241004173542-8f764644629a h1:d1J6xYNaQLjG+8XflluHU6rrBxsvjIr/B9lETKVn92Q= -github.com/charmbracelet/x/exp/teatest v0.0.0-20241004173542-8f764644629a/go.mod h1:ektxP4TiEONm1mTGILRfo8F0a4rZMwsT1fEkXslQKtU= +github.com/charmbracelet/x/exp/golden v0.0.0-20241022174419-46d9bb99a691 h1:E7A9Eg1g/8kQIXVEH7bIWAE5ZSj7RCPIaVo4vawuxYc= +github.com/charmbracelet/x/exp/golden v0.0.0-20241022174419-46d9bb99a691/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= +github.com/charmbracelet/x/exp/teatest v0.0.0-20241022174419-46d9bb99a691 h1:xiYMZ3dUF3iXc90LCTKj5ZiiwuCvhEvGsF/qUCMRgEk= +github.com/charmbracelet/x/exp/teatest v0.0.0-20241022174419-46d9bb99a691/go.mod h1:ektxP4TiEONm1mTGILRfo8F0a4rZMwsT1fEkXslQKtU= github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0= github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -94,8 +94,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk= github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0= diff --git a/internal/metrics_test.go b/internal/metrics_test.go index d03cad9d..2d5ff5ad 100644 --- a/internal/metrics_test.go +++ b/internal/metrics_test.go @@ -2,10 +2,11 @@ package internal import ( "context" - "github.com/algorandfoundation/hack-tui/api" - "github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider" "strconv" "testing" + + "github.com/algorandfoundation/hack-tui/api" + "github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider" ) func Test_GetMetrics(t *testing.T) { @@ -14,7 +15,7 @@ func Test_GetMetrics(t *testing.T) { if err != nil { t.Fatal(err) } - client, err := api.NewClientWithResponses("http://localhost:4001", api.WithRequestEditorFn(apiToken.Intercept)) + client, err := api.NewClientWithResponses("http://localhost:8080", api.WithRequestEditorFn(apiToken.Intercept)) metrics, err := GetMetrics(context.Background(), client) if err != nil { diff --git a/internal/participation_test.go b/internal/participation_test.go index ede9455e..69038dac 100644 --- a/internal/participation_test.go +++ b/internal/participation_test.go @@ -3,9 +3,10 @@ package internal import ( "context" "fmt" + "testing" + "github.com/algorandfoundation/hack-tui/api" "github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider" - "testing" ) func Test_ListParticipationKeys(t *testing.T) { @@ -27,7 +28,7 @@ func Test_ListParticipationKeys(t *testing.T) { if err != nil { t.Fatal(err) } - client, err = api.NewClientWithResponses("http://localhost:4001", api.WithRequestEditorFn(apiToken.Intercept)) + client, err = api.NewClientWithResponses("http://localhost:8080", api.WithRequestEditorFn(apiToken.Intercept)) if err != nil { t.Fatal(err) } @@ -59,7 +60,7 @@ func Test_ReadParticipationKey(t *testing.T) { if err != nil { t.Fatal(err) } - client, err = api.NewClientWithResponses("http://localhost:4001", api.WithRequestEditorFn(apiToken.Intercept)) + client, err = api.NewClientWithResponses("http://localhost:8080", api.WithRequestEditorFn(apiToken.Intercept)) if err != nil { t.Fatal(err) } @@ -100,7 +101,7 @@ func Test_GenerateParticipationKey(t *testing.T) { if err != nil { t.Fatal(err) } - client, err = api.NewClientWithResponses("http://localhost:4001", api.WithRequestEditorFn(apiToken.Intercept)) + client, err = api.NewClientWithResponses("http://localhost:8080", api.WithRequestEditorFn(apiToken.Intercept)) if err != nil { t.Fatal(err) } @@ -126,7 +127,7 @@ func Test_DeleteParticipationKey(t *testing.T) { if err != nil { t.Fatal(err) } - client, err := api.NewClientWithResponses("http://localhost:4001", api.WithRequestEditorFn(apiToken.Intercept)) + client, err := api.NewClientWithResponses("http://localhost:8080", api.WithRequestEditorFn(apiToken.Intercept)) if err != nil { t.Fatal(err) } diff --git a/ui/status_test.go b/ui/status_test.go index 92571c8f..53cab3f8 100644 --- a/ui/status_test.go +++ b/ui/status_test.go @@ -2,11 +2,12 @@ package ui import ( "bytes" + "testing" + "time" + "github.com/algorandfoundation/hack-tui/internal" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/x/exp/teatest" - "testing" - "time" ) func Test_StatusViewRender(t *testing.T) { diff --git a/ui/viewport_test.go b/ui/viewport_test.go index 67df8355..513808e7 100644 --- a/ui/viewport_test.go +++ b/ui/viewport_test.go @@ -2,18 +2,19 @@ package ui import ( "bytes" + "testing" + "time" + "github.com/algorandfoundation/hack-tui/api" "github.com/algorandfoundation/hack-tui/internal" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/x/exp/teatest" "github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider" - "testing" - "time" ) func Test_ViewportViewRender(t *testing.T) { apiToken, err := securityprovider.NewSecurityProviderApiKey("header", "X-Algo-API-Token", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") - client, err := api.NewClientWithResponses("http://localhost:4001", api.WithRequestEditorFn(apiToken.Intercept)) + client, err := api.NewClientWithResponses("http://localhost:8080", api.WithRequestEditorFn(apiToken.Intercept)) if err != nil { t.Fatal(err) }