mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 01:48:22 +00:00
ad basic ci testing
This commit is contained in:
parent
28e2ccf7e4
commit
54f4b4ca23
3 changed files with 118 additions and 0 deletions
34
.github/workflows/.go.yml
vendored
Normal file
34
.github/workflows/.go.yml
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
|
- name: "Setup Passbolt"
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/passbolt/passbolt_docker.git ../passbolt_docker
|
||||||
|
cd ../passbolt_docker
|
||||||
|
docker-compose up -d
|
||||||
|
docker ps -a
|
||||||
|
- name: "Test"
|
||||||
|
run: |
|
||||||
|
docker exec passbolt_docker_passbolt_1 sh -c '/usr/bin/wait-for.sh -t 30 localhost:443'
|
||||||
|
output=$(docker exec passbolt_docker_passbolt_1 sh -c 'su -m -c "/usr/share/php/passbolt/bin/cake \
|
||||||
|
passbolt register_user \
|
||||||
|
-u your@email.com \
|
||||||
|
-f yourname \
|
||||||
|
-l surname \
|
||||||
|
-r admin" -s /bin/sh www-data')
|
||||||
|
export REG_URL=$(echo ${output##* your mailbox or here: } | tr -d '\n')
|
||||||
|
echo "Register with $REG_URL"
|
||||||
|
go test -v ./...
|
30
helper/resource_test.go
Normal file
30
helper/resource_test.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestResourceCreate(t *testing.T) {
|
||||||
|
id, err := CreateResource(context.TODO(), client, "", "name", "username", "https://url.lan", "password123", "a password description")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Creating Resource %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, name, username, uri, password, description, err := GetResource(context.TODO(), client, id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Getting Resource %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
equal(t, "Name", name, "name")
|
||||||
|
equal(t, "Username", username, "username")
|
||||||
|
equal(t, "URI", uri, "https://url.lan")
|
||||||
|
equal(t, "Password", password, "password123")
|
||||||
|
equal(t, "Description", description, "a password description")
|
||||||
|
}
|
||||||
|
|
||||||
|
func equal(t *testing.T, name, a, b string) {
|
||||||
|
if a != b {
|
||||||
|
t.Fatalf("Value %v is %v instead of %v", name, a, b)
|
||||||
|
}
|
||||||
|
}
|
54
helper/setup_test.go
Normal file
54
helper/setup_test.go
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/speatzle/go-passbolt/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
var client *api.Client
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
url := os.Getenv("REG_URL")
|
||||||
|
fmt.Printf("Registering with url: %v\n", url)
|
||||||
|
userID, token, err := ParseInviteUrl(url)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Unable to Parse Invite URL: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
tr := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
}
|
||||||
|
hc := &http.Client{Transport: tr}
|
||||||
|
|
||||||
|
rc, err := api.NewClient(hc, "", "https://localhost", "", "")
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Creating Registration Client: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
privkey, err := SetupAccount(ctx, rc, userID, token, "password123")
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Setup Account: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err := api.NewClient(hc, "", "https://localhost", privkey, "password123")
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Setup Client: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Login(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Login Client: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
client = c
|
||||||
|
|
||||||
|
os.Exit(m.Run())
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue