@@ -23,6 +23,7 @@ func TestCreateAppVersion(t *testing.T) {
2323 tests := []struct {
2424 name string
2525 request * model.CreateAppVersionRequest
26+ dryRun bool
2627 mockResponse * http.Response
2728 mockResponseBody string
2829 mockError error
@@ -31,6 +32,25 @@ func TestCreateAppVersion(t *testing.T) {
3132 {
3233 name : "success" ,
3334 request : & model.CreateAppVersionRequest {ApplicationKey : "test-app" , Version : "1.0.0" },
35+ dryRun : false ,
36+ mockResponse : & http.Response {StatusCode : 201 },
37+ mockResponseBody : "{}" ,
38+ mockError : nil ,
39+ expectedError : "" ,
40+ },
41+ {
42+ name : "success with dry-run (200 OK)" ,
43+ request : & model.CreateAppVersionRequest {ApplicationKey : "test-app" , Version : "1.0.0" },
44+ dryRun : true ,
45+ mockResponse : & http.Response {StatusCode : 200 },
46+ mockResponseBody : "{\" validation\" : \" passed\" }" ,
47+ mockError : nil ,
48+ expectedError : "" ,
49+ },
50+ {
51+ name : "success with dry-run (201 Created)" ,
52+ request : & model.CreateAppVersionRequest {ApplicationKey : "test-app" , Version : "1.0.0" },
53+ dryRun : true ,
3454 mockResponse : & http.Response {StatusCode : 201 },
3555 mockResponseBody : "{}" ,
3656 mockError : nil ,
@@ -39,6 +59,7 @@ func TestCreateAppVersion(t *testing.T) {
3959 {
4060 name : "failure" ,
4161 request : & model.CreateAppVersionRequest {ApplicationKey : "test-app" , Version : "1.0.0" },
62+ dryRun : false ,
4263 mockResponse : & http.Response {StatusCode : 400 },
4364 mockResponseBody : "error" ,
4465 mockError : nil ,
@@ -47,6 +68,7 @@ func TestCreateAppVersion(t *testing.T) {
4768 {
4869 name : "http client error" ,
4970 request : & model.CreateAppVersionRequest {ApplicationKey : "test-app" , Version : "1.0.0" },
71+ dryRun : false ,
5072 mockResponse : nil ,
5173 mockResponseBody : "" ,
5274 mockError : errors .New ("http client error" ),
@@ -57,13 +79,15 @@ func TestCreateAppVersion(t *testing.T) {
5779 for _ , tt := range tests {
5880 t .Run (tt .name , func (t * testing.T ) {
5981 mockHttpClient := mockhttp .NewMockApptrustHttpClient (ctrl )
60- mockHttpClient .EXPECT ().Post ("/v1/applications/test-app/versions/" , tt .request , map [string ]string {"async" : "false" }).
61- Return (tt .mockResponse , []byte (tt .mockResponseBody ), tt .mockError ).Times (1 )
82+ mockHttpClient .EXPECT ().Post ("/v1/applications/test-app/versions/" , tt .request , map [string ]string {
83+ "async" : "false" ,
84+ "dry_run" : strconv .FormatBool (tt .dryRun ),
85+ }).Return (tt .mockResponse , []byte (tt .mockResponseBody ), tt .mockError ).Times (1 )
6286
6387 mockCtx := mockservice .NewMockContext (ctrl )
6488 mockCtx .EXPECT ().GetHttpClient ().Return (mockHttpClient ).Times (1 )
6589
66- err := service .CreateAppVersion (mockCtx , tt .request )
90+ err := service .CreateAppVersion (mockCtx , tt .request , tt . dryRun )
6791 if tt .expectedError == "" {
6892 assert .NoError (t , err )
6993 } else {
0 commit comments