-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from Zhang21/feat-dingdingSign
feat: 钉钉加签
- Loading branch information
Showing
5 changed files
with
146 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package controllers | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDDMesage(t *testing.T) { | ||
// A sample dingding message json payload | ||
payload := ` | ||
{ | ||
"msgtype": "markdown", | ||
"markdown": { | ||
"title": "AlertPrometheus告警测试", | ||
"text": "**测试告警信息**\n" | ||
}, | ||
"at": { | ||
"atMobiles": ["139xxxxxxxx", "159xxxxxxxx"], | ||
"isAtAll": false | ||
} | ||
}` | ||
message := DDMessage{} | ||
err := json.Unmarshal([]byte(payload), &message) | ||
assert.Nil(t, err) | ||
} | ||
|
||
func TestDingdingSign(t *testing.T) { | ||
var want, result string | ||
|
||
// url without parm secret | ||
withoutURL := "https://oapi.dingtalk.com/robot/send?access_token=XXX" | ||
want = withoutURL | ||
result = dingdingSign(withoutURL) | ||
assert.Equal(t, want, result) | ||
|
||
// url with parm secret | ||
withURL := "https://oapi.dingtalk.com/robot/send?access_token=XXX&secret=mysecret" | ||
result = dingdingSign(withURL) | ||
t.Logf("一个示例的加签的地址:%s", result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters