-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10cf6e3
commit 953f68d
Showing
6 changed files
with
162 additions
and
32 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
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
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,47 @@ | ||
package whencli | ||
|
||
import ( | ||
"testing" | ||
|
||
gabs "github.com/Jeffail/gabs/v2" | ||
assert "github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test__ListInputs(t *testing.T) { | ||
expressions := []string{ | ||
"branch = 'master'", | ||
"change_in('lib')", | ||
"branch = ", | ||
} | ||
|
||
results, err := ListInputs(expressions) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, 3, len(results)) | ||
assert.Equal(t, []ListInputsResult{ | ||
ListInputsResult{ | ||
Expression: expressions[0], | ||
Error: "", | ||
Inputs: fromJSON(`[{"name": "branch", "type": "keyword"}]`), | ||
}, | ||
ListInputsResult{ | ||
Expression: expressions[1], | ||
Error: "", | ||
Inputs: fromJSON(`[{"name": "change_in", "params": ["lib"], "type": "fun"}]`), | ||
}, | ||
ListInputsResult{ | ||
Expression: expressions[2], | ||
Error: "Invalid or incomplete expression at the end of the line.", | ||
Inputs: fromJSON(`[]`), | ||
}, | ||
}, results) | ||
} | ||
|
||
func fromJSON(s string) *gabs.Container { | ||
res, err := gabs.ParseJSON([]byte(s)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return res | ||
} |
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,71 @@ | ||
# rubocop:disable all | ||
|
||
require_relative "../e2e" | ||
|
||
system "rm -f /tmp/output.yml" | ||
system "rm -f /tmp/logs.jsonl" | ||
|
||
pipeline = %{ | ||
version: v1.0 | ||
name: Test | ||
agent: | ||
machine: | ||
type: e1-standard-2 | ||
blocks: | ||
- name: Test | ||
skip: | ||
when: "branch = 'master' and ahahahaha and change_in('/lib')" | ||
task: | ||
jobs: | ||
- name: Hello | ||
commands: | ||
- echo "Hello World" | ||
- name: Test | ||
skip: | ||
when: "branch =" | ||
task: | ||
jobs: | ||
- name: Hello | ||
commands: | ||
- echo "Hello World" | ||
} | ||
|
||
origin = TestRepoForChangeIn.setup() | ||
|
||
origin.add_file('.semaphore/semaphore.yml', pipeline) | ||
origin.commit!("Bootstrap") | ||
|
||
origin.add_file("lib/A.txt", "hello") | ||
origin.commit!("Changes on master") | ||
|
||
origin.create_branch("dev") | ||
origin.add_file("lib/B.txt", "hello") | ||
origin.commit!("Changes in dev") | ||
|
||
repo = origin.clone_local_copy(branch: "dev") | ||
repo.run("#{spc} evaluate change-in --input .semaphore/semaphore.yml --output /tmp/output.yml --logs /tmp/logs.jsonl", fail: false) | ||
|
||
assert_eq($?.exitstatus, 1) | ||
|
||
errors = File.read('/tmp/logs.jsonl').lines.map { |l| JSON.parse(l) } | ||
assert_eq(errors.size, 2) | ||
|
||
assert_eq(errors[0], { | ||
"type" => "ErrorInvalidWhenExpression", | ||
"message" => "Invalid when expression: branch = 'master' and ahahahaha and change_in('/lib')", | ||
"location" => { | ||
"file" => ".semaphore/semaphore.yml", | ||
"path" => ["blocks", "0", "skip", "when"] | ||
} | ||
}) | ||
|
||
assert_eq(errors[1], { | ||
"type" => "ErrorInvalidWhenExpression", | ||
"message" => "Invalid when expression: branch =", | ||
"location" => { | ||
"file" => ".semaphore/semaphore.yml", | ||
"path" => ["blocks", "1", "skip", "when"] | ||
} | ||
}) |