-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new fields to jobfile, better validation, unit tests.
- Loading branch information
Showing
25 changed files
with
417 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: CI | ||
on: [push] | ||
jobs: | ||
tests: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21.x' | ||
- name: Client tests | ||
run: make test |
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,55 @@ | ||
package job | ||
|
||
import ( | ||
"github.com/samber/lo" | ||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
"path" | ||
"testing" | ||
) | ||
|
||
var flagtests = []struct { | ||
file string | ||
expected string | ||
}{ | ||
{"tests/jobfile/valid_minimalist.yaml", ""}, | ||
{"tests/jobfile/valid_full_featured.yaml", ""}, | ||
|
||
{"tests/jobfile/invalid_missing_name.yaml", "name is required"}, | ||
{"tests/jobfile/invalid_missing_image_dockerfile.yaml", "image.dockerfile is required"}, | ||
{"tests/jobfile/invalid_missing_image_context.yaml", "image.context is required"}, | ||
{"tests/jobfile/invalid_missing_services_image.yaml", "services[mysql].image is required"}, | ||
{"tests/jobfile/invalid_missing_services_health_cmd.yaml", "services[mysql].health.cmd is required"}, | ||
|
||
{"tests/jobfile/invalid_version.yaml", "unsupported version '42'"}, | ||
{"tests/jobfile/invalid_image_dockerfile.yaml", "image.dockerfile must be an existing file on disk"}, | ||
{"tests/jobfile/invalid_image_context.yaml", "image.context must be an existing folder on disk"}, | ||
{"tests/jobfile/invalid_services_map.yaml", "yaml: unmarshal errors:\n line 7: cannot unmarshal !!seq into map[string]job.JobfileService"}, | ||
{"tests/jobfile/invalid_services_keys.yaml", "services names must be valid identifiers"}, | ||
{"tests/jobfile/invalid_services_env_keys.yaml", "services[mysql].env[0/2] must be a valid environment variable identifier"}, | ||
} | ||
|
||
func TestJobValidate(t *testing.T) { | ||
var buf []byte | ||
var err error | ||
|
||
for _, tt := range flagtests { | ||
t.Run(tt.file, func(t *testing.T) { | ||
buf = lo.Must(os.ReadFile(tt.file)) | ||
|
||
var jobfile Jobfile | ||
if err = yaml.Unmarshal(buf, &jobfile); err != nil { | ||
assert.Equal(t, tt.expected, err.Error()) | ||
return | ||
} | ||
jobfile.Path = path.Dir(tt.file) | ||
if err = jobfile.Validate(); err != nil { | ||
assert.Equal(t, tt.expected, err.Error()) | ||
return | ||
} | ||
|
||
assert.Equal(t, "", tt.expected) | ||
}) | ||
} | ||
} |
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
Empty file.
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,5 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "./toto" |
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,5 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "toto.dockerfile" | ||
context: "." |
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,4 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" |
4 changes: 4 additions & 0 deletions
4
client/job/tests/jobfile/invalid_missing_image_dockerfile.yaml
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,4 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
context: "." |
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,4 @@ | ||
version: "1" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." |
10 changes: 10 additions & 0 deletions
10
client/job/tests/jobfile/invalid_missing_services_health_cmd.yaml
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,10 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
mysql: | ||
image: mysql | ||
health: | ||
retries: 1 |
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,9 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
mysql: | ||
env: | ||
TOTO: toto |
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,10 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
mysql: | ||
image: mysql | ||
env: | ||
0/2: foo |
10 changes: 10 additions & 0 deletions
10
client/job/tests/jobfile/invalid_services_health_timeout.yaml
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,10 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
mysql: | ||
image: mysql | ||
health: | ||
timeout: |
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,8 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
0/2: | ||
image: mysql |
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,8 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
- mysql | ||
- redis |
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,5 @@ | ||
version: "42" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." |
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,24 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." | ||
services: | ||
redis: | ||
image: "redis:7.0.5-alpine" | ||
health: | ||
cmd: ["redis-cli", "ping"] | ||
timeout: "5s" | ||
wait: "1s" | ||
retries: 10 | ||
mysql: | ||
image: "mysql:8.0.31" | ||
env: | ||
MYSQL_ROOT_PASSWORD: "root" | ||
health: | ||
cmd: ["mysqladmin", "-u", "root", "-proot", "-h", "127.0.0.1", "ping"] | ||
timeout: "10s" | ||
interval: "2s" | ||
retries: 20 | ||
tasks: | | ||
sloth instance --app tipee list -o json | jq -r '.[] | select(.features.tests) | .id' | tail -n 1 |
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,5 @@ | ||
version: "1" | ||
name: "test" | ||
image: | ||
dockerfile: "a.dockerfile" | ||
context: "." |
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
Oops, something went wrong.