Skip to content

Commit

Permalink
Create repo only when DryRun is false (#221)
Browse files Browse the repository at this point in the history
* Create repo only when DruRun is false

* Attempt to fix repo creation visibility tests by changing dru-run  to be false

* Attempt to fix repo creation visibility tests by changing using IsPrivate flag

* Added debug logs

* Added override ignore

* Removed debug code

* Added missing IsPrivate true

* Reestablished previous code
  • Loading branch information
josecordaz authored May 27, 2021
1 parent 16bbe7d commit 31935fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 3 additions & 5 deletions pkg/cmdimpl/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,10 @@ func Add(args []string, allParams AddParamSet) error {
git push --set-upstream origin main`
cmd := fmt.Sprintf(cmdStr, owner, fluxRepoName)

if err := gitproviders.CreateRepository(fluxRepoName, owner, params.IsPrivate); err != nil {
return wrapError(err, "could not create repository")
}

if !params.DryRun {
if err := gitproviders.CreateRepository(fluxRepoName, owner, params.IsPrivate); err != nil {
return wrapError(err, "could not create repository")
}
if err := utils.CallCommandForEffectWithDebug(cmd); err != nil {
return wrapError(err, "could not add remote")
}
Expand Down Expand Up @@ -407,7 +406,6 @@ func Add(args []string, allParams AddParamSet) error {
return wrapError(err, "could not generate source manifest")
}

fmt.Println("DeploymentType check1", params.DeploymentType)
var appManifests []byte
switch params.DeploymentType {
case string(DeployTypeHelm):
Expand Down
15 changes: 8 additions & 7 deletions pkg/cmdimpl/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ var _ = Describe("Add repo with custom access test", func() {
Path: "./",
Branch: "main",
PrivateKey: privateKeyFileName,
DryRun: true,
IsPrivate: true,
Namespace: "wego-system",
IsPrivate: true,
DeploymentType: DeployTypeKustomize,
})

Expect(err).To(BeNil())
return override.Result{}
},
utils.OverrideFailure(utils.CallCommandForEffectWithInputPipeOp),
utils.OverrideFailure(utils.CallCommandForEffectWithDebugOp),
utils.OverrideIgnore(utils.CallCommandForEffectWithInputPipeOp),
utils.OverrideIgnore(utils.CallCommandOp),
utils.OverrideIgnore(utils.CallCommandForEffectWithDebugOp),
utils.OverrideBehavior(utils.CallCommandForEffectOp, handleGitLsRemote),
fluxops.Override(FailFluxHandler),
gitproviders.Override(fgphandler),
Expand Down Expand Up @@ -288,16 +288,17 @@ var _ = Describe("Add repo with custom access test", func() {
Path: "./",
Branch: "main",
PrivateKey: privateKeyFileName,
DryRun: true,
Namespace: "wego-system",
IsPrivate: false,
DeploymentType: DeployTypeKustomize,
})

Expect(err).Should(BeNil())
return override.Result{}
},
utils.OverrideFailure(utils.CallCommandForEffectWithInputPipeOp),
utils.OverrideFailure(utils.CallCommandForEffectWithDebugOp),
utils.OverrideIgnore(utils.CallCommandForEffectWithInputPipeOp),
utils.OverrideIgnore(utils.CallCommandOp),
utils.OverrideIgnore(utils.CallCommandForEffectWithDebugOp),
utils.OverrideBehavior(utils.CallCommandForEffectOp, handleGitLsRemote),
fluxops.Override(FailFluxHandler),
gitproviders.Override(fgphandler),
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ func OverrideFailure(callOp CallOperation) override.Override {
}
}

func OverrideIgnore(callOp CallOperation) override.Override {
location := &behaviors[callOp]
return override.Override{Handler: location, Mock: func(args ...interface{}) ([]byte, []byte, error) {
fmt.Println("ignoring ", args)
return nil, nil, nil
},
Original: behaviors[callOp],
}
}

func WithBehaviorFor(callOp CallOperation, behavior func(args ...interface{}) ([]byte, []byte, error), action func() ([]byte, []byte, error)) ([]byte, []byte, error) {
existingBehavior := behaviors[callOp]
behaviors[callOp] = behavior
Expand Down

0 comments on commit 31935fb

Please sign in to comment.