go.fuchsia.dev/jiri@v0.0.0-20240502161911-b66513b29486/cmd/jiri/edit_test.go (about)

     1  // Copyright 2019 The Fuchsia Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/google/go-cmp/cmp"
    12  )
    13  
    14  func TestUpdateVersion(t *testing.T) {
    15  	manifestContent := `
    16  <?xml version="1.0" encoding="UTF-8"?>
    17  <manifest>
    18  <packages>
    19      <!-- Packages for buildtools -->
    20      <!--   GN -->
    21      <package name="gn/gn/${platform}"
    22               version="git_revision:89d5ef56cb999a1cb007b2671d375932703d4665"
    23               path="buildtools/{{.OS}}-{{.Arch}}"/>
    24      <!--   Ninja -->
    25      <package name="infra/ninja/${platform}"
    26               version="git_revision:9eac2058b70615519b2c4d8c6bdbfca1bd079e39"
    27               path="buildtools/{{.OS}}-{{.Arch}}"/>
    28      <!--   Breakpad -->
    29      <package name="fuchsia/tools/breakpad/${os=linux}-${arch}"
    30               version="git_revision:9eac2058b70615519b2c4d8c6bdbfca1bd079e39"
    31               path="buildtools/{{.OS}}-{{.Arch}}"/>
    32  </packages>
    33  </manifest>
    34  `
    35  
    36  	tests := make(map[*packageChanges]string)
    37  	tests[&packageChanges{
    38  		Name:   "gn/gn/${platform}",
    39  		OldVer: "git_revision:89d5ef56cb999a1cb007b2671d375932703d4665",
    40  		NewVer: "git_revision:ffffffffffffffffffffffffffffffffffffffff",
    41  	}] = `
    42  <?xml version="1.0" encoding="UTF-8"?>
    43  <manifest>
    44  <packages>
    45      <!-- Packages for buildtools -->
    46      <!--   GN -->
    47      <package name="gn/gn/${platform}"
    48               version="git_revision:ffffffffffffffffffffffffffffffffffffffff"
    49               path="buildtools/{{.OS}}-{{.Arch}}"/>
    50      <!--   Ninja -->
    51      <package name="infra/ninja/${platform}"
    52               version="git_revision:9eac2058b70615519b2c4d8c6bdbfca1bd079e39"
    53               path="buildtools/{{.OS}}-{{.Arch}}"/>
    54      <!--   Breakpad -->
    55      <package name="fuchsia/tools/breakpad/${os=linux}-${arch}"
    56               version="git_revision:9eac2058b70615519b2c4d8c6bdbfca1bd079e39"
    57               path="buildtools/{{.OS}}-{{.Arch}}"/>
    58  </packages>
    59  </manifest>
    60  `
    61  	tests[&packageChanges{
    62  		Name:   "fuchsia/tools/breakpad/${os=linux}-${arch}",
    63  		OldVer: "git_revision:9eac2058b70615519b2c4d8c6bdbfca1bd079e39",
    64  		NewVer: "git_revision:ffffffffffffffffffffffffffffffffffffffff",
    65  	}] = `
    66  <?xml version="1.0" encoding="UTF-8"?>
    67  <manifest>
    68  <packages>
    69      <!-- Packages for buildtools -->
    70      <!--   GN -->
    71      <package name="gn/gn/${platform}"
    72               version="git_revision:89d5ef56cb999a1cb007b2671d375932703d4665"
    73               path="buildtools/{{.OS}}-{{.Arch}}"/>
    74      <!--   Ninja -->
    75      <package name="infra/ninja/${platform}"
    76               version="git_revision:9eac2058b70615519b2c4d8c6bdbfca1bd079e39"
    77               path="buildtools/{{.OS}}-{{.Arch}}"/>
    78      <!--   Breakpad -->
    79      <package name="fuchsia/tools/breakpad/${os=linux}-${arch}"
    80               version="git_revision:ffffffffffffffffffffffffffffffffffffffff"
    81               path="buildtools/{{.OS}}-{{.Arch}}"/>
    82  </packages>
    83  </manifest>
    84  `
    85  
    86  	for k, v := range tests {
    87  		if res, err := updateVersion(manifestContent, "package", *k); err != nil {
    88  			t.Errorf("test updateVersion failed due to error: %v", err)
    89  		} else if res != v {
    90  			t.Errorf("expect:%s\n got:%s\nwhen testing updateVersion", v, res)
    91  		}
    92  	}
    93  }
    94  
    95  func TestUpdateRevision(t *testing.T) {
    96  	mainifestContent := `
    97  <?xml version="1.0" encoding="UTF-8"?>
    98  <!-- See README.dart.md for instructions on how to update this -->
    99  <manifest>
   100  	<projects>
   101  	<project name="dart/sdk"
   102  				path="third_party/dart"
   103  				remote="https://dart.googlesource.com/sdk"
   104  				gerrithost="https://dart-review.googlesource.com"
   105  				revision="224f82c21cb2966f36ab850eae7ef5c8697cc477"/>
   106  	<project name="dart/observatory_pub_packages"
   107  				path="third_party/dart/third_party/observatory_pub_packages"
   108  				remote="https://dart.googlesource.com/observatory_pub_packages/"
   109  				gerrithost="https://dart-review.googlesource.com"
   110  				revision="0894122173b0f98eb08863a7712e78407d4477bc"/>
   111  
   112  	<project name="third_party/dart-pkg"
   113  				path="third_party/dart-pkg/pub"
   114  				remote="https://fuchsia.googlesource.com/third_party/dart-pkg"
   115  				gerrithost="https://fuchsia-review.googlesource.com"/>
   116  	</projects>
   117  </manifest>
   118  `
   119  
   120  	tests := make(map[*projectChanges]string)
   121  	tests[&projectChanges{
   122  		Name:   "dart/sdk",
   123  		Remote: "",
   124  		Path:   "",
   125  		OldRev: "224f82c21cb2966f36ab850eae7ef5c8697cc477",
   126  		NewRev: "ffffffffffffffffffffffffffffffffffffffff",
   127  	}] = `
   128  <?xml version="1.0" encoding="UTF-8"?>
   129  <!-- See README.dart.md for instructions on how to update this -->
   130  <manifest>
   131  	<projects>
   132  	<project name="dart/sdk"
   133  				path="third_party/dart"
   134  				remote="https://dart.googlesource.com/sdk"
   135  				gerrithost="https://dart-review.googlesource.com"
   136  				revision="ffffffffffffffffffffffffffffffffffffffff"/>
   137  	<project name="dart/observatory_pub_packages"
   138  				path="third_party/dart/third_party/observatory_pub_packages"
   139  				remote="https://dart.googlesource.com/observatory_pub_packages/"
   140  				gerrithost="https://dart-review.googlesource.com"
   141  				revision="0894122173b0f98eb08863a7712e78407d4477bc"/>
   142  
   143  	<project name="third_party/dart-pkg"
   144  				path="third_party/dart-pkg/pub"
   145  				remote="https://fuchsia.googlesource.com/third_party/dart-pkg"
   146  				gerrithost="https://fuchsia-review.googlesource.com"/>
   147  	</projects>
   148  </manifest>
   149  `
   150  
   151  	tests[&projectChanges{
   152  		Name:   "third_party/dart-pkg",
   153  		Remote: "",
   154  		Path:   "",
   155  		OldRev: "",
   156  		NewRev: "ffffffffffffffffffffffffffffffffffffffff",
   157  	}] = `
   158  <?xml version="1.0" encoding="UTF-8"?>
   159  <!-- See README.dart.md for instructions on how to update this -->
   160  <manifest>
   161  	<projects>
   162  	<project name="dart/sdk"
   163  				path="third_party/dart"
   164  				remote="https://dart.googlesource.com/sdk"
   165  				gerrithost="https://dart-review.googlesource.com"
   166  				revision="224f82c21cb2966f36ab850eae7ef5c8697cc477"/>
   167  	<project name="dart/observatory_pub_packages"
   168  				path="third_party/dart/third_party/observatory_pub_packages"
   169  				remote="https://dart.googlesource.com/observatory_pub_packages/"
   170  				gerrithost="https://dart-review.googlesource.com"
   171  				revision="0894122173b0f98eb08863a7712e78407d4477bc"/>
   172  
   173  	<project name="third_party/dart-pkg"
   174  				path="third_party/dart-pkg/pub"
   175  				remote="https://fuchsia.googlesource.com/third_party/dart-pkg"
   176  				gerrithost="https://fuchsia-review.googlesource.com"
   177           revision="ffffffffffffffffffffffffffffffffffffffff"/>
   178  	</projects>
   179  </manifest>
   180  `
   181  	for k, v := range tests {
   182  		if res, err := updateRevision(mainifestContent, "project", k.OldRev, k.NewRev, k.Name); err != nil {
   183  			t.Errorf("test updateRevision failed due to error: %v", err)
   184  		} else if res != v {
   185  			t.Errorf("expect:%s\n got:%s\nwhen testing updateVersion", v, res)
   186  		}
   187  	}
   188  }
   189  
   190  func TestUpdateDuplicateRevision(t *testing.T) {
   191  	manifestContent := `
   192  <?xml version="1.0" encoding="UTF-8"?>
   193  <manifest>
   194    <projects>
   195      <!-- The ICU library to use for top-of-tree Fuchsia builds -->
   196      <project name="chromium/deps/icu@default"
   197               gitsubmoduleof="fuchsia"
   198               path="third_party/icu/default"
   199               remote="https://chromium.googlesource.com/chromium/deps/icu"
   200               gerrithost="https://chromium-review.googlesource.com"
   201               revision="1b7d391f0528fb3a4976b7541b387ee04f915f83"/>
   202      <!-- The ICU library to use for "stable" Fuchsia builds -->
   203      <project name="chromium/deps/icu@stable"
   204               gitsubmoduleof="fuchsia"
   205               path="third_party/icu/stable"
   206               remote="https://chromium.googlesource.com/chromium/deps/icu"
   207               gerrithost="https://chromium-review.googlesource.com"
   208               revision="da07448619763d1cde255b361324242646f5b268"/>
   209      <!-- The ICU library to use for "latest" Fuchsia builds -->
   210      <project name="chromium/deps/icu@latest"
   211               gitsubmoduleof="fuchsia"
   212               path="third_party/icu/latest"
   213               remote="https://chromium.googlesource.com/chromium/deps/icu"
   214               gerrithost="https://chromium-review.googlesource.com"
   215               revision="da07448619763d1cde255b361324242646f5b268"/>
   216      <project name="chromium/deps/icu@extra"
   217               gitsubmoduleof="fuchsia"
   218               path="third_party/icu/latest"
   219               remote="https://chromium.googlesource.com/chromium/deps/icu"
   220               gerrithost="https://chromium-review.googlesource.com"/>
   221    </projects>
   222  </manifest>
   223  `
   224  
   225  	tests := make(map[*projectChanges]string)
   226  	tests[&projectChanges{
   227  		Name:   "chromium/deps/icu@latest",
   228  		Remote: "",
   229  		Path:   "",
   230  		OldRev: "da07448619763d1cde255b361324242646f5b268",
   231  		NewRev: "1b7d391f0528fb3a4976b7541b387ee04f915f83",
   232  	}] = `
   233  <?xml version="1.0" encoding="UTF-8"?>
   234  <manifest>
   235    <projects>
   236      <!-- The ICU library to use for top-of-tree Fuchsia builds -->
   237      <project name="chromium/deps/icu@default"
   238               gitsubmoduleof="fuchsia"
   239               path="third_party/icu/default"
   240               remote="https://chromium.googlesource.com/chromium/deps/icu"
   241               gerrithost="https://chromium-review.googlesource.com"
   242               revision="1b7d391f0528fb3a4976b7541b387ee04f915f83"/>
   243      <!-- The ICU library to use for "stable" Fuchsia builds -->
   244      <project name="chromium/deps/icu@stable"
   245               gitsubmoduleof="fuchsia"
   246               path="third_party/icu/stable"
   247               remote="https://chromium.googlesource.com/chromium/deps/icu"
   248               gerrithost="https://chromium-review.googlesource.com"
   249               revision="da07448619763d1cde255b361324242646f5b268"/>
   250      <!-- The ICU library to use for "latest" Fuchsia builds -->
   251      <project name="chromium/deps/icu@latest"
   252               gitsubmoduleof="fuchsia"
   253               path="third_party/icu/latest"
   254               remote="https://chromium.googlesource.com/chromium/deps/icu"
   255               gerrithost="https://chromium-review.googlesource.com"
   256               revision="1b7d391f0528fb3a4976b7541b387ee04f915f83"/>
   257      <project name="chromium/deps/icu@extra"
   258               gitsubmoduleof="fuchsia"
   259               path="third_party/icu/latest"
   260               remote="https://chromium.googlesource.com/chromium/deps/icu"
   261               gerrithost="https://chromium-review.googlesource.com"/>
   262    </projects>
   263  </manifest>
   264  `
   265  	tests[&projectChanges{
   266  		Name:   "chromium/deps/icu@extra",
   267  		Remote: "",
   268  		Path:   "",
   269  		OldRev: "",
   270  		NewRev: "1b7d391f0528fb3a4976b7541b387ee04f915f83",
   271  	}] = `
   272  <?xml version="1.0" encoding="UTF-8"?>
   273  <manifest>
   274    <projects>
   275      <!-- The ICU library to use for top-of-tree Fuchsia builds -->
   276      <project name="chromium/deps/icu@default"
   277               gitsubmoduleof="fuchsia"
   278               path="third_party/icu/default"
   279               remote="https://chromium.googlesource.com/chromium/deps/icu"
   280               gerrithost="https://chromium-review.googlesource.com"
   281               revision="1b7d391f0528fb3a4976b7541b387ee04f915f83"/>
   282      <!-- The ICU library to use for "stable" Fuchsia builds -->
   283      <project name="chromium/deps/icu@stable"
   284               gitsubmoduleof="fuchsia"
   285               path="third_party/icu/stable"
   286               remote="https://chromium.googlesource.com/chromium/deps/icu"
   287               gerrithost="https://chromium-review.googlesource.com"
   288               revision="da07448619763d1cde255b361324242646f5b268"/>
   289      <!-- The ICU library to use for "latest" Fuchsia builds -->
   290      <project name="chromium/deps/icu@latest"
   291               gitsubmoduleof="fuchsia"
   292               path="third_party/icu/latest"
   293               remote="https://chromium.googlesource.com/chromium/deps/icu"
   294               gerrithost="https://chromium-review.googlesource.com"
   295               revision="da07448619763d1cde255b361324242646f5b268"/>
   296      <project name="chromium/deps/icu@extra"
   297               gitsubmoduleof="fuchsia"
   298               path="third_party/icu/latest"
   299               remote="https://chromium.googlesource.com/chromium/deps/icu"
   300               gerrithost="https://chromium-review.googlesource.com"
   301               revision="1b7d391f0528fb3a4976b7541b387ee04f915f83"/>
   302    </projects>
   303  </manifest>
   304  `
   305  
   306  	for k, v := range tests {
   307  		t.Run(fmt.Sprintf("%v", k), func(t *testing.T) {
   308  			if res, err := updateRevision(manifestContent, "project", k.OldRev, k.NewRev, k.Name); err != nil {
   309  				t.Errorf("test updateRevision failed due to error: %v", err)
   310  			} else if res != v {
   311  				t.Errorf("expect:%s\n got:%s\nwhen testing updateVersion, diff:\n%v", v, res, cmp.Diff(v, res))
   312  			}
   313  		})
   314  	}
   315  }