-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE DATABASE `sms-public`; | ||
CREATE DATABASE `sms-private`; | ||
--- | ||
CREATE USER 'sms' @'%' IDENTIFIED BY 'sms'; | ||
GRANT ALL PRIVILEGES ON `sms-public`.* TO 'sms' @'%'; | ||
GRANT ALL PRIVILEGES ON `sms-private`.* TO 'sms' @'%'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
fcm: | ||
credentials_json: "{}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
services: | ||
public: | ||
image: android-sms-gateway/server | ||
build: | ||
context: ../.. | ||
dockerfile: ./build/package/Dockerfile | ||
args: | ||
- APP=sms-gateway | ||
environment: | ||
- DEBUG= | ||
- CONFIG_PATH=config.yml | ||
- GOOSE_DBSTRING=sms:sms@tcp(db:3306)/sms | ||
- HTTP__LISTEN=0.0.0.0:3000 | ||
- DATABASE__HOST=db | ||
- DATABASE__PORT=3306 | ||
- DATABASE__USER=sms | ||
- DATABASE__PASSWORD=sms | ||
- DATABASE__DATABASE=sms-public | ||
- GATEWAY__MODE=public | ||
- FCM__CREDENTIALS_JSON=${FCM__CREDENTIALS_JSON} | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- ./data/config.yml:/app/config.yml:ro | ||
restart: 'unless-stopped' | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
|
||
private: | ||
image: android-sms-gateway/server | ||
build: | ||
context: ../.. | ||
dockerfile: ./build/package/Dockerfile | ||
args: | ||
- APP=sms-gateway | ||
environment: | ||
- DEBUG= | ||
- CONFIG_PATH=config.yml | ||
- GOOSE_DBSTRING=sms:sms@tcp(db:3306)/sms | ||
- HTTP__LISTEN=0.0.0.0:3000 | ||
- DATABASE__HOST=db | ||
- DATABASE__PORT=3306 | ||
- DATABASE__USER=sms | ||
- DATABASE__PASSWORD=sms | ||
- DATABASE__DATABASE=sms-private | ||
- GATEWAY__MODE=private | ||
- GATEWAY__PRIVATE_TOKEN=123456789 | ||
ports: | ||
- "3001:3000" | ||
volumes: | ||
- ./data/config.yml:/app/config.yml:ro | ||
restart: 'unless-stopped' | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
|
||
db: | ||
image: mariadb:lts | ||
environment: | ||
- MARIADB_ROOT_PASSWORD=root | ||
- MARIADB_AUTO_UPGRADE=1 | ||
volumes: | ||
- ./data/10-init.sql:/docker-entrypoint-initdb.d/10-init.sql:ro | ||
restart: 'unless-stopped' | ||
healthcheck: | ||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] | ||
start_period: 4s | ||
interval: 4s | ||
timeout: 2s | ||
retries: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/android-sms-gateway/server/test/e2e | ||
|
||
go 1.22.0 | ||
|
||
require github.com/go-resty/resty/v2 v2.16.2 | ||
|
||
require golang.org/x/net v0.27.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/go-resty/resty/v2 v2.16.2 h1:CpRqTjIzq/rweXUt9+GxzzQdlkqMdt8Lm/fuK/CAbAg= | ||
github.com/go-resty/resty/v2 v2.16.2/go.mod h1:0fHAoK7JoBy/Ch36N8VFeMsK7xQOHhvWaC3iOktwmIU= | ||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= | ||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= | ||
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= | ||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
const ( | ||
PublicURL = "http://localhost:3000/api" | ||
PrivateURL = "http://localhost:3001/api" | ||
) | ||
|
||
func isOnline() bool { | ||
for _, v := range []string{PublicURL, PrivateURL} { | ||
_, err := resty.New(). | ||
SetBaseURL(v). | ||
SetTimeout(100 * time.Millisecond). | ||
R(). | ||
Get("/health") | ||
|
||
if err != nil { | ||
log.Println("waiting for health", err) | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
log.Println("running e2e tests") | ||
|
||
if _, ok := os.LookupEnv("CI"); !ok { | ||
if err := exec.Command("docker", "compose", "up", "-d", "--build").Run(); err != nil { | ||
log.Fatal(fmt.Errorf("docker-compose up -d: %w", err)) | ||
} | ||
|
||
defer func() { | ||
if err := exec.Command("docker", "compose", "down", "-v").Run(); err != nil { | ||
log.Fatal(fmt.Errorf("docker-compose down -v: %w", err)) | ||
} | ||
log.Println("e2e tests finished") | ||
}() | ||
} | ||
|
||
startedAt := time.Now() | ||
for { | ||
if time.Since(startedAt) > 20*time.Second { | ||
log.Println("timeout") | ||
return | ||
} | ||
|
||
if isOnline() { | ||
log.Println("e2e tests started") | ||
break | ||
} | ||
|
||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
m.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
func makeClient(baseUrl string) *resty.Client { | ||
return resty.New(). | ||
SetBaseURL(baseUrl). | ||
SetTimeout(300 * time.Millisecond) | ||
} | ||
|
||
func TestPublicDeviceRegister(t *testing.T) { | ||
cases := []struct { | ||
headers map[string]string | ||
expectedStatusCode int | ||
}{ | ||
{ | ||
headers: map[string]string{ | ||
"Authorization": "Bearer 123456789", | ||
}, | ||
expectedStatusCode: 201, | ||
}, | ||
{ | ||
headers: map[string]string{}, | ||
expectedStatusCode: 201, | ||
}, | ||
{ | ||
headers: map[string]string{ | ||
"Authorization": "Bearer 987654321", | ||
}, | ||
expectedStatusCode: 201, | ||
}, | ||
} | ||
|
||
client := makeClient(PublicURL + "/mobile/v1/device") | ||
|
||
for _, c := range cases { | ||
res, err := client.R(). | ||
SetHeader("Content-Type", "application/json"). | ||
SetBody(`{"name": "Public Device Name", "pushToken": "token"}`). | ||
SetHeaders(c.headers). | ||
Post("") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if res.StatusCode() != c.expectedStatusCode { | ||
t.Fatal(res.StatusCode(), res.String()) | ||
} | ||
} | ||
} | ||
|
||
func TestPrivateDeviceRegister(t *testing.T) { | ||
cases := []struct { | ||
headers map[string]string | ||
expectedStatusCode int | ||
}{ | ||
{ | ||
headers: map[string]string{ | ||
"Authorization": "Bearer 123456789", | ||
}, | ||
expectedStatusCode: 201, | ||
}, | ||
{ | ||
headers: map[string]string{}, | ||
expectedStatusCode: 401, | ||
}, | ||
{ | ||
headers: map[string]string{ | ||
"Authorization": "Bearer 987654321", | ||
}, | ||
expectedStatusCode: 401, | ||
}, | ||
} | ||
|
||
client := makeClient(PrivateURL + "/mobile/v1/device") | ||
|
||
for _, c := range cases { | ||
res, err := client.R(). | ||
SetHeader("Content-Type", "application/json"). | ||
SetBody(`{"name": "Private Device Name", "pushToken": "token"}`). | ||
SetHeaders(c.headers). | ||
Post("") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if res.StatusCode() != c.expectedStatusCode { | ||
t.Fatal(res.StatusCode(), res.String()) | ||
} | ||
} | ||
} |