mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-08 13:37:13 +08:00
feat: add openim test .keep
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
parent
79b70c450f
commit
9c539c7197
24
.github/workflows/e2e-test.yml
vendored
24
.github/workflows/e2e-test.yml
vendored
@ -79,10 +79,22 @@ jobs:
|
|||||||
sudo make tidy
|
sudo make tidy
|
||||||
sudo make tools.verify.go-gitlint
|
sudo make tools.verify.go-gitlint
|
||||||
|
|
||||||
- name: Build, Start, Test, Check Services and Print Logs
|
- name: Build, Start
|
||||||
run: |
|
run: |
|
||||||
sudo ./scripts/install/install.sh -i && \
|
sudo ./scripts/install/install.sh -i
|
||||||
sudo make test-api && \
|
|
||||||
sudo ./scripts/install/install.sh -s && \
|
- name: Exec OpenIM System Status Chack
|
||||||
sudo ./scripts/install/install.sh -u || \
|
run: |
|
||||||
(echo "An error occurred, printing logs:" && sudo cat ./_output/logs/* 2>/dev/null)
|
sudo ./scripts/install/install.sh -s
|
||||||
|
|
||||||
|
- name: Exec OpenIM API test
|
||||||
|
run: |
|
||||||
|
sudo make test-api
|
||||||
|
|
||||||
|
- name: Exec OpenIM E2E test
|
||||||
|
run: |
|
||||||
|
sudo make test-e2e
|
||||||
|
|
||||||
|
- name: Exec OpenIM System uninstall
|
||||||
|
run: |
|
||||||
|
sudo ./scripts/install/install.sh -u
|
||||||
4
Makefile
4
Makefile
@ -171,6 +171,10 @@ cover:
|
|||||||
test-api:
|
test-api:
|
||||||
@$(MAKE) go.test.api
|
@$(MAKE) go.test.api
|
||||||
|
|
||||||
|
## test-e2e: Run e2e test
|
||||||
|
test-api:
|
||||||
|
@$(MAKE) go.test.e2e
|
||||||
|
|
||||||
## updates: Check for updates to go.mod dependencies. ✨
|
## updates: Check for updates to go.mod dependencies. ✨
|
||||||
.PHONY: updates
|
.PHONY: updates
|
||||||
@$(MAKE) go.updates
|
@$(MAKE) go.updates
|
||||||
|
|||||||
@ -199,6 +199,12 @@ go.test.api:
|
|||||||
@echo "===========> Run api test"
|
@echo "===========> Run api test"
|
||||||
@$(ROOT_DIR)/scripts/install/test.sh openim::test::test
|
@$(ROOT_DIR)/scripts/install/test.sh openim::test::test
|
||||||
|
|
||||||
|
## go.test.e2e: Run e2e test
|
||||||
|
.PHONY: go.test.e2e
|
||||||
|
go.test.e2e:
|
||||||
|
@echo "===========> Run e2e test"
|
||||||
|
@$(ROOT_DIR)/scripts/install/test.sh openim::test::e2e
|
||||||
|
|
||||||
## go.demo: Run demo
|
## go.demo: Run demo
|
||||||
.PHONY: go.demo
|
.PHONY: go.demo
|
||||||
go.demo:
|
go.demo:
|
||||||
|
|||||||
@ -52,6 +52,14 @@ The E2E tests are organized into the following directory structure:
|
|||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
|
Since the deployment of OpenIM requires some components such as Mongo and Kafka, you should think a bit before using E2E tests
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
OR User [kubernetes deployment](https://github.com/openimsdk/helm-charts)
|
||||||
|
|
||||||
Before running the E2E tests, ensure that you have the following prerequisites installed:
|
Before running the E2E tests, ensure that you have the following prerequisites installed:
|
||||||
|
|
||||||
- Docker
|
- Docker
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
|
|||||||
152
test/e2e/framework/helpers/chat/chat.go
Normal file
152
test/e2e/framework/helpers/chat/chat.go
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// The default template version
|
||||||
|
defaultTemplateVersion = "v1.3.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Define the URL to get the latest version
|
||||||
|
// latestVersionURL := "https://github.com/openimsdk/chat/releases/latest"
|
||||||
|
// latestVersion, err := getLatestVersion(latestVersionURL)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Printf("Failed to get the latest version: %v\n", err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
latestVersion := defaultTemplateVersion
|
||||||
|
|
||||||
|
// Construct the download URL
|
||||||
|
downloadURL := fmt.Sprintf("https://github.com/openimsdk/chat/releases/download/%s/chat_Linux_x86_64.tar.gz", latestVersion)
|
||||||
|
|
||||||
|
// Set the installation directory
|
||||||
|
installDir := "/tmp/chat"
|
||||||
|
|
||||||
|
// Clear the installation directory before proceeding
|
||||||
|
err := os.RemoveAll(installDir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to clear installation directory: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the installation directory
|
||||||
|
err = os.MkdirAll(installDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to create installation directory: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download and extract OpenIM Chat to the installation directory
|
||||||
|
err = downloadAndExtract(downloadURL, installDir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to download and extract OpenIM Chat: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create configuration file directory
|
||||||
|
configDir := filepath.Join(installDir, "config")
|
||||||
|
err = os.MkdirAll(configDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to create configuration directory: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download configuration files
|
||||||
|
configURL := "https://raw.githubusercontent.com/openimsdk/chat/main/config/config.yaml"
|
||||||
|
err = downloadAndExtract(configURL, configDir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to download and extract configuration files: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the processes to be started
|
||||||
|
cmds := []string{
|
||||||
|
"admin-api",
|
||||||
|
"admin-rpc",
|
||||||
|
"chat-api",
|
||||||
|
"chat-rpc",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start each process in a new goroutine
|
||||||
|
for _, cmd := range cmds {
|
||||||
|
go startProcess(filepath.Join(installDir, cmd))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block the main thread indefinitely
|
||||||
|
select {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getLatestVersion fetches the latest version number from a given URL
|
||||||
|
func getLatestVersion(url string) (string, error) {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
location := resp.Header.Get("Location")
|
||||||
|
if location == "" {
|
||||||
|
return defaultTemplateVersion, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the version number from the URL
|
||||||
|
latestVersion := filepath.Base(location)
|
||||||
|
return latestVersion, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// downloadAndExtract downloads a file from a URL and extracts it to a destination directory
|
||||||
|
func downloadAndExtract(url, destDir string) error {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("error downloading file, HTTP status code: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the destination directory
|
||||||
|
err = os.MkdirAll(destDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the path for the downloaded file
|
||||||
|
filePath := filepath.Join(destDir, "downloaded_file.tar.gz")
|
||||||
|
file, err := os.Create(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Copy the downloaded file
|
||||||
|
_, err = io.Copy(file, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the file
|
||||||
|
cmd := exec.Command("tar", "xzvf", filePath, "-C", destDir)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
// startProcess starts a process and prints any errors encountered
|
||||||
|
func startProcess(cmdPath string) {
|
||||||
|
cmd := exec.Command(cmdPath)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
fmt.Printf("Failed to start process %s: %v\n", cmdPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user