aboutsummaryrefslogtreecommitdiff
path: root/statement_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-20 23:14:03 +0700
committerShulhan <ms@kilabit.info>2023-10-20 23:45:00 +0700
commitcda5c7c31a84b01e2231bed579d7f4bb6212a272 (patch)
tree996ff00e15bcc7c683c223cbff020cd40d78290b /statement_test.go
parent6c99e66401ce06889b0d8fd46a0e073402b359f0 (diff)
downloadawwan-cda5c7c31a84b01e2231bed579d7f4bb6212a272.tar.xz
all: add parser for magic command "#get" or "#put" with owner and mode
The owner and mode is defined after the magic command with the following syntax, [ USER [ ":" GROUP ]] ["+" MODE] The USER and/or GROUP is optional, its accept the value as in "chown". The MODE also optional, its value must be an octal.
Diffstat (limited to 'statement_test.go')
-rw-r--r--statement_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/statement_test.go b/statement_test.go
index 521ad40..6da8dfe 100644
--- a/statement_test.go
+++ b/statement_test.go
@@ -42,6 +42,41 @@ func TestParseStatement(t *testing.T) {
raw: []byte(` a\ b c`),
},
}, {
+ raw: []byte(`#get:user:group `),
+ expError: `ParseStatement: "#get:": missing arguments`,
+ }, {
+ raw: []byte(`#get:user:group src`),
+ expError: `ParseStatement: "#get:": missing destination file`,
+ }, {
+ raw: []byte(`#get:user:group src dst`),
+ exp: &Statement{
+ kind: statementKindGet,
+ owner: `user:group`,
+ args: []string{`src`, `dst`},
+ raw: []byte(`src dst`),
+ },
+ }, {
+ raw: []byte(`#get:+800 src dst`),
+ expError: `ParseStatement: "#get:": strconv.ParseUint: parsing "800": invalid syntax`,
+ }, {
+ raw: []byte(`#get:user:group+561 src dst`),
+ exp: &Statement{
+ kind: statementKindGet,
+ owner: `user:group`,
+ mode: 369,
+ args: []string{`src`, `dst`},
+ raw: []byte(`src dst`),
+ },
+ }, {
+ raw: []byte(`#get:user:group+0561 src dst`),
+ exp: &Statement{
+ kind: statementKindGet,
+ owner: `user:group`,
+ mode: 0561,
+ args: []string{`src`, `dst`},
+ raw: []byte(`src dst`),
+ },
+ }, {
raw: []byte(`#get! `),
expError: `ParseStatement: "#get!": missing arguments`,
}, {
@@ -111,6 +146,8 @@ func TestParseStatement(t *testing.T) {
)
for _, c = range cases {
+ t.Logf(`ParseStatement: %s`, c.raw)
+
got, err = ParseStatement(c.raw)
if err != nil {
test.Assert(t, `error`, c.expError, err.Error())