Skip to content

Commit

Permalink
Merge branch 'master' into add-silence-no-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
GenPage authored Apr 16, 2021
2 parents ac3c62d + 3bb6f21 commit 23a43b6
Show file tree
Hide file tree
Showing 126 changed files with 1,766 additions and 735 deletions.
12 changes: 10 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ jobs:
- run: make test-coverage
- run:
name: post coverage to codecov.io
command: bash <(curl -s https://codecov.io/bash)
command: |
curl -s https://codecov.io/bash > codecov
VERSION=$(grep 'VERSION=\".*\"' codecov | cut -d'"' -f2);
for i in 1 256 512
do
diff <(shasum -a $i codecov) <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/$VERSION/SHA${i}SUM)
done
chmod +x codecov
./codecov
- run: make check-fmt
- run: make check-lint
e2e:
Expand All @@ -19,7 +27,7 @@ jobs:
# We do this instead of setting --default-tf-version because setting
# that flag starts the download asynchronously so we'd have a race
# condition.
TERRAFORM_VERSION: 0.14.9
TERRAFORM_VERSION: 0.14.10
steps:
- checkout
- run: make build-service
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM runatlantis/atlantis-base:v3.5
LABEL authors="Anubhav Mishra, Luke Kysow"

# install terraform binaries
ENV DEFAULT_TERRAFORM_VERSION=0.14.9
ENV DEFAULT_TERRAFORM_VERSION=0.14.10

# In the official Atlantis image we only have the latest of each Terraform version.
RUN AVAILABLE_TERRAFORM_VERSIONS="0.8.8 0.9.11 0.10.8 0.11.14 0.12.30 0.13.6 ${DEFAULT_TERRAFORM_VERSION}" && \
Expand Down
2 changes: 1 addition & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ type ServerCmd struct {
// Useful for testing to keep the logs clean.
SilenceOutput bool
AtlantisVersion string
Logger *logging.SimpleLogger
Logger logging.SimpleLogging
}

// ServerCreator creates servers.
Expand Down
69 changes: 36 additions & 33 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

