|
| 1 | +package ci_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "sync" |
| 5 | + "testing" |
| 6 | + "text/template" |
| 7 | + |
| 8 | + "github.com/commitdev/commit0/internal/config" |
| 9 | + "github.com/commitdev/commit0/internal/generate/ci" |
| 10 | + "github.com/commitdev/commit0/internal/templator" |
| 11 | +) |
| 12 | + |
| 13 | +func TestGenerateJenkins(t *testing.T) { |
| 14 | + testConf := &config.Commit0Config{ |
| 15 | + Language: "go", |
| 16 | + CI: config.CI{ |
| 17 | + System: "jenkins", |
| 18 | + }, |
| 19 | + } |
| 20 | + testTemp := &templator.CITemplator{ |
| 21 | + Jenkins: &template.Template{}, |
| 22 | + CircleCI: &template.Template{}, |
| 23 | + TravisCI: &template.Template{}, |
| 24 | + } |
| 25 | + var wg sync.WaitGroup |
| 26 | + err := ci.Generate(testTemp, testConf, "/dev/null", &wg) |
| 27 | + if err != nil { |
| 28 | + t.Errorf("Error when executing test. %s", err) |
| 29 | + } |
| 30 | + |
| 31 | + expectedBuildImage := "golang/golang:1.12" |
| 32 | + actualBuildImage := testConf.CI.BuildImage |
| 33 | + if actualBuildImage != expectedBuildImage { |
| 34 | + t.Errorf("want: %s, got: %s", expectedBuildImage, actualBuildImage) |
| 35 | + } |
| 36 | + |
| 37 | + expectedBuildCommand := "make build" |
| 38 | + actualBuildCommand := testConf.CI.BuildCommand |
| 39 | + if actualBuildCommand != expectedBuildCommand { |
| 40 | + t.Errorf("want: %s, got: %s", expectedBuildCommand, actualBuildCommand) |
| 41 | + } |
| 42 | + |
| 43 | + expectedTestCommand := "make test" |
| 44 | + actualTestCommand := testConf.CI.TestCommand |
| 45 | + if actualTestCommand != expectedTestCommand { |
| 46 | + t.Errorf("want: %s, got: %s", expectedTestCommand, actualTestCommand) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestGenerateInvalidLanguage(t *testing.T) { |
| 51 | + testConf := &config.Commit0Config{ |
| 52 | + Language: "invalidLanguage", |
| 53 | + } |
| 54 | + testTemp := &templator.CITemplator{ |
| 55 | + Jenkins: &template.Template{}, |
| 56 | + CircleCI: &template.Template{}, |
| 57 | + TravisCI: &template.Template{}, |
| 58 | + } |
| 59 | + var wg sync.WaitGroup |
| 60 | + err := ci.Generate(testTemp, testConf, "/dev/null", &wg) |
| 61 | + if err == nil { |
| 62 | + t.Errorf("Error should be thrown with invalid language specified. %s", err.Error()) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func TestGenerateInvalidCISystem(t *testing.T) { |
| 67 | + testConf := &config.Commit0Config{ |
| 68 | + Language: "go", |
| 69 | + CI: config.CI{ |
| 70 | + System: "invalidCISystem", |
| 71 | + }, |
| 72 | + } |
| 73 | + testTemp := &templator.CITemplator{ |
| 74 | + Jenkins: &template.Template{}, |
| 75 | + CircleCI: &template.Template{}, |
| 76 | + TravisCI: &template.Template{}, |
| 77 | + } |
| 78 | + var wg sync.WaitGroup |
| 79 | + err := ci.Generate(testTemp, testConf, "/dev/null", &wg) |
| 80 | + if err == nil { |
| 81 | + t.Errorf("Error should be thrown with invalid ci system specified. %s", err.Error()) |
| 82 | + } |
| 83 | +} |
0 commit comments