作者 yangfu

增加测试用例

... ... @@ -7,10 +7,7 @@ aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#阿里云基础配置
AccessKeyID ="LTAI4FhiZ3UktC6N1u3H5GFC"
AccessKeySecret ="UyspWwdni55CYQ02hUCint4qY2jNYO"
#AccessKeyID ="LTAI4Fz1LUBW2fXp6QWaJHRS"
#AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
#阿里云->绑定域名 cname = https://media.goexample.live/
cname ="https://media.fjmaimaimai.com/"
cname ="https://media.goexample.live/"
#友盟推送
... ...
... ... @@ -7,5 +7,5 @@ AccessKeySecret ="aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
log_level = "${LOG_LEVEL||debug}"
aliyun_logs_access ="${aliyun_logs_access||F:/log/app.log}"
#阿里云 https://media.goexample.live/
#阿里云
cname ="https://media.fjmaimaimai.com/"
... ...
... ... @@ -3,11 +3,25 @@ module openapi
go 1.12
require (
github.com/ajg/form v1.5.1 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.60.348
github.com/aliyun/aliyun-sts-go-sdk v0.0.0-20171106034748-98d3903a2309
github.com/astaxie/beego v1.10.0
github.com/fatih/structs v1.1.0 // indirect
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/klauspost/cpuid v1.2.3 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.10.3
github.com/onsi/gomega v1.7.1
github.com/satori/go.uuid v1.2.0
github.com/sergi/go-diff v1.1.0 // indirect
github.com/valyala/fasthttp v1.13.1 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
)
... ...
... ... @@ -3,7 +3,9 @@ package main
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/pkg/constant"
_ "openapi/pkg/log"
_ "openapi/pkg/port/beego"
)
... ... @@ -12,6 +14,6 @@ func main() {
log.Info("server on stop!")
}()
log.Info("server on start!")
constant.DebugConfig()
beego.Run()
}
... ...
package service
import (
"github.com/astaxie/beego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/pkg/constant"
protocol "openapi/pkg/domain"
"openapi/pkg/infrastructure/aliyun"
"openapi/pkg/infrastructure/utils"
... ... @@ -44,7 +44,7 @@ func CreateUploadVideo(header *protocol.RequestHeader, request *aliyun.CreateUpl
return
}
rsp.FileName = fileName
rsp.FileURL = up.GetFileUrl(beego.AppConfig.String("cname"))
rsp.FileURL = up.GetFileUrl(constant.CName)
return
}
... ...
package constant
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
)
var (
LogFilePath string = "F:/log/app.log"
LogLevel string = "error"
)
func init() {
LogLevel = config.StringDefault("log_level", LogLevel)
LogFilePath = config.StringDefault("aliyun_logs_access", LogFilePath)
}
func DebugConfig() {
for i := range config.HistorySort {
k := config.HistorySort[i]
v, ok := config.History[k]
if !ok {
continue
}
log.Debug(fmt.Sprintf("【load config】 %v=%v", k, v))
}
}
... ...
package constant
import (
"github.com/astaxie/beego"
)
var config = NewConfigLoader()
type ConfigLoader struct {
History map[string]interface{}
HistorySort []string
}
func NewConfigLoader() *ConfigLoader {
return &ConfigLoader{
History: make(map[string]interface{}),
HistorySort: make([]string, 0),
}
}
func (c *ConfigLoader) String(key string) (ret string, ok bool) {
if ret = beego.AppConfig.String(key); len(ret) != 0 {
ok = true
c.SetHistory(key, ret)
return
}
return
}
func (c *ConfigLoader) StringDefault(key string, defaultValue string) string {
if ret, ok := c.String(key); ok {
return ret
}
return defaultValue
}
func (c *ConfigLoader) SetHistory(key string, value interface{}) {
if _, ok := c.History[key]; !ok {
c.History[key] = value
c.HistorySort = append(c.HistorySort, key)
}
}
... ...
package constant
var (
RegionID = "cn-shanghai"
AccessKeyID string = "LTAI4FhiZ3UktC6N1u3H5GFC"
AccessKeySecret string = "UyspWwdni55CYQ02hUCint4qY2jNYO"
CName string = "https://media.goexample.live/"
)
func init() {
AccessKeyID = config.StringDefault("AccessKeyID", AccessKeyID)
AccessKeySecret = config.StringDefault("AccessKeySecret", AccessKeySecret)
CName = config.StringDefault("cname", CName)
}
... ...
package aliyun
import "github.com/astaxie/beego"
var (
RegionID = "cn-shanghai"
AccessKeyID = beego.AppConfig.String("AccessKeyID")
AccessKeySecret = beego.AppConfig.String("AccessKeySecret")
//RegionID = "cn-shanghai"
//AccessKeyID = beego.AppConfig.String("AccessKeyID")
//AccessKeySecret = beego.AppConfig.String("AccessKeySecret")
)
const (
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
comm_time "gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
"openapi/pkg/constant"
"openapi/pkg/infrastructure/utils"
"path"
"path/filepath"
... ... @@ -17,13 +18,13 @@ import (
//客户端
func DefaultVodClient() (client *vod.Client, err error) {
return InitVodClient(AccessKeyID, AccessKeySecret)
return InitVodClient(constant.AccessKeyID, constant.AccessKeySecret)
}
//初始化客户端
func InitVodClient(accessKeyId string, accessKeySecret string) (client *vod.Client, err error) {
// 点播服务接入区域
regionId := RegionID
regionId := constant.RegionID
// 创建授权对象
credential := &credentials.AccessKeyCredential{
accessKeyId,
... ... @@ -73,7 +74,7 @@ func RefreshUploadVideo(client *vod.Client, r *RefreshUploadVideoRequest) (respo
if up, e := ParseUploadAddress(rsp.UploadAddress); e != nil {
log.Error(e)
} else {
response.FileURL = up.GetFileUrl(beego.AppConfig.String("cname"))
response.FileURL = up.GetFileUrl(constant.CName)
}
return
}
... ...
package log
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"openapi/pkg/constant"
"openapi/pkg/infrastructure/utils"
)
func init() {
log.InitLog(config.Logger{
Filename: constant.LogFilePath,
Level: fmt.Sprintf("%v", utils.ResolveLogLevel(constant.LogLevel)),
})
}
... ...
... ... @@ -2,6 +2,7 @@ package routers
import (
"github.com/astaxie/beego"
"openapi/pkg/constant"
"openapi/pkg/port/beego/controllers"
"openapi/pkg/port/beego/controllers/v1"
)
... ... @@ -13,6 +14,6 @@ func init() {
beego.NSNamespace("vod", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.VodController{})),
beego.NSNamespace("push", beego.NSBefore(controllers.AllowOption), beego.NSInclude(&v1.PushController{})),
)
beego.SetStaticPath("/log", beego.AppConfig.String("aliyun_logs_access"))
beego.SetStaticPath("/log", constant.LogFilePath)
beego.AddNamespace(nsV1)
}
... ...
package push
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("消息推送测试", func() {
ginkgo.Describe("消息推送测试", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"mmmType": 1,
"deviceToken": "",
"clientId": "b5fff5f6b0af551da5f381fa47991828",
"appkey": "5AjJeDOSOZ5ojQpXJFjhg9",
"secret": "9VnM8MaA6n84Y5VnOIaSvA",
"appId": "TkpBI4awmg9fBUx3NWKXS6",
"title": " hello",
"content": " hello content",
"ext": map[string]interface{}{"transData": "trans-content"},
}
httpExpect.POST("/v1/push/pushInfo").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package push
import (
"github.com/astaxie/beego"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"net/http"
"net/http/httptest"
_ "openapi/pkg/port/beego"
"testing"
)
func TestPush(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Beego Port Config Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = ginkgo.BeforeSuite(func() {
handler = beego.BeeApp.Handlers
beego.BConfig.CopyRequestBody = true
server = httptest.NewServer(handler)
})
var _ = ginkgo.AfterSuite(func() {
server.Close()
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("创建图片上传凭证(单图片)", func() {
ginkgo.Describe("创建图片上传凭证(单图片)", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"fileName": "test.jpg",
}
httpExpect.POST("/v1/vod/createUploadImage").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("创建图片上传凭证(多图片)", func() {
ginkgo.Describe("创建图片上传凭证(多图片)", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"items": []struct {
FileName string `json:"fileName"`
}{{FileName: "test.jpg"}},
}
httpExpect.POST("/v1/vod/createUploadImages").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("创建视频上传凭证(单视频)", func() {
ginkgo.Describe("创建视频上传凭证(单视频)", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"fileName": "test.mp4",
}
httpExpect.POST("/v1/vod/createUploadVideos").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("创建视频上传凭证(多视频)", func() {
ginkgo.Describe("创建视频上传凭证(多视频)", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"items": []struct {
FileName string `json:"fileName"`
}{{FileName: "test.mp4"}},
}
httpExpect.POST("/v1/vod/createUploadVideos").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("获取播放信息测试", func() {
ginkgo.Describe("获取播放信息测试", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"videoId": "7be8e50dd65e45d285908bf28c8e94b2",
}
httpExpect.POST("/v1/vod/getPlayInfo").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("获取播放凭证测试", func() {
ginkgo.Describe("获取播放凭证测试", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"videoId": "7be8e50dd65e45d285908bf28c8e94b2",
}
httpExpect.POST("/v1/vod/getVideoPlayAuth").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/gavv/httpexpect"
"github.com/onsi/ginkgo"
"net/http"
)
var _ = ginkgo.Describe("刷新视频上次凭证", func() {
ginkgo.Describe("刷新视频上次凭证", func() {
ginkgo.Context("", func() {
ginkgo.It("", func() {
httpExpect := httpexpect.New(ginkgo.GinkgoT(), server.URL)
body := map[string]interface{}{
"videoId": "1023bc472c69499dbe332afa785ee610",
}
httpExpect.POST("/v1/vod/refreshUploadVideo").
WithJSON(body).
WithHeader("x-mmm-appproject", "opportunity").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "成功")
})
})
})
})
... ...
package vod
import (
"github.com/astaxie/beego"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"net/http"
"net/http/httptest"
_ "openapi/pkg/port/beego"
"testing"
)
func TestPush(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Beego Port Config Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = ginkgo.BeforeSuite(func() {
handler = beego.BeeApp.Handlers
beego.BConfig.CopyRequestBody = true
server = httptest.NewServer(handler)
})
var _ = ginkgo.AfterSuite(func() {
server.Close()
})
... ...