homedir "github.com/mitchellh/go-homedir"
"github.com/runatlantis/atlantis/server"
"github.com/runatlantis/atlantis/server/logging"
. "github.com/runatlantis/atlantis/testing"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -112,7 +113,7 @@ func TestExecute_Defaults(t *testing.T) {
GHUserFlag: "user",
GHTokenFlag: "token",
RepoAllowlistFlag: "*",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand Down Expand Up @@ -156,7 +157,7 @@ func TestExecute_Defaults(t *testing.T) {

func TestExecute_Flags(t *testing.T) {
t.Log("Should use all flags that are set.")
c := setup(testFlags)
c := setup(testFlags, t)
err := c.Execute()
Ok(t, err)
for flag, exp := range testFlags {
Expand All @@ -174,7 +175,7 @@ func TestExecute_ConfigFile(t *testing.T) {
defer os.Remove(tmpFile) // nolint: errcheck
c := setup(map[string]interface{}{
ConfigFlag: tmpFile,
})
}, t)
err := c.Execute()
Ok(t, err)
for flag, exp := range testFlags {
Expand All @@ -189,7 +190,7 @@ func TestExecute_EnvironmentVariables(t *testing.T) {
os.Setenv(envKey, fmt.Sprintf("%v", value)) // nolint: errcheck
defer func(key string) { os.Unsetenv(key) }(envKey)
}
c := setup(nil)
c := setup(nil, t)
err := c.Execute()
Ok(t, err)
for flag, exp := range testFlags {
Expand All @@ -201,7 +202,7 @@ func TestExecute_NoConfigFlag(t *testing.T) {
t.Log("If there is no config flag specified Execute should return nil.")
c := setupWithDefaults(map[string]interface{}{
ConfigFlag: "",
})
}, t)
err := c.Execute()
Ok(t, err)
}
Expand All @@ -210,7 +211,7 @@ func TestExecute_ConfigFileExtension(t *testing.T) {
t.Log("If the config file doesn't have an extension then error.")
c := setupWithDefaults(map[string]interface{}{
ConfigFlag: "does-not-exist",
})
}, t)
err := c.Execute()
Equals(t, "invalid config: reading does-not-exist: Unsupported Config Type \"\"", err.Error())
}
Expand All @@ -219,7 +220,7 @@ func TestExecute_ConfigFileMissing(t *testing.T) {
t.Log("If the config file doesn't exist then error.")
c := setupWithDefaults(map[string]interface{}{
ConfigFlag: "does-not-exist.yaml",
})
}, t)
err := c.Execute()
Equals(t, "invalid config: reading does-not-exist.yaml: open does-not-exist.yaml: no such file or directory", err.Error())
}
Expand All @@ -230,7 +231,7 @@ func TestExecute_ConfigFileExists(t *testing.T) {
defer os.Remove(tmpFile) // nolint: errcheck
c := setupWithDefaults(map[string]interface{}{
ConfigFlag: tmpFile,
})
}, t)
err := c.Execute()
Ok(t, err)
}
Expand All @@ -241,7 +242,7 @@ func TestExecute_InvalidConfig(t *testing.T) {
defer os.Remove(tmpFile) // nolint: errcheck
c := setupWithDefaults(map[string]interface{}{
ConfigFlag: tmpFile,
})
}, t)
err := c.Execute()
Assert(t, strings.Contains(err.Error(), "unmarshal errors"), "should be an unmarshal error")
}
Expand All @@ -252,7 +253,7 @@ func TestExecute_RepoAllowlistScheme(t *testing.T) {
GHUserFlag: "user",
GHTokenFlag: "token",
RepoAllowlistFlag: "http://github.com/*",
})
}, t)
err := c.Execute()
Assert(t, err != nil, "should be an error")
Equals(t, "--repo-allowlist cannot contain ://, should be hostnames only", err.Error())
Expand Down Expand Up @@ -281,7 +282,7 @@ func TestExecute_ValidateLogLevel(t *testing.T) {
}
for _, testCase := range cases {
t.Log("Should validate log level when " + testCase.description)
c := setupWithDefaults(testCase.flags)
c := setupWithDefaults(testCase.flags, t)
err := c.Execute()
if testCase.expectError {
Assert(t, err != nil, "should be an error")
Expand All @@ -294,7 +295,7 @@ func TestExecute_ValidateLogLevel(t *testing.T) {
func TestExecute_ValidateCheckoutStrategy(t *testing.T) {
c := setupWithDefaults(map[string]interface{}{
CheckoutStrategyFlag: "invalid",
})
}, t)
err := c.Execute()
ErrEquals(t, "invalid checkout strategy: not one of branch or merge", err)
}
Expand Down Expand Up @@ -336,7 +337,7 @@ func TestExecute_ValidateSSLConfig(t *testing.T) {
}
for _, testCase := range cases {
t.Log("Should validate ssl config when " + testCase.description)
c := setupWithDefaults(testCase.flags)
c := setupWithDefaults(testCase.flags, t)
err := c.Execute()
if testCase.expectError {
Assert(t, err != nil, "should be an error")
Expand Down Expand Up @@ -512,7 +513,7 @@ func TestExecute_ValidateVCSConfig(t *testing.T) {
t.Log("Should validate vcs config when " + testCase.description)
testCase.flags[RepoAllowlistFlag] = "*"

c := setup(testCase.flags)
c := setup(testCase.flags, t)
err := c.Execute()
if testCase.expectError {
Assert(t, err != nil, "should be an error")
Expand All @@ -530,7 +531,7 @@ func TestExecute_ExpandHomeInDataDir(t *testing.T) {
GHTokenFlag: "token",
RepoAllowlistFlag: "*",
DataDirFlag: "~/this/is/a/path",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand All @@ -543,7 +544,7 @@ func TestExecute_RelativeDataDir(t *testing.T) {
t.Log("Should convert relative dir to absolute.")
c := setupWithDefaults(map[string]interface{}{
DataDirFlag: "../",
})
}, t)

// Figure out what ../ should be as an absolute path.
expectedAbsolutePath, err := filepath.Abs("../")
Expand All @@ -560,7 +561,7 @@ func TestExecute_GithubUser(t *testing.T) {
GHUserFlag: "@user",
GHTokenFlag: "token",
RepoAllowlistFlag: "*",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand All @@ -573,7 +574,7 @@ func TestExecute_GithubApp(t *testing.T) {
GHAppKeyFileFlag: "key.pem",
GHAppIDFlag: "1",
RepoAllowlistFlag: "*",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand All @@ -586,7 +587,7 @@ func TestExecute_GitlabUser(t *testing.T) {
GitlabUserFlag: "@user",
GitlabTokenFlag: "token",
RepoAllowlistFlag: "*",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand All @@ -599,7 +600,7 @@ func TestExecute_BitbucketUser(t *testing.T) {
BitbucketUserFlag: "@user",
BitbucketTokenFlag: "token",
RepoAllowlistFlag: "*",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand All @@ -612,7 +613,7 @@ func TestExecute_ADUser(t *testing.T) {
ADUserFlag: "@user",
ADTokenFlag: "token",
RepoAllowlistFlag: "*",
})
}, t)
err := c.Execute()
Ok(t, err)

Expand All @@ -626,7 +627,7 @@ func TestExecute_BitbucketCloudWithWebhookSecret(t *testing.T) {
BitbucketTokenFlag: "token",
RepoAllowlistFlag: "*",
BitbucketWebhookSecretFlag: "my secret",
})
}, t)
err := c.Execute()
ErrEquals(t, "--bitbucket-webhook-secret cannot be specified for Bitbucket Cloud because it is not supported by Bitbucket", err)
}
Expand All @@ -638,15 +639,15 @@ func TestExecute_BitbucketServerBaseURLScheme(t *testing.T) {
BitbucketTokenFlag: "token",
RepoAllowlistFlag: "*",
BitbucketBaseURLFlag: "mydomain.com",
})
}, t)
ErrEquals(t, "--bitbucket-base-url must have http:// or https://, got \"mydomain.com\"", c.Execute())

