-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from marema31/RECIPES
Adding recipes first iteration, the issue #25 does not impact the main features I want to achieve for a MVP
- Loading branch information
Showing
72 changed files
with
922 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cmd_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/marema31/kamino/cmd" | ||
) | ||
|
||
type mockedCookbook struct { | ||
called bool | ||
errorLoad error | ||
doReturnValue bool | ||
} | ||
|
||
//Do manage the runnning of the cookbook | ||
func (ck *mockedCookbook) Do(ctx context.Context) bool { | ||
ck.called = true | ||
return ck.doReturnValue | ||
} | ||
|
||
// Load the step file and returns the priority and a list of steper for this file | ||
func (ck *mockedCookbook) Load(ctx context.Context, path string, recipes []string, stepNames []string, stepTypes []string) error { | ||
ck.called = false | ||
return ck.errorLoad | ||
} | ||
|
||
// Statistics return statistics on the cookbook | ||
func (ck *mockedCookbook) Statistics() (map[string][]int, int) { | ||
result := make(map[string][]int) | ||
var total int | ||
return result, total | ||
|
||
} | ||
|
||
func TestApplyOk(t *testing.T) { | ||
ck := &mockedCookbook{} | ||
err := cmd.Apply(ck, "testdata/good", []string{"recipe1ok", "recipe2ok"}, nil, nil) | ||
if err != nil { | ||
t.Errorf("Load should not returns an error, returned: %v", err) | ||
} | ||
|
||
if !ck.called { | ||
t.Errorf("Do should be called") | ||
} | ||
} | ||
|
||
func TestApplyLoadError(t *testing.T) { | ||
ck := &mockedCookbook{} | ||
ck.errorLoad = fmt.Errorf("fake error") | ||
err := cmd.Apply(ck, "testdata/good", []string{"recipe1ok", "recipe2ok"}, nil, nil) | ||
if err == nil { | ||
t.Errorf("Load should returns an error") | ||
} | ||
|
||
if ck.called { | ||
t.Errorf("Do should not be called") | ||
} | ||
} | ||
|
||
func TestApplyDoError(t *testing.T) { | ||
ck := &mockedCookbook{} | ||
ck.doReturnValue = true | ||
err := cmd.Apply(ck, "testdata/good", []string{"recipe1ok", "recipe2ok"}, nil, nil) | ||
if err == nil { | ||
t.Errorf("Load should returns an error") | ||
} | ||
|
||
if !ck.called { | ||
t.Errorf("Do should be called") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.