-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinstance_test.go
48 lines (40 loc) · 1.04 KB
/
instance_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gomaxcompute
import (
"encoding/base64"
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDecodeInstanceResult(t *testing.T) {
a := assert.New(t)
s := `<?xml version="1.0"?>
<Instance>
<Tasks>
<Task Type="SQL">
<Name>AnonymousSQLTask</Name>
<Result %s %s><![CDATA[%s]]></Result>
</Task>
</Tasks>
</Instance>`
{
data := "abc123!?$*&()'-=@~"
sEnc := base64.StdEncoding.EncodeToString([]byte(data))
content, err := decodeInstanceResult([]byte(fmt.Sprintf(s, "Transform=\"Base64\"", "Format=\"csv\"", sEnc)))
a.NoError(err)
a.Equal(data, content)
}
{
data := "1,2,3"
content, err := decodeInstanceResult([]byte(fmt.Sprintf(s, "", "Format=\"csv\"", data)))
a.NoError(err)
a.Equal(data, content)
}
{
_, err := decodeInstanceResult([]byte(fmt.Sprintf(s, "", "Format=\"text\"", "1,2,3")))
a.Error(err) // unsupported format text
}
{
_, err := decodeInstanceResult([]byte(fmt.Sprintf(s, "Transform=\"zip\"", "Format=\"csv\"", "1,2,3")))
a.Error(err) // unsupported transform zip
}
}