Skip to content

Commit

Permalink
[#82] Add first test
Browse files Browse the repository at this point in the history
  • Loading branch information
juampynr committed Jul 6, 2022
1 parent 6447573 commit 60d197c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module drupal9ci

go 1.18

require github.com/stretchr/testify v1.7.1

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand All @@ -12,6 +15,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -142,6 +143,7 @@ github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand All @@ -163,6 +165,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI=
github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
Expand Down
32 changes: 18 additions & 14 deletions scripts/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,24 @@ func MapCIProviderToScript(ciProvider *string, setupScripts *SetupScripts) (*str
var setupScript *string
var err error

switch *ciProvider {
case Bitbucket:
setupScript = &setupScripts.BitBucket
case CircleCI:
setupScript = &setupScripts.CircleCI
case GithubActions:
setupScript = &setupScripts.GitHubActions
case GitLabCI:
setupScript = &setupScripts.GitLabCI
case TravisCI:
setupScript = &setupScripts.TravisCI
default:
err = fmt.Errorf("Unknown CI provider")
if ciProvider == nil {
err = fmt.Errorf("Missing CI provider")
} else {
switch *ciProvider {
case Bitbucket:
setupScript = &setupScripts.BitBucket
case CircleCI:
setupScript = &setupScripts.CircleCI
case GithubActions:
setupScript = &setupScripts.GitHubActions
case GitLabCI:
setupScript = &setupScripts.GitLabCI
case TravisCI:
setupScript = &setupScripts.TravisCI
default:
err = fmt.Errorf("Unknown CI provider")
}
}

return setupScript, err
}
34 changes: 34 additions & 0 deletions scripts/scripts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package scripts

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestMapCIProviderToScript(t *testing.T) {
type testCase struct {
name string
ciProvider func() *string
setupScripts *SetupScripts
assertions func(t *testing.T, tt testCase)
}
tests := []testCase{
{
name: "wrong provider",
ciProvider: func() *string {
return nil
},
setupScripts: LoadSetupScripts(),
assertions: func(t *testing.T, tt testCase) {
ciProvider, err := MapCIProviderToScript(tt.ciProvider(), tt.setupScripts)
assert.Nil(t, ciProvider)
assert.Error(t, err)
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.assertions(t, tt)
})
}
}

0 comments on commit 60d197c

Please sign in to comment.