c = setup(map[string]interface{}{
BitbucketUserFlag: "user",
BitbucketTokenFlag: "token",
RepoAllowlistFlag: "*",
BitbucketBaseURLFlag: "://mydomain.com",
})
}, t)
ErrEquals(t, "error parsing --bitbucket-webhook-secret flag value \"://mydomain.com\": parse \"://mydomain.com\": missing protocol scheme", c.Execute())
}

Expand All @@ -657,7 +658,7 @@ func TestExecute_BitbucketServerBaseURLPort(t *testing.T) {
BitbucketTokenFlag: "token",
RepoAllowlistFlag: "*",
BitbucketBaseURLFlag: "http://mydomain.com:7990",
})
}, t)
Ok(t, c.Execute())
Equals(t, "http://mydomain.com:7990", passedConfig.BitbucketBaseURL)
}
Expand All @@ -670,7 +671,7 @@ func TestExecute_RepoCfgFlags(t *testing.T) {
RepoAllowlistFlag: "github.com",
RepoConfigFlag: "repos.yaml",
RepoConfigJSONFlag: "{}",
})
}, t)
err := c.Execute()
ErrEquals(t, "cannot use --repo-config and --repo-config-json at the same time", err)
}
Expand All @@ -682,7 +683,7 @@ func TestExecute_TFEHostnameOnly(t *testing.T) {
GHTokenFlag: "token",
RepoAllowlistFlag: "github.com",
TFEHostnameFlag: "not-app.terraform.io",
})
}, t)
err := c.Execute()
ErrEquals(t, "if setting --tfe-hostname, must set --tfe-token", err)
}
Expand All @@ -694,7 +695,7 @@ func TestExecute_BothAllowAndWhitelist(t *testing.T) {
GHTokenFlag: "token",
RepoAllowlistFlag: "github.com",
RepoWhitelistFlag: "github.com",
})
}, t)
err := c.Execute()
ErrEquals(t, "both --repo-allowlist and --repo-whitelist cannot be set–use --repo-allowlist", err)
}
Expand All @@ -704,7 +705,7 @@ func TestExecute_AllowAndWhitelist(t *testing.T) {
c := setup(map[string]interface{}{
GHUserFlag: "user",
GHTokenFlag: "token",
})
}, t)
err := c.Execute()
ErrEquals(t, "--repo-allowlist must be set for security purposes", err)
}
Expand All @@ -717,7 +718,7 @@ func TestExecute_BothSilenceAllowAndWhitelistErrors(t *testing.T) {
RepoAllowlistFlag: "*",
SilenceWhitelistErrorsFlag: true,
SilenceAllowlistErrorsFlag: true,
})
}, t)
err := c.Execute()
ErrEquals(t, "both --silence-allowlist-errors and --silence-whitelist-errors cannot be set–use --silence-allowlist-errors", err)
}
Expand All @@ -730,14 +731,14 @@ func TestExecute_RepoWhitelistDeprecation(t *testing.T) {
GHTokenFlag: "token",
RepoWhitelistFlag: "*",
SilenceWhitelistErrorsFlag: true,
})
}, t)
err := c.Execute()
Ok(t, err)
Equals(t, true, passedConfig.SilenceAllowlistErrors)
Equals(t, "*", passedConfig.RepoAllowlist)
}

func setup(flags map[string]interface{}) *cobra.Command {
func setup(flags map[string]interface{}, t *testing.T) *cobra.Command {
vipr := viper.New()
for k, v := range flags {
vipr.Set(k, v)
Expand All @@ -746,11 +747,12 @@ func setup(flags map[string]interface{}) *cobra.Command {
ServerCreator: &ServerCreatorMock{},
Viper: vipr,
SilenceOutput: true,
Logger: logging.NewNoopLogger(t),
}
return c.Init()
}

func setupWithDefaults(flags map[string]interface{}) *cobra.Command {
func setupWithDefaults(flags map[string]interface{}, t *testing.T) *cobra.Command {
vipr := viper.New()
flags[GHUserFlag] = "user"
flags[GHTokenFlag] = "token"
Expand All @@ -763,6 +765,7 @@ func setupWithDefaults(flags map[string]interface{}) *cobra.Command {
ServerCreator: &ServerCreatorMock{},
Viper: vipr,
SilenceOutput: true,
Logger: logging.NewNoopLogger(t),
}
return c.Init()
}
Expand Down
Loading

0 comments on commit 23a43b6

Please sign in to comment.