diff --git a/cmd/marathon-resource/actions/actions.go b/cmd/marathon-resource/actions/actions.go index 0dc356f..f412b9e 100644 --- a/cmd/marathon-resource/actions/actions.go +++ b/cmd/marathon-resource/actions/actions.go @@ -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 + +} diff --git a/cmd/marathon-resource/actions/actions_test.go b/cmd/marathon-resource/actions/actions_test.go index e65277a..dd156f2 100644 --- a/cmd/marathon-resource/actions/actions_test.go +++ b/cmd/marathon-resource/actions/actions_test.go @@ -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) + } + } +} diff --git a/cmd/marathon-resource/main.go b/cmd/marathon-resource/main.go index 66e617b..d39db60 100644 --- a/cmd/marathon-resource/main.go +++ b/cmd/marathon-resource/main.go @@ -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 {