Skip to content

Commit

Permalink
Fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jjulien committed Mar 10, 2019
1 parent 7175dd4 commit 83d09ab
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 65 deletions.
2 changes: 1 addition & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (s *ServerCmd) validate(userConfig server.UserConfig) error {
return fmt.Errorf("--%s and --%s are both required for ssl", SSLKeyFileFlag, SSLCertFileFlag)
}
if userConfig.AllowRepoConfig && userConfig.RepoConfig != "" {
return fmt.Errorf("You cannot use both --%s and --%s together. --%s is deprecated and will be removed in a later version, you should use --%s instead.", AllowRepoConfigFlag, RepoConfigFlag, AllowRepoConfigFlag, RepoConfigFlag)
return fmt.Errorf("You cannot use both --%s and --%s together. --%s is deprecated and will be removed in a later version, you should use --%s instead", AllowRepoConfigFlag, RepoConfigFlag, AllowRepoConfigFlag, RepoConfigFlag)
}

// The following combinations are valid.
Expand Down
4 changes: 2 additions & 2 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,11 +903,11 @@ func TestExecute_BitbucketServerBaseURLPort(t *testing.T) {
// Cannot use both --allow-repo-config and --repo-config
func TestExecute_AllowRepoConfigWithAllowRestrictedRepoConfig(t *testing.T) {
c := setup(map[string]interface{}{
cmd.AllowRepoConfigFlag: true,
cmd.AllowRepoConfigFlag: true,
cmd.RepoConfigFlag: "somefile",
})
err := c.Execute()
ErrEquals(t, "You cannot use both --allow-repo-config and --repo-config together. --allow-repo-config is deprecated and will be removed in a later version, you should use --repo-config instead.", err)
ErrEquals(t, "You cannot use both --allow-repo-config and --repo-config together. --allow-repo-config is deprecated and will be removed in a later version, you should use --repo-config instead", err)
}

func setup(flags map[string]interface{}) *cobra.Command {
Expand Down
68 changes: 34 additions & 34 deletions server/events/project_command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func TestDefaultProjectCommandBuilder_BuildAutoplanCommands(t *testing.T) {
exp: []exp{
{
projectConfig: &valid.Project{
Dir: ".",
Dir: ".",
Workspace: "default",
Autoplan: getDefaultAutoPlan(),
Autoplan: getDefaultAutoPlan(),
},
dir: ".",
workspace: "default",
dir: ".",
workspace: "default",
},
},
},
Expand Down Expand Up @@ -272,16 +272,16 @@ func TestDefaultProjectCommandBuilder_RepoRestrictionsBuildPlanCommands(t *testi
When(vcsClient.GetModifiedFiles(baseRepo, pull)).ThenReturn([]string{"main.tf"}, nil)

builder := &events.DefaultProjectCommandBuilder{
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
WorkingDir: workingDir,
ParserValidator: &yaml.ParserValidator{},
VCSClient: vcsClient,
ProjectFinder: &events.DefaultProjectFinder{},
AllowRepoConfig: false,
RepoConfig: repoConfig,
PendingPlanFinder: &events.DefaultPendingPlanFinder{},
AllowRepoConfigFlag: "allow-repo-config",
CommentBuilder: &events.CommentParser{},
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
WorkingDir: workingDir,
ParserValidator: &yaml.ParserValidator{},
VCSClient: vcsClient,
ProjectFinder: &events.DefaultProjectFinder{},
AllowRepoConfig: false,
RepoConfig: repoConfig,
PendingPlanFinder: &events.DefaultPendingPlanFinder{},
AllowRepoConfigFlag: "allow-repo-config",
CommentBuilder: &events.CommentParser{},
}

ctxs, err := builder.BuildAutoplanCommands(&events.CommandContext{
Expand Down Expand Up @@ -358,15 +358,15 @@ func TestDefaultProjectCommandBuilder_BuildSingleApplyCommandRepoRestrictions(t
When(vcsClient.GetModifiedFiles(baseRepo, pull)).ThenReturn([]string{"main.tf"}, nil)

builder := &events.DefaultProjectCommandBuilder{
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
WorkingDir: workingDir,
ParserValidator: &yaml.ParserValidator{},
VCSClient: vcsClient,
ProjectFinder: &events.DefaultProjectFinder{},
AllowRepoConfig: false,
RepoConfig: repoConfig,
AllowRepoConfigFlag: "allow-repo-config",
CommentBuilder: &events.CommentParser{},
WorkingDirLocker: events.NewDefaultWorkingDirLocker(),
WorkingDir: workingDir,
ParserValidator: &yaml.ParserValidator{},
VCSClient: vcsClient,
ProjectFinder: &events.DefaultProjectFinder{},
AllowRepoConfig: false,
RepoConfig: repoConfig,
AllowRepoConfigFlag: "allow-repo-config",
CommentBuilder: &events.CommentParser{},
}

cmdCtx := &events.CommandContext{
Expand Down Expand Up @@ -423,15 +423,15 @@ func TestDefaultProjectCommandBuilder_BuildSinglePlanApplyCommand(t *testing.T)
Name: models.PlanCommand,
Workspace: "myworkspace",
},
AtlantisYAML: "",
AtlantisYAML: "",
ExpProjectConfig: &valid.Project{
Dir: ".",
Dir: ".",
Workspace: "myworkspace",
Autoplan: getDefaultAutoPlan(),
Autoplan: getDefaultAutoPlan(),
},
ExpCommentArgs: []string{"commentarg"},
ExpWorkspace: "myworkspace",
ExpDir: ".",
ExpCommentArgs: []string{"commentarg"},
ExpWorkspace: "myworkspace",
ExpDir: ".",
},
{
Description: "no atlantis.yaml with project flag",
Expand Down Expand Up @@ -750,15 +750,15 @@ func TestDefaultProjectCommandBuilder_BuildMultiPlanNoAtlantisYAML(t *testing.T)
Equals(t, "project1", ctxs[0].RepoRelDir)
Equals(t, "default", ctxs[0].Workspace)
project1Config := valid.Project{
Dir: "project1",
Dir: "project1",
Workspace: events.DefaultWorkspace,
Autoplan: getDefaultAutoPlan(),
Autoplan: getDefaultAutoPlan(),
}

project2Config := valid.Project{
Dir: "project2",
Dir: "project2",
Workspace: events.DefaultWorkspace,
Autoplan: getDefaultAutoPlan(),
Autoplan: getDefaultAutoPlan(),
}
Equals(t, project1Config, *ctxs[0].ProjectConfig)
Equals(t, "project2", ctxs[1].RepoRelDir)
Expand Down Expand Up @@ -1096,6 +1096,6 @@ func String(v string) *string { return &v }
func getDefaultAutoPlan() valid.Autoplan {
return valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
Enabled: true,
Enabled: true,
}
}
4 changes: 2 additions & 2 deletions server/events/yaml/parser_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (p *ParserValidator) parseAndValidate(configData []byte, repoConfig raw.Rep
}

func (p *ParserValidator) getOverrideErrorMessage(key string) error {
return fmt.Errorf("%q cannot be specified in %q by default. To enable this, add %q to %q in the server side repo config.", key, AtlantisYAMLFilename, key, raw.AllowedOverridesKey)
return fmt.Errorf("%q cannot be specified in %q by default. To enable this, add %q to %q in the server side repo config", key, AtlantisYAMLFilename, key, raw.AllowedOverridesKey)
}

// Checks any sensitive fields present in atlantis.yaml against the list of allowed overrides and merge the configuration
Expand Down Expand Up @@ -172,7 +172,7 @@ func (p *ParserValidator) ValidateOverridesAndMergeConfig(config raw.Config, rep
config.Projects = finalProjects

if len(config.Workflows) > 0 && !(allowAllRepoConfig || lastMatchingRepo.AllowCustomWorkflows) {
return config, fmt.Errorf("%q cannot be specified in %q by default. To enable this, set %q to true in the server side repo config.", raw.CustomWorkflowsKey, AtlantisYAMLFilename, raw.CustomWorkflowsKey)
return config, fmt.Errorf("%q cannot be specified in %q by default. To enable this, set %q to true in the server side repo config", raw.CustomWorkflowsKey, AtlantisYAMLFilename, raw.CustomWorkflowsKey)
} else if len(config.Workflows) == 0 {
if len(repoConfig.Workflows) > 0 {
config.Workflows = repoConfig.Workflows
Expand Down
40 changes: 20 additions & 20 deletions server/events/yaml/parser_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ projects:
repos:
- id: /.*/
`,
expErr: `"workflow" cannot be specified in "atlantis.yaml" by default. To enable this, add "workflow" to "allowed_overrides" in the server side repo config.`,
expErr: `"workflow" cannot be specified in "atlantis.yaml" by default. To enable this, add "workflow" to "allowed_overrides" in the server side repo config`,
},
{
description: "atlantis config with custom workflows denied by repo config",
Expand All @@ -763,7 +763,7 @@ repos:
- id: /.*/
allowed_overrides: ["workflow"]
`,
expErr: `"workflows" cannot be specified in "atlantis.yaml" by default. To enable this, set "workflows" to true in the server side repo config.`,
expErr: `"workflows" cannot be specified in "atlantis.yaml" by default. To enable this, set "workflows" to true in the server side repo config`,
},
{
description: "atlantis config with workflow override allowed by repo config",
Expand Down Expand Up @@ -851,11 +851,11 @@ projects:
repos:
- id: /.*/
`,
expErr: `"apply_requirements" cannot be specified in "atlantis.yaml" by default. To enable this, add "apply_requirements" to "allowed_overrides" in the server side repo config.`,
expErr: `"apply_requirements" cannot be specified in "atlantis.yaml" by default. To enable this, add "apply_requirements" to "allowed_overrides" in the server side repo config`,
},
{
description: "last matching repo should be used",
repoName: "thisproject",
repoName: "thisproject",
atlantisYaml: `
version: 2
projects:
Expand All @@ -871,25 +871,25 @@ workflows:
workflow1: ~
workflow2: ~
`,
exp: valid.Config{
Version: 2,
Projects: []valid.Project{
{
Dir: ".",
Workspace: "default",
Workflow: String("workflow2"),
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
Enabled: true,
exp: valid.Config{
Version: 2,
Projects: []valid.Project{
{
Dir: ".",
Workspace: "default",
Workflow: String("workflow2"),
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
Enabled: true,
},
},
},
Workflows: map[string]valid.Workflow{
"workflow1": {},
"workflow2": {},
},
},
},
Workflows: map[string]valid.Workflow{
"workflow1": {},
"workflow2": {},
},
},
},
{
description: "atlantis config uses a workflow that doesn't exist in atlantis.yaml or repo config",
repoName: "anything",
Expand Down
1 change: 0 additions & 1 deletion server/events/yaml/raw/repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func checkOverrideValues(values interface{}) error {

func (r *Repo) IsOverrideAllowed(override string) bool {
for _, allowed := range r.AllowedOverrides {
fmt.Printf("checking %s against %s\n", allowed, override);
if allowed == override {
return true
}
Expand Down
8 changes: 3 additions & 5 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ repos:
Ok(t, err)

s, err := server.NewServer(server.UserConfig{
DataDir: tmpDir,
RepoConfig: repoFileLocation,
DataDir: tmpDir,
RepoConfig: repoFileLocation,
AtlantisURL: "http://example.com",
}, server.Config {

})
}, server.Config{})
Ok(t, err)
Equals(t, s.CommandRunner.ProjectCommandBuilder.(*events.DefaultProjectCommandBuilder).RepoConfig, expConfig)
}
Expand Down

0 comments on commit 83d09ab

Please sign in to comment.