1.4.5.2
This commit is contained in:
50
EdgeAPI/internal/senders/mediasenders/media_script_test.go
Normal file
50
EdgeAPI/internal/senders/mediasenders/media_script_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
//go:build plus
|
||||
|
||||
package mediasenders
|
||||
|
||||
import (
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/files"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScriptMedia_Send(t *testing.T) {
|
||||
script := `#!/usr/bin/env bash
|
||||
|
||||
echo "subject:${MessageSubject}"
|
||||
echo "body:${MessageBody}"
|
||||
`
|
||||
|
||||
tmp := files.NewFile(Tea.Root + "/web/tmp/media_test.sh")
|
||||
err := tmp.WriteString(script)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = tmp.Chmod(0777)
|
||||
defer func() {
|
||||
_ = tmp.Delete()
|
||||
}()
|
||||
|
||||
media := NewScriptMedia()
|
||||
media.Path = tmp.Path()
|
||||
_, err = media.Send("zhangsan", "this is subject", "this is body", teaconst.GlobalProductName, timeutil.Format("Y-m-d H:i:s"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScriptMedia_Send2(t *testing.T) {
|
||||
media := NewScriptMedia()
|
||||
media.ScriptType = "code"
|
||||
media.Script = `#!/usr/bin/env bash
|
||||
|
||||
echo "subject:${MessageSubject}"
|
||||
echo "body:${MessageBody}"
|
||||
`
|
||||
_, err := media.Send("zhangsan", "this is subject", "this is body", teaconst.GlobalProductName, timeutil.Format("Y-m-d H:i:s"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user