Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions compiler/native/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,121 @@ func TestNative_Compile_Pipeline_Type(t *testing.T) {
}
}

func TestNative_Compile_NameCollisionsReserved(t *testing.T) {
// setup types
name := "foo"
author := "author"
number := int64(1)

tests := []struct {
name string
yamlFile string
wantErr bool
}{
// clone
{
name: "stages pipeline: stage name is clone, step name is clone",
yamlFile: "testdata/stages_clone_stage_clone_step.yml",
wantErr: true,
},
{
name: "stages pipeline: stage name is clonez, step name is clone",
yamlFile: "testdata/stages_clonez_stage_clone_step.yml",
wantErr: false,
},
{
name: "stages pipeline: stage name is clonez, step name is clone without commands",
yamlFile: "testdata/stages_clonez_stage_clone_step_no_commands.yml",
wantErr: true,
},
{
name: "stages pipeline: clone false, stage name is clone, step name is clone",
yamlFile: "testdata/stages_clone_false_clone_stage_clone_step.yml",
wantErr: false,
},
{
name: "stages pipeline: clone false, stage name is clone, step name is clone without commands",
yamlFile: "testdata/stages_clone_false_clone_stage_clone_step_no_commands.yml",
wantErr: true,
},
{
name: "steps pipeline: step named clone",
yamlFile: "testdata/steps_clone_step.yml",
wantErr: true,
},
{
name: "steps pipeline: clone false, step named clone",
yamlFile: "testdata/steps_clone_false_clone_step.yml",
wantErr: false,
},
{
name: "steps pipeline: clone false, step named clone without commands",
yamlFile: "testdata/steps_clone_false_clone_step_no_commands.yml",
wantErr: true,
},
// init
{
name: "stages pipeline: stage name is init, step name is init",
yamlFile: "testdata/stages_init_stage_init_step.yml",
wantErr: true,
},
{
name: "stages pipeline: stage name is initz, step name is init",
yamlFile: "testdata/stages_initz_stage_init_step.yml",
wantErr: false,
},
{
name: "stages pipeline: stage name is initz, step name is init without commands",
yamlFile: "testdata/stages_initz_stage_init_step_no_commands.yml",
wantErr: true,
},
{
name: "steps pipeline: step named init",
yamlFile: "testdata/steps_init_step.yml",
wantErr: true,
},
{
name: "steps pipeline: steps named init and clone",
yamlFile: "testdata/steps_init_clone.yml",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

// run test
yaml, err := os.ReadFile(tt.yamlFile)
if err != nil {
t.Errorf("Reading yaml file return err: %v", err)
}

compiler, err := FromCLICommand(context.Background(), testCommand(t, "http://foo.example.com"))
if err != nil {
t.Errorf("Creating compiler returned err: %v", err)
}

compiler.repo = &api.Repo{Name: &author}
compiler.build = &api.Build{Author: &name, Number: &number}

got, _, err := compiler.Compile(context.Background(), yaml)
if (err != nil) != tt.wantErr {
t.Errorf("Compile() error = %v, wantErr %v", err, tt.wantErr)
return
}

if tt.wantErr && got != nil {
t.Errorf("Compile() returned %v, want nil when expecting error", got)
}

if !tt.wantErr && got == nil {
t.Errorf("Compile() returned nil, want non-nil when not expecting error")
}
})
}
}

func TestNative_Compile_StageNameCollision(t *testing.T) {
// setup types
name := "foo"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "1"

metadata:
clone: false

stages:
clone:
steps:
- name: clone
image: alpine:latest
commands:
- echo 'hello'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "1"

metadata:
clone: false

stages:
clone:
steps:
- name: clone
image: alpine:latest
9 changes: 9 additions & 0 deletions compiler/native/testdata/stages_clone_stage_clone_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "1"

stages:
clone:
steps:
- name: clone
image: alpine:latest
commands:
- echo 'hello'
9 changes: 9 additions & 0 deletions compiler/native/testdata/stages_clonez_stage_clone_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "1"

stages:
clonez:
steps:
- name: clone
image: alpine:latest
commands:
- echo 'hello'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "1"

stages:
clonez:
steps:
- name: clone
image: alpine:latest
9 changes: 9 additions & 0 deletions compiler/native/testdata/stages_init_stage_init_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "1"

stages:
init:
steps:
- name: init
image: alpine:latest
commands:
- echo 'hello'
9 changes: 9 additions & 0 deletions compiler/native/testdata/stages_initz_stage_init_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "1"

stages:
initz:
steps:
- name: init
image: alpine:latest
commands:
- echo 'hello'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "1"

stages:
initz:
steps:
- name: init
image: alpine:latest
10 changes: 10 additions & 0 deletions compiler/native/testdata/steps_clone_false_clone_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "1"

metadata:
clone: false

steps:
- name: clone
image: alpine:latest
commands:
- echo 'hello'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "1"

metadata:
clone: false

steps:
- name: clone
image: alpine:latest
7 changes: 7 additions & 0 deletions compiler/native/testdata/steps_clone_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "1"

steps:
- name: clone
image: alpine:latest
commands:
- echo 'hello'
12 changes: 12 additions & 0 deletions compiler/native/testdata/steps_init_clone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "1"

steps:
- name: init
image: alpine:latest
commands:
- echo 'hello'

- name: clone
image: alpine:latest
commands:
- echo 'hello'
7 changes: 7 additions & 0 deletions compiler/native/testdata/steps_init_step.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "1"

steps:
- name: init
image: alpine:latest
commands:
- echo 'hello'
Loading
Loading