Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,30 @@ jobs:
# uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}

e2e-test:
name: E2E Test
runs-on: ubuntu-latest
needs: test
steps:
# step 1: checkout repository code
- name: Checkout code into workspace directory
uses: actions/checkout@v4

# step 2: set up go
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

# step 3: install main project dependencies
- name: Install main Go dependencies
run: go mod download

# step 4: install e2e test dependencies
- name: Install E2E test dependencies
run: cd tests/e2e && go mod download

# step 5: run e2e tests with verbose output
- name: Run E2E tests
run: cd tests/e2e && go test -v ./...
13 changes: 10 additions & 3 deletions internal/commands/webhooks/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhooks

import (
"fmt"
"net/url"
"strings"

"github.com/android-sms-gateway/cli/internal/core/codes"
Expand Down Expand Up @@ -41,17 +42,23 @@ var register = &cli.Command{
},
},
Action: func(c *cli.Context) error {
url := c.Args().Get(0)
if url == "" {
targetUrl := strings.TrimSpace(c.Args().Get(0))
if targetUrl == "" {
return cli.Exit("URL is empty", codes.ParamsError)
}

// accept only absolute http/https URLs
parsed, err := url.Parse(targetUrl)
if err != nil || parsed.Host == "" || (parsed.Scheme != "http" && parsed.Scheme != "https") {
return cli.Exit("invalid URL", codes.ParamsError)
}

client := metadata.GetClient(c.App.Metadata)
renderer := metadata.GetRenderer(c.App.Metadata)

req := smsgateway.Webhook{
ID: c.String("id"),
URL: url,
URL: targetUrl,
Event: c.String("event"),
}

Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/general_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package e2e

import (
"bytes"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
)

func TestHelpFlag(t *testing.T) {
// Run the CLI binary with the --help flag
var stdout, stderr bytes.Buffer

cmd := exec.Command("./smsgate", "--help")
cmd.Stdout = &stdout
cmd.Stderr = &stderr

err := cmd.Run()

assert.NoError(t, err)

// Verify the output
assert.Contains(t, stdout.String(), "CLI interface for working with SMS Gateway for Android™")
}
11 changes: 11 additions & 0 deletions tests/e2e/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module e2e

go 1.24.3

require github.com/stretchr/testify v1.10.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions tests/e2e/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
23 changes: 23 additions & 0 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package e2e

import (
"os"
"os/exec"
"testing"
)

func TestMain(m *testing.M) {
// Build the CLI binary
cmd := exec.Command("go", "build", "-o", "tests/e2e/smsgate", "cmd/smsgate/smsgate.go")
cmd.Dir = "../../"
err := cmd.Run()
if err != nil {
panic(err)
}

code := m.Run()

_ = os.Remove("smsgate")

os.Exit(code)
}
Loading
Loading