-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeff DeCola (jeff-VirtualBox)
committed
Oct 6, 2016
1 parent
8a5a4ac
commit a1a8a6b
Showing
7 changed files
with
318 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
concourse | ||
playa-mesos | ||
coverage.out | ||
|
||
### Linux ### | ||
*~ | ||
|
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,153 @@ | ||
package actions | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/ckaznocha/marathon-resource/cmd/marathon-resource/marathon" | ||
"github.com/ckaznocha/marathon-resource/cmd/marathon-resource/mocks" | ||
gomarathon "github.com/gambol99/go-marathon" | ||
"github.com/golang/mock/gomock" | ||
) | ||
|
||
func TestOut(t *testing.T) { | ||
var ( | ||
ctrl = gomock.NewController(t) | ||
mockMarathoner = mocks.NewMockMarathoner(ctrl) | ||
) | ||
defer ctrl.Finish() | ||
|
||
gomock.InOrder( | ||
mockMarathoner.EXPECT().UpdateApp(gomock.Any()).Times(1).Return(gomarathon.DeploymentID{DeploymentID: "foo", Version: "bar"}, nil), | ||
mockMarathoner.EXPECT().UpdateApp(gomock.Any()).Times(1).Return(gomarathon.DeploymentID{}, errors.New("Something went wrong")), | ||
mockMarathoner.EXPECT().UpdateApp(gomock.Any()).Times(1).Return(gomarathon.DeploymentID{DeploymentID: "baz", Version: "bar"}, nil), | ||
mockMarathoner.EXPECT().UpdateApp(gomock.Any()).Times(1).Return(gomarathon.DeploymentID{DeploymentID: "quux", Version: "bar"}, nil), | ||
mockMarathoner.EXPECT().UpdateApp(gomock.Any()).Times(1).Return(gomarathon.DeploymentID{DeploymentID: "zork", Version: "bar"}, nil), | ||
) | ||
gomock.InOrder( | ||
mockMarathoner.EXPECT().CheckDeployment("foo").Times(1).Return(false, nil), | ||
mockMarathoner.EXPECT().CheckDeployment("baz").Times(2).Return(true, nil), | ||
mockMarathoner.EXPECT().CheckDeployment("quux").Times(1).Return(false, errors.New("Something bad happend")), | ||
mockMarathoner.EXPECT().CheckDeployment("zork").Times(2).Return(true, nil), | ||
) | ||
gomock.InOrder( | ||
mockMarathoner.EXPECT().DeleteDeployment("baz").Times(1).Return(nil), | ||
mockMarathoner.EXPECT().DeleteDeployment("zork").Times(1).Return(errors.New("Now way!")), | ||
) | ||
|
||
type args struct { | ||
input InputJSON | ||
appJSONPath string | ||
apiclient marathon.Marathoner | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want IOOutput | ||
wantErr bool | ||
}{ | ||
{ | ||
"Works", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "app.json", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{Version: Version{Ref: "bar"}}, | ||
false, | ||
}, | ||
{ | ||
"Bad app json file", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "ajson", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{}, | ||
true, | ||
}, | ||
{ | ||
"Bad app json file", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "app_bad.json", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{}, | ||
true, | ||
}, | ||
{ | ||
"Error from UpdateApp", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "app.json", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{}, | ||
true, | ||
}, | ||
{ | ||
"Deployment times out", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "app.json", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{}, | ||
true, | ||
}, | ||
{ | ||
"Check deployment errors", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "app.json", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{}, | ||
true, | ||
}, | ||
{ | ||
"Delete deployment errors", | ||
args{ | ||
input: InputJSON{ | ||
Params: Params{AppJSON: "app.json", TimeOut: 2}, | ||
Source: Source{}, | ||
}, | ||
appJSONPath: "../fixtures", | ||
apiclient: mockMarathoner, | ||
}, | ||
IOOutput{}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
got, err := Out(tt.args.input, tt.args.appJSONPath, tt.args.apiclient) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("%q. Out() error = %v, wantErr %v", tt.name, err, tt.wantErr) | ||
continue | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("%q. Out() = %v, want %v", tt.name, got, tt.want) | ||
} | ||
} | ||
} |
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 @@ | ||
{] |
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.