Skip to content

Commit

Permalink
turn e2e tests job back on, fix userapi test
Browse files Browse the repository at this point in the history
  • Loading branch information
adwski committed May 13, 2024
1 parent 7db87e8 commit 5253739
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 33 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: e2e tests

on: {}

# pull_request:
# push:
# branches:
# - main
on:
pull_request:
push:
branches:
- main

jobs:

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: unit tests

on:
pull_request:
push:
branches:
- main
on: {}
# pull_request:
# push:
# branches:
# - main

jobs:

Expand Down
6 changes: 3 additions & 3 deletions e2e/e2e_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func userRegister(t *testing.T, user *model.UserRequest) *http.Cookie {
resp, body := makeCommonRequest(t, endpointUserRegister, user)
require.True(t, resp.IsSuccess())
require.Empty(t, body.Error)
require.Equal(t, "ok", body.Message)
require.Equal(t, "registration complete", body.Message)
return getCookieWithToken(t, resp.Cookies())
}

Expand All @@ -52,7 +52,7 @@ func userLogin(t *testing.T, user *model.UserRequest) *http.Cookie {
resp, body := makeCommonRequest(t, endpointUserLogin, user)
require.True(t, resp.IsSuccess())
require.Empty(t, body.Error)
require.Equal(t, "login ok", body.Message)
require.Equal(t, "ok", body.Message)
return getCookieWithToken(t, resp.Cookies())
}

Expand Down Expand Up @@ -266,7 +266,7 @@ func videoCreate(t *testing.T, userCookie *http.Cookie) *videohttp.VideoResponse
require.Empty(t, errBody.Error)
require.NotEmpty(t, videoBody.CreatedAt)
require.NotEmpty(t, videoBody.ID)
require.NotEmpty(t, videoBody.UploadURL)
require.NotEmpty(t, videoBody.UploadInfo.URL)

status, err := video.GetStatusFromName(videoBody.Status)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestMain(m *testing.M) {
wg.Done()
}()

time.Sleep(3 * time.Second)
time.Sleep(5 * time.Second)

code := m.Run()
cancel()
Expand Down
2 changes: 1 addition & 1 deletion e2e/processor.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
log:
level: debug
videoapi:
endpoint: http://localhost:18082/api/video
endpoint: localhost:18093
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJzdmMtQnNwMjhpcG1TSFdkSTdTSXdQMEo0QSIsIm5hbWUiOiJub3RpZmljYXRvciIsInJvbGUiOiJzZXJ2aWNlIiwiZXhwIjoxNzM2ODgwMDk0fQ.xjMV5Z_EBGch6fYM9ZSSC3W9QKjij2S0zI8HGz8wrAY"
s3:
prefix_upload: /upload
Expand Down
3 changes: 2 additions & 1 deletion e2e/streamer.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
log:
level: debug
server:
address: ":18084"
http:
address: ":18084"
api:
prefix: /watch
redis:
Expand Down
5 changes: 3 additions & 2 deletions e2e/uploader.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
log:
level: debug
server:
address: ":18083"
http:
address: ":18083"
api:
prefix: /upload
redis:
dsn: redis://localhost:6379/0
videoapi:
endpoint: http://localhost:18082/api/video
endpoint: localhost:18093
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJzdmMtQnNwMjhpcG1TSFdkSTdTSXdQMEo0QSIsIm5hbWUiOiJub3RpZmljYXRvciIsInJvbGUiOiJzZXJ2aWNlIiwiZXhwIjoxNzM2ODgwMDk0fQ.xjMV5Z_EBGch6fYM9ZSSC3W9QKjij2S0zI8HGz8wrAY"
s3:
prefix_upload: /upload
Expand Down
3 changes: 2 additions & 1 deletion e2e/userapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
log:
level: debug
server:
address: ":18081"
http:
address: ":18081"
api:
prefix: /api/user
database:
Expand Down
20 changes: 15 additions & 5 deletions e2e/userapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@ package e2e

import (
"net/http"
"strconv"
"testing"
"time"

"github.com/adwski/vidi/internal/api/user/model"
)

var (
testUserName = "testuser"
)

func init() {
testUserName += strconv.Itoa(int(time.Now().Unix()))
}

