preparation for v0.2.0 #3
@ -1,11 +1,12 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.suyono.dev/suyono/wingmate"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gitea.suyono.dev/suyono/wingmate"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -96,11 +97,11 @@ const crontabTestCase3 = `a 13 3,5,7 * * /path/to/executable
|
|||||||
*/5 13 a * * /path/to/executable
|
*/5 13 a * * /path/to/executable
|
||||||
*/5 13 3,5,7 a * /path/to/executable
|
*/5 13 3,5,7 a * /path/to/executable
|
||||||
*/5 13 3,5,7 * a /path/to/executable
|
*/5 13 3,5,7 * a /path/to/executable
|
||||||
*/x 13 3,5,7 * a /path/to/executable
|
*/x 13 3,5,7 * * /path/to/executable
|
||||||
76 13 3,5,7 * a /path/to/executable
|
76 13 3,5,7 * * /path/to/executable
|
||||||
*/75 13 3,5,7 * a /path/to/executable
|
*/75 13 3,5,7 * * /path/to/executable
|
||||||
*/5 13 3,x,7 * a /path/to/executable
|
*/5 13 3,x,7 * * /path/to/executable
|
||||||
*/5 13 3,5,67 * a /path/to/executable
|
*/5 13 3,5,67 * * /path/to/executable
|
||||||
*/5 13 * * /path/to/executable
|
*/5 13 * * /path/to/executable
|
||||||
*/5 13 3,5,7 * * /path/to/executable`
|
*/5 13 3,5,7 * * /path/to/executable`
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -24,7 +25,31 @@ func TestYaml(t *testing.T) {
|
|||||||
config: yamlTestCase0,
|
config: yamlTestCase0,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "service only",
|
||||||
|
config: yamlTestCase1,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "cron only",
|
||||||
|
config: yamlTestCase2,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid content - service",
|
||||||
|
config: yamlTestCase3,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, tc := range yamlBlobs {
|
||||||
|
tests = append(tests, testEntry{
|
||||||
|
name: fmt.Sprintf("negative - %d", i),
|
||||||
|
config: tc,
|
||||||
|
wantErr: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
setup(t)
|
setup(t)
|
||||||
@ -77,3 +102,157 @@ cron:
|
|||||||
user: "1001"
|
user: "1001"
|
||||||
group: "978"
|
group: "978"
|
||||||
schedule: "*/5 * * * 2,3"`
|
schedule: "*/5 * * * 2,3"`
|
||||||
|
|
||||||
|
const yamlTestCase1 = `version: "1"
|
||||||
|
service:
|
||||||
|
one:
|
||||||
|
command: ["command", "arg0", "arg1"]
|
||||||
|
environ: ["ENV1=value1", "ENV2=valueX"]
|
||||||
|
user: "user1"
|
||||||
|
group: "999"
|
||||||
|
working_dir: "/path/to/working"`
|
||||||
|
|
||||||
|
const yamlTestCase2 = `version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 * * * 2,3"`
|
||||||
|
|
||||||
|
const yamlTestCase3 = `version: "1"
|
||||||
|
service:
|
||||||
|
one:
|
||||||
|
command: 12345
|
||||||
|
environ: ["ENV1=value1", "ENV2=valueX"]
|
||||||
|
user: "user1"
|
||||||
|
group: "999"
|
||||||
|
working_dir: "/path/to/working"`
|
||||||
|
|
||||||
|
var yamlBlobs = []string{
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "a 13 3,5,7 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 a 3,5,7 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 13 a * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 13 3,5,7 a *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 13 3,5,7 * a"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/x 13 3,5,7 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "76 13 3,5,7 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/75 13 3,5,7 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 13 3,x,7 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 13 3,5,67 * *"`,
|
||||||
|
`version: "1"
|
||||||
|
cron:
|
||||||
|
cron-one:
|
||||||
|
command:
|
||||||
|
- command-cron
|
||||||
|
- arg0
|
||||||
|
- arg1
|
||||||
|
environ: ["ENV1=v1", "ENV2=var2"]
|
||||||
|
user: "1001"
|
||||||
|
group: "978"
|
||||||
|
schedule: "*/5 13 * *"`,
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user