diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 9e9704c91..535c30f75 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -79,10 +79,22 @@ jobs: sudo make tidy sudo make tools.verify.go-gitlint - - name: Build, Start, Test, Check Services and Print Logs + - name: Build, Start run: | - sudo ./scripts/install/install.sh -i && \ - sudo make test-api && \ - sudo ./scripts/install/install.sh -s && \ - sudo ./scripts/install/install.sh -u || \ - (echo "An error occurred, printing logs:" && sudo cat ./_output/logs/* 2>/dev/null) + sudo ./scripts/install/install.sh -i + + - name: Exec OpenIM System Status Chack + run: | + 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 \ No newline at end of file diff --git a/Makefile b/Makefile index 42d82274e..dedc25e11 100644 --- a/Makefile +++ b/Makefile @@ -171,6 +171,10 @@ cover: 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. ✨ .PHONY: updates @$(MAKE) go.updates diff --git a/chat b/chat new file mode 100755 index 000000000..b79e06dd7 Binary files /dev/null and b/chat differ diff --git a/scripts/make-rules/golang.mk b/scripts/make-rules/golang.mk index e0cb5861d..113625ef6 100644 --- a/scripts/make-rules/golang.mk +++ b/scripts/make-rules/golang.mk @@ -199,6 +199,12 @@ go.test.api: @echo "===========> Run api 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 .PHONY: go.demo go.demo: diff --git a/test/e2e/README.md b/test/e2e/README.md index 80d6da127..6779d0592 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -52,6 +52,14 @@ The E2E tests are organized into the following directory structure: ## 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: - Docker diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index df8caf702..b70bf6651 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -1 +1,2 @@ package e2e + diff --git a/test/e2e/framework/helpers/chat/chat.go b/test/e2e/framework/helpers/chat/chat.go new file mode 100644 index 000000000..4fca28f2a --- /dev/null +++ b/test/e2e/framework/helpers/chat/chat.go @@ -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) + } +} diff --git a/test/e2e/upgrade/README.go b/test/e2e/upgrade/README.go deleted file mode 100644 index e69de29bb..000000000