Skip to content

Commit

Permalink
fix: fix openim zk env set
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
  • Loading branch information
cubxxw committed Dec 27, 2023
1 parent 47dd6b1 commit f937419
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pkg/common/discoveryregister/discoveryregister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (

func setupTestEnvironment() {
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_PASSWORD", "")
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/common/discoveryregister/zookeeper/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ func getEnv(key, fallback string) string {
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 {
if value, exists := os.LookupEnv("ZOOKEEPER_ADDRESS"); exists {
return strings.Split(value, ",")
address, addrExists := os.LookupEnv("ZOOKEEPER_ADDRESS")
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
}
12 changes: 0 additions & 12 deletions tools/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,10 @@ import (
"time"

"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"

"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
func mockInitCfg() error {
config.Config.Mysql.Username = "root"
Expand Down

0 comments on commit f937419

Please sign in to comment.