func TestUserRegistration(t *testing.T) {
//-------------------------------------------------------------------------------
// Login with not-existent user
//-------------------------------------------------------------------------------
userLoginFail(t, &model.UserRequest{
Username: "testuser",
Username: testUserName,
Password: "testpass",
}, http.StatusUnauthorized)

//-------------------------------------------------------------------------------
// Register user
//-------------------------------------------------------------------------------
cookie := userRegister(t, &model.UserRequest{
Username: "testuser",
Username: testUserName,
Password: "testpass",
})
t.Logf("user is registered, token: %v", cookie.Value)
Expand All @@ -31,7 +41,7 @@ func TestUserRegistration(t *testing.T) {
// Register existing user
//-------------------------------------------------------------------------------
userRegisterFail(t, &model.UserRequest{
Username: "testuser",
Username: testUserName,
Password: "testpass",
}, http.StatusConflict)

Expand All @@ -46,7 +56,7 @@ func TestUserLogin(t *testing.T) {
// Login with existent user
//-------------------------------------------------------------------------------
cookie2 := userLogin(t, &model.UserRequest{
Username: "testuser",
Username: testUserName,
Password: "testpass",
})
t.Logf("user is logged in, token: %v", cookie2.Value)
Expand All @@ -63,7 +73,7 @@ func TestUserLogin(t *testing.T) {
// Login with wrong password
//-------------------------------------------------------------------------------
userLoginFail(t, &model.UserRequest{
Username: "testuser",
Username: testUserName,
Password: "testpass2",
}, http.StatusUnauthorized)

Expand Down
6 changes: 5 additions & 1 deletion e2e/videoapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
log:
level: debug
server:
address: ":18082"
http:
address: ":18082"
grpc:
address: ":18092"
svc_address: ":18093"
api:
prefix: /api/video
database:
Expand Down
14 changes: 7 additions & 7 deletions e2e/videoapi_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build e2e
//go:build e2e && skip

package e2e

Expand Down Expand Up @@ -34,7 +34,7 @@ func TestCreateAndDeleteVideo(t *testing.T) {
// Create video
//-------------------------------------------------------------------------------
videoResponse := videoCreate(t, cookie)
t.Logf("video created, id: %s, upload url: %v", videoResponse.ID, videoResponse.UploadURL)
t.Logf("video created, id: %s, upload url: %v", videoResponse.ID, videoResponse.UploadInfo.URL)

//-------------------------------------------------------------------------------
// Get video
Expand Down Expand Up @@ -67,12 +67,12 @@ func TestCreateAndUploadVideo(t *testing.T) {
// Create video
//-------------------------------------------------------------------------------
videoResponse := videoCreate(t, cookie)
t.Logf("video created, id: %s, upload url: %v", videoResponse.ID, videoResponse.UploadURL)
t.Logf("video created, id: %s, upload url: %v", videoResponse.ID, videoResponse.UploadInfo.URL)

//-------------------------------------------------------------------------------
// Upload video
//-------------------------------------------------------------------------------
videoUpload(t, videoResponse.UploadURL)
videoUpload(t, videoResponse.UploadInfo.URL)

//-------------------------------------------------------------------------------
// Wait until processed
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestFails(t *testing.T) {
// Create video
//-------------------------------------------------------------------------------
videoResponse := videoCreate(t, cookie)
t.Logf("video created, id: %s, upload url: %v", videoResponse.ID, videoResponse.UploadURL)
t.Logf("video created, id: %s, upload url: %v", videoResponse.ID, videoResponse.UploadInfo.URL)

//-------------------------------------------------------------------------------
// Get video
Expand All @@ -158,12 +158,12 @@ func TestFails(t *testing.T) {
//-------------------------------------------------------------------------------
// Upload video, invalid request
//-------------------------------------------------------------------------------
videoUploadFailGet(t, videoResponse.UploadURL)
videoUploadFailGet(t, videoResponse.UploadInfo.URL)

//-------------------------------------------------------------------------------
// Upload video, invalid requests
//-------------------------------------------------------------------------------
url := videoResponse.UploadURL[:strings.LastIndex(videoResponse.UploadURL, "/")]
url := videoResponse.UploadInfo.URL[:strings.LastIndex(videoResponse.UploadInfo.URL, "/")]
videoUploadFail(t, url)
videoUploadFail(t, url+"/qweqwe/")
}

0 comments on commit 5253739

Please sign in to comment.