mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-26 21:22:16 +08:00 
			
		
		
		
	fix: fix openim zk env set
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
		
							parent
							
								
									47dd6b17f6
								
							
						
					
					
						commit
						f937419175
					
				| @ -24,7 +24,8 @@ import ( | |||||||
| 
 | 
 | ||||||
| func setupTestEnvironment() { | func setupTestEnvironment() { | ||||||
| 	os.Setenv("ZOOKEEPER_SCHEMA", "openim") | 	os.Setenv("ZOOKEEPER_SCHEMA", "openim") | ||||||
| 	os.Setenv("ZOOKEEPER_ADDRESS", "172.28.0.1:12181") | 	os.Setenv("ZOOKEEPER_ADDRESS", "172.28.0.1") | ||||||
|  | 	os.Setenv("ZOOKEEPER_PORT", "12181") | ||||||
| 	os.Setenv("ZOOKEEPER_USERNAME", "") | 	os.Setenv("ZOOKEEPER_USERNAME", "") | ||||||
| 	os.Setenv("ZOOKEEPER_PASSWORD", "") | 	os.Setenv("ZOOKEEPER_PASSWORD", "") | ||||||
| } | } | ||||||
|  | |||||||
| @ -52,10 +52,18 @@ func getEnv(key, fallback string) string { | |||||||
| 	return fallback | 	return fallback | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // getZkAddrFromEnv returns the value of an environment variable if it exists, otherwise it returns the fallback value. | // getZkAddrFromEnv returns the Zookeeper addresses combined from the ZOOKEEPER_ADDRESS and ZOOKEEPER_PORT environment variables. | ||||||
|  | // If the environment variables are not set, it returns the fallback value. | ||||||
| func getZkAddrFromEnv(fallback []string) []string { | func getZkAddrFromEnv(fallback []string) []string { | ||||||
| 	if value, exists := os.LookupEnv("ZOOKEEPER_ADDRESS"); exists { | 	address, addrExists := os.LookupEnv("ZOOKEEPER_ADDRESS") | ||||||
| 		return strings.Split(value, ",") | 	port, portExists := os.LookupEnv("ZOOKEEPER_PORT") | ||||||
|  | 
 | ||||||
|  | 	if addrExists && portExists { | ||||||
|  | 		addresses := strings.Split(address, ",") | ||||||
|  | 		for i, addr := range addresses { | ||||||
|  | 			addresses[i] = addr + ":" + port | ||||||
|  | 		} | ||||||
|  | 		return addresses | ||||||
| 	} | 	} | ||||||
| 	return fallback | 	return fallback | ||||||
| } | } | ||||||
|  | |||||||
| @ -21,22 +21,10 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"github.com/redis/go-redis/v9" | 	"github.com/redis/go-redis/v9" | ||||||
| 	"github.com/stretchr/testify/assert" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/common/config" | 	"github.com/openimsdk/open-im-server/v3/pkg/common/config" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestCheckMysql(t *testing.T) { |  | ||||||
| 	err := mockInitCfg() |  | ||||||
| 	assert.NoError(t, err, "Initialization should not produce errors") |  | ||||||
| 
 |  | ||||||
| 	err = checkMysql() |  | ||||||
| 	if err != nil { |  | ||||||
| 		// You might expect an error if MySQL isn't running locally with the mock credentials. |  | ||||||
| 		t.Logf("Expected error due to mock configuration: %v", err) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Mock for initCfg for testing purpose | // Mock for initCfg for testing purpose | ||||||
| func mockInitCfg() error { | func mockInitCfg() error { | ||||||
| 	config.Config.Mysql.Username = "root" | 	config.Config.Mysql.Username = "root" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user