Ver Fonte

add ut for livechannel & conn

hangzws há 7 anos atrás
pai
commit
aefbb2e508
3 ficheiros alterados com 31 adições e 0 exclusões
  1. 15 0
      oss/conn_test.go
  2. 4 0
      oss/livechannel.go
  3. 12 0
      oss/livechannel_test.go

+ 15 - 0
oss/conn_test.go

@@ -149,3 +149,18 @@ func (s *OssConnSuite) TestSignRtmpURL(c *C) {
 	hasPrefix = strings.HasPrefix(signedRtmpURL, playURL)
 	hasPrefix = strings.HasPrefix(signedRtmpURL, playURL)
 	c.Assert(hasPrefix, Equals, true)
 	c.Assert(hasPrefix, Equals, true)
 }
 }
+
+func (s *OssConnSuite) TestGetRtmpSignedStr(c *C) {
+	cfg := getDefaultOssConfig()
+	um := urlMaker{}
+	um.Init(endpoint, false, false)
+	conn := Conn{cfg, &um, nil}
+
+	//Anonymous
+	channelName := "test-get-rtmp-signed-str"
+	playlistName := "playlist.m3u8"
+	expiration := time.Now().Unix() + 3600
+	params := map[string]interface{}{}
+	signedStr := conn.getRtmpSignedStr(bucketName, channelName, playlistName, expiration, params)
+	c.Assert(signedStr, Equals, "")
+}

+ 4 - 0
oss/livechannel.go

@@ -199,6 +199,10 @@ func (bucket Bucket) DeleteLiveChannel(channelName string) error {
 	params := map[string]interface{}{}
 	params := map[string]interface{}{}
 	params["live"] = nil
 	params["live"] = nil
 
 
+	if channelName == "" {
+		return fmt.Errorf("invalid argument: channel name is empty")
+	}
+
 	resp, err := bucket.do("DELETE", channelName, params, nil, nil, nil)
 	resp, err := bucket.do("DELETE", channelName, params, nil, nil, nil)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 12 - 0
oss/livechannel_test.go

@@ -125,6 +125,14 @@ func (s *OssBucketLiveChannelSuite) TestDeleteLiveChannel(c *C) {
 	err = s.bucket.DeleteLiveChannel(channelName)
 	err = s.bucket.DeleteLiveChannel(channelName)
 	c.Assert(err, IsNil)
 	c.Assert(err, IsNil)
 
 
+	emptyChannelName := ""
+	err = s.bucket.DeleteLiveChannel(emptyChannelName)
+	c.Assert(err, NotNil)
+
+	longChannelName := randStr(65)
+	err = s.bucket.DeleteLiveChannel(longChannelName)
+	c.Assert(err, NotNil)
+
 	config, err = s.bucket.GetLiveChannelInfo(channelName)
 	config, err = s.bucket.GetLiveChannelInfo(channelName)
 	c.Assert(err, NotNil)
 	c.Assert(err, NotNil)
 }
 }
@@ -313,6 +321,10 @@ func (s *OssBucketLiveChannelSuite) TestListLiveChannel(c *C) {
 	c.Assert(err, IsNil)
 	c.Assert(err, IsNil)
 	ok = compareListResult(result, "", "", "", maxKeys, false, 200)
 	ok = compareListResult(result, "", "", "", maxKeys, false, 200)
 
 
+	invalidMaxKeys := -1
+	result, err = s.bucket.ListLiveChannel(MaxKeys(invalidMaxKeys))
+	c.Assert(err, NotNil)
+
 	for i := 0; i < 200; i++ {
 	for i := 0; i < 200; i++ {
 		channelName := fmt.Sprintf("%s-%03d", prefix, i)
 		channelName := fmt.Sprintf("%s-%03d", prefix, i)
 		err := s.bucket.DeleteLiveChannel(channelName)
 		err := s.bucket.DeleteLiveChannel(channelName)