go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/api/gitiles/rest_treediff_test.go (about)

     1  // Copyright 2017 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package gitiles
    16  
    17  import (
    18  	"context"
    19  	"net/http"
    20  	"testing"
    21  
    22  	"go.chromium.org/luci/common/proto/git"
    23  	"go.chromium.org/luci/common/proto/gitiles"
    24  
    25  	. "github.com/smartystreets/goconvey/convey"
    26  )
    27  
    28  const fakeLogTreeDiffData = ")]}'\n" + `{
    29    "log": [
    30      {
    31        "commit": "8983b2db201b133c57c9e3f57d02f0ec6a7f2871",
    32        "tree": "b1e6757180406cb6f9ce3039fa9b75c3bb729331",
    33        "parents": [
    34          "4914490a7dfd1e421f6a72c4cc4eb7e2d53f978a"
    35        ],
    36        "author": {
    37          "name": "recipe-roller",
    38          "email": "recipe-roller@chromium.org",
    39          "time": "Wed Sep 20 23:10:41 2017"
    40        },
    41        "committer": {
    42          "name": "Commit Bot",
    43          "email": "commit-bot@chromium.org",
    44          "time": "Wed Sep 20 23:20:26 2017"
    45        },
    46        "message": "Roll recipe dependencies (trivial).\n\nThis is an automated CL created by the recipe roller. This CL rolls recipe\nchanges from upstream projects (e.g. depot_tools) into downstream projects\n(e.g. tools/build).\n\n\nMore info is at https://goo.gl/zkKdpD. Use https://goo.gl/noib3a to file a bug.\nbuild:\n  https://crrev.com/d03ed4cbbbd2c33920723b2503cb66b6c4bf7e96 Add -v to all invocations of provision_devices.py (bpastene@chromium.org)\n\n\nTBR\u003diannucci@chromium.org\n\nRecipe-Tryjob-Bypass-Reason: Autoroller\nBugdroid-Send-Email: False\nChange-Id: Ie13de0b5fe9b83ecaed5bbf9e72cbc0593697752\nReviewed-on: https://chromium-review.googlesource.com/675964\nReviewed-by: Recipe Roller \u003crecipe-roller@chromium.org\u003e\nCommit-Queue: Recipe Roller \u003crecipe-roller@chromium.org\u003e\n",
    47        "tree_diff": [
    48          {
    49            "type": "modify",
    50            "old_id": "bbc4e3f6914072a163b714191c71492fd946b118",
    51            "old_mode": 33188,
    52            "old_path": "infra/config/recipes.cfg",
    53            "new_id": "f04e427a40c00dc7fc149f4c52954d41bcf3d9cb",
    54            "new_mode": 33188,
    55            "new_path": "infra/config/recipes.cfg"
    56          },
    57          {
    58            "type": "modify",
    59            "old_id": "8d63485b0dcb75645c17d3125525c025baa9cfa8",
    60            "old_mode": 33188,
    61            "old_path": "recipes/README.recipes.md",
    62            "new_id": "b3b2e83a33c2397ed46638112a2d9162a393234d",
    63            "new_mode": 33188,
    64            "new_path": "recipes/README.recipes.md"
    65          }
    66        ]
    67      },
    68      {
    69        "commit": "4914490a7dfd1e421f6a72c4cc4eb7e2d53f978a",
    70        "tree": "238e32d50c69917375490aebdf6a1cbc65f496ed",
    71        "parents": [
    72          "dbed67c599faf07473865727beed7cc65e5f3147"
    73        ],
    74        "author": {
    75          "name": "Brandon Wylie",
    76          "email": "wylieb@chromium.org",
    77          "time": "Wed Sep 20 22:50:08 2017"
    78        },
    79        "committer": {
    80          "name": "Commit Bot",
    81          "email": "commit-bot@chromium.org",
    82          "time": "Wed Sep 20 23:16:16 2017"
    83        },
    84        "message": "[Findit] Flake Analyzer - Rework timeouts for dtpr pipeline.\n\nCurrently the dtpr has a target iterations that it wants to get\nrun, and uses that as a basis of calculation. The strategy is\nflipped where it has a certain time period it wants to fill\nand calculates the number of tests that it needs to fill it.\nAlong with this, now that flake swarming tasks are being deleted\nat the start of every new task, I added elpased second to the\nflake analysis model to  fill in the approximation of time.\n\nBug:764961\nChange-Id: Ib3b033f48c2b3f7ac72d1b5973aa2bd9876d9963\nReviewed-on: https://chromium-review.googlesource.com/666320\nCommit-Queue: Brandon Wylie \u003cwylieb@chromium.org\u003e\nReviewed-by: Jeffrey Li \u003clijeffrey@chromium.org\u003e\nReviewed-by: Shuotao Gao \u003cstgao@chromium.org\u003e\n",
    85        "tree_diff": [
    86          {
    87            "type": "modify",
    88            "old_id": "5e99bfe849b1272c4f93998c1a4e474d50f71d07",
    89            "old_mode": 33188,
    90            "old_path": "appengine/findit/model/flake/master_flake_analysis.py",
    91            "new_id": "19db9511283f35ab878071b68c212cbf10ff0d08",
    92            "new_mode": 33188,
    93            "new_path": "appengine/findit/model/flake/master_flake_analysis.py"
    94          },
    95          {
    96            "type": "modify",
    97            "old_id": "40536a3f184ae7c0db26263e822c1da548041a9a",
    98            "old_mode": 33188,
    99            "old_path": "appengine/findit/waterfall/flake/determine_true_pass_rate_pipeline.py",
   100            "new_id": "f27168be0a4e38240b27df3e76bf73df08c8c137",
   101            "new_mode": 33188,
   102            "new_path": "appengine/findit/waterfall/flake/determine_true_pass_rate_pipeline.py"
   103          },
   104          {
   105            "type": "modify",
   106            "old_id": "b51512266349757e2531ed5d35a8fe5594559071",
   107            "old_mode": 33188,
   108            "old_path": "appengine/findit/waterfall/flake/flake_analysis_util.py",
   109            "new_id": "2241c947e48fb8853bdb509355c54cb4c56c6546",
   110            "new_mode": 33188,
   111            "new_path": "appengine/findit/waterfall/flake/flake_analysis_util.py"
   112          },
   113          {
   114            "type": "modify",
   115            "old_id": "3c66ca68c36239213f762862276171b8226ade17",
   116            "old_mode": 33188,
   117            "old_path": "appengine/findit/waterfall/flake/test/determine_true_pass_rate_pipeline_test.py",
   118            "new_id": "711a1259cd0db909af40c7e529940c06cd2ba265",
   119            "new_mode": 33188,
   120            "new_path": "appengine/findit/waterfall/flake/test/determine_true_pass_rate_pipeline_test.py"
   121          },
   122          {
   123            "type": "modify",
   124            "old_id": "5fe2ab9acdd1a5b8c4a31e62fa7c0d7ccdadbb97",
   125            "old_mode": 33188,
   126            "old_path": "appengine/findit/waterfall/flake/test/flake_analysis_util_test.py",
   127            "new_id": "bf886194e8f359cbb49bfa6dc17d6e4376dae375",
   128            "new_mode": 33188,
   129            "new_path": "appengine/findit/waterfall/flake/test/flake_analysis_util_test.py"
   130          },
   131          {
   132            "type": "modify",
   133            "old_id": "bad7a80f8315a20ccf4f02c97148f6e843e893de",
   134            "old_mode": 33188,
   135            "old_path": "appengine/findit/waterfall/flake/test/update_flake_analysis_data_points_pipeline_test.py",
   136            "new_id": "f217c9981c9f3ecd39a9831216ca133be676607a",
   137            "new_mode": 33188,
   138            "new_path": "appengine/findit/waterfall/flake/test/update_flake_analysis_data_points_pipeline_test.py"
   139          },
   140          {
   141            "type": "modify",
   142            "old_id": "f098f9575b22990c35928d6af4e59c5c0944e48d",
   143            "old_mode": 33188,
   144            "old_path": "appengine/findit/waterfall/flake/update_flake_analysis_data_points_pipeline.py",
   145            "new_id": "8a7a2acff2058240dd645096649dc28a48cb61e9",
   146            "new_mode": 33188,
   147            "new_path": "appengine/findit/waterfall/flake/update_flake_analysis_data_points_pipeline.py"
   148          }
   149        ]
   150      }
   151  	]
   152  }
   153  `
   154  
   155  func TestLogWithTreeDiff(t *testing.T) {
   156  	t.Parallel()
   157  	ctx := context.Background()
   158  
   159  	Convey("Log with TreeDiff", t, func() {
   160  		srv, c := newMockClient(func(w http.ResponseWriter, r *http.Request) {
   161  			w.WriteHeader(200)
   162  			w.Header().Set("Content-Type", "application/json")
   163  			w.Write([]byte(fakeLogTreeDiffData))
   164  		})
   165  		defer srv.Close()
   166  
   167  		res, err := c.Log(ctx, &gitiles.LogRequest{
   168  			Project:            "repo",
   169  			Committish:         "8de6836858c99e48f3c58164ab717bda728e95dd",
   170  			ExcludeAncestorsOf: "master",
   171  			PageSize:           10,
   172  			TreeDiff:           true,
   173  		})
   174  		So(err, ShouldBeNil)
   175  		So(len(res.Log), ShouldEqual, 2)
   176  		So(res.Log[1].TreeDiff[0], ShouldResemble, &git.Commit_TreeDiff{
   177  			Type:    git.Commit_TreeDiff_MODIFY,
   178  			OldId:   "5e99bfe849b1272c4f93998c1a4e474d50f71d07",
   179  			OldMode: 33188,
   180  			OldPath: "appengine/findit/model/flake/master_flake_analysis.py",
   181  			NewId:   "19db9511283f35ab878071b68c212cbf10ff0d08",
   182  			NewMode: 33188,
   183  			NewPath: "appengine/findit/model/flake/master_flake_analysis.py",
   184  		})
   185  
   186  	})
   187  }