Skip to content

Commit

Permalink
feat: refactor GetVersion function and add test cases in common/func_…
Browse files Browse the repository at this point in the history
…test.go

- Change the second parameter in the `GetVersion` function from `p` to `typ`
- Remove the metadata line with `if len(v) != 2 {` and the closing bracket `}` at the end of the function
- Remove the return statement `return v[1]` and add a new return statement `return version`
- Add a new file `common/func_test.go`
- Add two test cases for the `GetVersion` function in the new file

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed May 24, 2024
1 parent 54c4566 commit 3ce2c3f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
36 changes: 20 additions & 16 deletions common/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,28 @@ func GetChannel(p string) string {
}

// GetVersion 获取版本地址
func GetVersion(devops bool, p, version string) string {
func GetVersion(devops bool, typ, version string) string {
if !devops {
// 渠成不支持版本
return DefaultQuickonOSSVersion
}
v := strings.Split(version, "-")
if len(v) != 2 {
switch p {
case string(ZenTaoIPDType):
return DefaultZentaoDevOPSIPDVersion
case string(ZenTaoBizType):
return DefaultZentaoDevOPSBizVersion
case string(ZenTaoMaxType):
return DefaultZentaoDevOPSMaxVersion
default:
if devops {
return DefaultZentaoDevOPSOSSVersion
}
return DefaultQuickonOSSVersion
}
if len(v) == 2 {
return v[1]
}
defaultVersion := DefaultZentaoDevOPSOSSVersion
switch typ {
case string(ZenTaoIPDType):
defaultVersion = DefaultZentaoDevOPSIPDVersion
case string(ZenTaoBizType):
defaultVersion = DefaultZentaoDevOPSBizVersion
case string(ZenTaoMaxType):
defaultVersion = DefaultZentaoDevOPSMaxVersion
}
if version == defaultVersion || len(version) == 0 {
return defaultVersion
}
return v[1]
return version
}

func GetDefaultConfig() string {
Expand Down
48 changes: 48 additions & 0 deletions common/func_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2021-2023 北京渠成软件有限公司(Beijing Qucheng Software Co., Ltd. www.qucheng.com) All rights reserved.
// Use of this source code is covered by the following dual licenses:
// (1) Z PUBLIC LICENSE 1.2 (ZPL 1.2)
// (2) Affero General Public License 3.0 (AGPL 3.0)
// license that can be found in the LICENSE file.

package common

import "testing"

func TestGetVersion(t *testing.T) {
type args struct {
devops bool
typ string
version string
}
tests := []struct {
name string
args args
want string
}{
{
name: "test1",
args: args{
devops: true,
typ: "oss",
version: "v1.0.0",
},
want: "v1.0.0",
},
{
name: "test2",
args: args{
devops: true,
typ: "oss",
version: "",
},
want: DefaultZentaoDevOPSOSSVersion,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetVersion(tt.args.devops, tt.args.typ, tt.args.version); got != tt.want {
t.Logf("GetVersion() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion pkg/quickon/quickon.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (m *Meta) Init() error {
}
}
installVersion := common.GetVersion(m.DevopsMode, m.Type, m.Version)
m.Log.Infof("devops: %v, type: %s, version: %s(%s), channel: %s", m.DevopsMode, m.Type, m.Version, installVersion, common.GetChannel(m.Version))
m.Log.Infof("devops: %v, type: %s, version: %s, channel: %s", m.DevopsMode, m.Type, installVersion, common.GetChannel(m.Version))
m.Log.Debugf("start init %s", common.GetInstallType(m.DevopsMode))
cfg.Quickon.Type = common.QuickonType(m.Type)
cfg.Quickon.DevOps = m.DevopsMode
Expand Down

0 comments on commit 3ce2c3f

Please sign in to comment.