Skip to content

Commit

Permalink
test config
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaomingqiang committed Oct 31, 2020
1 parent 64e7a66 commit 4bb7a11
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ output
coverage
modules.txt
*.log
test
*_test.go
*.json
*.sh
12 changes: 6 additions & 6 deletions core/config/app_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func GetInternalAppSettingsByEnv() *AppSettings {
return NewInternalAppSettings(appID, appSecret, verificationToken, encryptKey)
}

func NewISVAppSettings(appID, appSecret, verificationToken, eventEncryptKey string) *AppSettings {
return newAppSettings(constants.AppTypeISV, appID, appSecret, verificationToken, eventEncryptKey)
func NewISVAppSettings(appID, appSecret, verificationToken, encryptKey string) *AppSettings {
return newAppSettings(constants.AppTypeISV, appID, appSecret, verificationToken, encryptKey)
}

func NewInternalAppSettings(appID, appSecret, verificationToken, eventEncryptKey string) *AppSettings {
return newAppSettings(constants.AppTypeInternal, appID, appSecret, verificationToken, eventEncryptKey)
func NewInternalAppSettings(appID, appSecret, verificationToken, encryptKey string) *AppSettings {
return newAppSettings(constants.AppTypeInternal, appID, appSecret, verificationToken, encryptKey)
}

func newAppSettings(appType constants.AppType, appID, appSecret, verificationToken, eventEncryptKey string) *AppSettings {
func newAppSettings(appType constants.AppType, appID, appSecret, verificationToken, encryptKey string) *AppSettings {
if appID == "" || appSecret == "" {
panic("appID or appSecret is empty")
}
Expand All @@ -41,7 +41,7 @@ func newAppSettings(appType constants.AppType, appID, appSecret, verificationTok
AppID: appID,
AppSecret: appSecret,
VerificationToken: verificationToken,
EncryptKey: eventEncryptKey,
EncryptKey: encryptKey,
}
}

Expand Down
44 changes: 44 additions & 0 deletions core/test/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package test

import (
"github.com/larksuite/oapi-sdk-go/core/config"
"github.com/larksuite/oapi-sdk-go/core/constants"
"os"
"strings"
)

func domainFeiShu(env string) string {
return os.Getenv(env + "_FEISHU_DOMAIN")
}

func getISVAppSettings(env string) *config.AppSettings {
appID, appSecret, verificationToken, encryptKey := os.Getenv(env+"_ISV_APP_ID"),
os.Getenv(env+"_ISV_APP_SECRET"), os.Getenv(env+"_ISV_VERIFICATION_TOKEN"), os.Getenv(env+"_ISV_ENCRYPT_KEY")
return config.NewISVAppSettings(appID, appSecret, verificationToken, encryptKey)
}

func getInternalAppSettings(env string) *config.AppSettings {
appID, appSecret, verificationToken, encryptKey := os.Getenv(env+"_INTERNAL_APP_ID"),
os.Getenv(env+"_INTERNAL_APP_SECRET"), os.Getenv(env+"_INTERNAL_VERIFICATION_TOKEN"), os.Getenv(env+"_INTERNAL_ENCRYPT_KEY")
return config.NewInternalAppSettings(appID, appSecret, verificationToken, encryptKey)
}

func GetISVConf(env string) *config.Config {
env = strings.ToUpper(env)
return config.NewTestConfig(getDomain(env), getISVAppSettings(env))
}

func GetInternalConf(env string) *config.Config {
env = strings.ToUpper(env)
return config.NewTestConfig(getDomain(env), getInternalAppSettings(env))
}

func getDomain(env string) constants.Domain {
if env != "STAGING" && env != "PRE" && env != "ONLINE" {
panic("env must in [staging, pre, online]")
}
if env == "ONLINE" {
return constants.DomainFeiShu
}
return constants.Domain(domainFeiShu(env))
}
35 changes: 0 additions & 35 deletions core/test/test_data.go

This file was deleted.

2 changes: 1 addition & 1 deletion sample/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"os"
)

var conf = test.GetOnlineInternalConf()
var conf = test.GetInternalConf("online")

func main() {
testSendMessage()
Expand Down
2 changes: 1 addition & 1 deletion sample/card/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func main() {

conf := test.GetOnlineInternalConf()
var conf = test.GetInternalConf("online")

card.SetHandler(conf, func(coreCtx *core.Context, card *model.Card) (interface{}, error) {
fmt.Println(coreCtx.GetRequestID())
Expand Down
2 changes: 1 addition & 1 deletion sample/card/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func main() {

conf := test.GetOnlineInternalConf()
var conf = test.GetInternalConf("online")

card.SetHandler(conf, func(ctx *core.Context, card *model.Card) (interface{}, error) {
fmt.Println(ctx.GetRequestID())
Expand Down
2 changes: 1 addition & 1 deletion sample/event/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func main() {

conf := test.GetStagingISVConf()
var conf = test.GetISVConf("online")

application.SetAppOpenEventHandler(conf, func(ctx *core.Context, appOpenEvent *application.AppOpenEvent) error {
fmt.Println(ctx.GetRequestID())
Expand Down
2 changes: 1 addition & 1 deletion sample/event/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func main() {

conf := test.GetStagingISVConf()
var conf = test.GetISVConf("online")

application.SetAppOpenEventHandler(conf, func(coreCtx *core.Context, appOpenEvent *application.AppOpenEvent) error {
fmt.Println(coreCtx.GetRequestID())
Expand Down

0 comments on commit 4bb7a11

Please sign in to comment.