Skip to content

Commit

Permalink
Added In func with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff DeCola (jeff-VirtualBox) committed Oct 6, 2016
1 parent 1b64d83 commit b14e3bb
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cmd/marathon-resource/actions/actions.go
Expand Up @@ -104,3 +104,15 @@ deployloop:
return IOOutput{Version: Version{Ref: did.Version}}, nil

}

// In shall
func In(input InputJSON, apiclient marathon.Marathoner) (IOOutput, error) {

app, err := apiclient.GetApp(input.Source.AppID, input.Version.Ref)
if err != nil {
return IOOutput{}, err
}

return IOOutput{Version: Version{Ref: app.Version}}, nil

}
59 changes: 59 additions & 0 deletions cmd/marathon-resource/actions/actions_test.go
Expand Up @@ -151,3 +151,62 @@ func TestOut(t *testing.T) {
}
}
}

func TestIn(t *testing.T) {
var (
ctrl = gomock.NewController(t)
mockMarathoner = mocks.NewMockMarathoner(ctrl)
)
defer ctrl.Finish()

gomock.InOrder(
mockMarathoner.EXPECT().GetApp("bar", "foo").Times(1).Return(gomarathon.Application{Version: "foo"}, nil),
mockMarathoner.EXPECT().GetApp("baz", "quux").Times(1).Return(gomarathon.Application{}, errors.New("Bad stuff")),
)

type args struct {
input InputJSON
apiclient marathon.Marathoner
}
tests := []struct {
name string
args args
want IOOutput
wantErr bool
}{
{
"Works",
args{
input: InputJSON{
Source: Source{AppID: "bar"},
Version: Version{Ref: "foo"},
},
apiclient: mockMarathoner,
},
IOOutput{Version: Version{Ref: "foo"}},
false,
},
{
"Errors",
args{
input: InputJSON{
Source: Source{AppID: "baz"},
Version: Version{Ref: "quux"},
},
apiclient: mockMarathoner,
},
IOOutput{},
true,
},
}
for _, tt := range tests {
got, err := In(tt.args.input, tt.args.apiclient)
if (err != nil) != tt.wantErr {
t.Errorf("%q. In() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("%q. In() = %v, want %v", tt.name, got, tt.want)
}
}
}
11 changes: 10 additions & 1 deletion cmd/marathon-resource/main.go
Expand Up @@ -44,8 +44,17 @@ func main() {
switch os.Args[1] {
case check:
//TODO: do check

case in:
//TODO: do in
output, err := actions.In(input, m)
if err != nil {
logger.WithError(err).Fatalf("Unable to get APP info from marathon: %s", err)
}
if err = encoder.Encode(output); err != nil {
logger.WithError(err).Fatalf("Failed to write output: %s", err)
}
return

case out:
output, err := actions.Out(input, os.Args[2], m)
if err != nil {
Expand Down

0 comments on commit b14e3bb

Please sign in to comment.