How to use buildSpecs method of build Package

Best Ginkgo code snippet using build.buildSpecs

per_project_buildspec_test.go

Source:per_project_buildspec_test.go Github

copy

Full Screen

1// Copyright 2021 The Chromium OS Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//go:build !windows5// +build !windows6package main7import (8	"fmt"9	"testing"10	"time"11	"infra/cros/internal/assert"12	gerrit "infra/cros/internal/gerrit"13	"infra/cros/internal/gs"14	lgs "go.chromium.org/luci/common/gcloud/gs"15	"go.chromium.org/luci/hardcoded/chromeinfra"16)17const (18	unpinnedLocalManifestXML = `19<manifest>20  <remote name="cros-internal"21          fetch="https://chrome-internal.googlesource.com"22          review="https://chrome-internal-review.googlesource.com" />23  <project name="foo"24	   path="src/foo"25	   remote="cros-internal" />26  <project name="bar"27	   path="src/bar"28	   remote="cros-internal" />29</manifest>30`31	buildspecXML = `32<manifest>33  <remote name="cros-internal"34          fetch="https://chrome-internal.googlesource.com"35          review="https://chrome-internal-review.googlesource.com" />36  <project name="foo"37	   path="src/foo"38	   revision="revision-foo"39	   remote="cros-internal" />40  <project name="baz"41	   path="src/baz"42	   revision="revision-baz"43	   remote="cros-internal" />44</manifest>45`46	pinnedLocalManifestXML = `<manifest>47  <remote fetch="https://chrome-internal.googlesource.com" name="cros-internal" review="https://chrome-internal-review.googlesource.com"></remote>48  <default></default>49  <project path="src/foo" name="foo" revision="revision-foo" remote="cros-internal"></project>50  <project path="src/bar" name="bar" remote="cros-internal"></project>51</manifest>`52)53var (54	application = GetApplication(chromeinfra.DefaultAuthOptions())55)56type testConfig struct {57	projects   map[string][]string58	otherRepos []string59	// Map between buildspec name and whether or not to expect a GS write.60	buildspecs              map[string]bool61	branches                []string62	buildspecsExists        bool63	expectedForce           bool64	watchPaths              map[string][]string65	allProjects             []string66	noLocalManifestProjects []string67	expectedSetTTL          map[string]time.Duration68	dryRun                  bool69}70func (tc *testConfig) setUpPPBTest(t *testing.T) (*gs.FakeClient, gerrit.Client) {71	t.Helper()72	projects := map[string]string{}73	for prog, projs := range tc.projects {74		projects["chromeos/program/"+prog] = fmt.Sprintf("chromeos-%s", prog)75		for _, proj := range projs {76			projects["chromeos/project/"+prog+"/"+proj] = fmt.Sprintf("chromeos-%s-%s", prog, proj)77		}78	}79	for _, repo := range tc.otherRepos {80		projects[repo] = gsBuildspecPath(repo).Bucket()81	}82	// Mock tip-of-branch (branch) manifest file requests.83	expectedDownloads := map[gerrit.ExpectedPathParams]*string{}84	for project := range projects {85		contents := unpinnedLocalManifestXML86		for _, branch := range tc.branches {87			expectedDownloads[gerrit.ExpectedPathParams{88				Host:    chromeInternalHost,89				Project: project,90				Path:    "local_manifest.xml",91				Ref:     branch,92			}] = &contents93		}94	}95	for _, project := range tc.noLocalManifestProjects {96		for _, branch := range tc.branches {97			expectedDownloads[gerrit.ExpectedPathParams{98				Host:    chromeInternalHost,99				Project: project,100				Path:    "local_manifest.xml",101				Ref:     branch,102			}] = nil103		}104	}105	gc := &gerrit.MockClient{106		T: t,107		ExpectedProjects: map[string][]string{108			chromeInternalHost: tc.allProjects,109		},110		ExpectedBranches: map[string]map[string]map[string]string{111			// Mock manifest-internal branches request.112			chromeInternalHost: {113				"chromeos/manifest-internal": {114					"refs/heads/main":                "deadcafe",115					"refs/heads/release-R93-13816.B": "deadbeef",116					"refs/heads/release-R94-13904.B": "beefcafe",117				},118			},119		},120		ExpectedDownloads: expectedDownloads,121	}122	// Mock external and internal buildspec file requests.123	expectedReads := map[string][]byte{}124	expectedWrites := map[string][]byte{}125	for buildspec := range tc.buildspecs {126		expectedReads[string(lgs.MakePath(externalBuildspecsGSBucketDefault, buildspec))] = []byte("")127		expectedReads[string(lgs.MakePath(internalBuildspecsGSBucketDefault, buildspec))] = []byte(buildspecXML)128	}129	expectedBucketLists := make(map[string][]string)130	for buildspec, expectWrite := range tc.buildspecs {131		relpath := fmt.Sprintf("buildspecs/%s", buildspec)132		if expectWrite {133			for _, bucket := range projects {134				expectedWrites[string(lgs.MakePath(bucket, relpath))] = []byte(pinnedLocalManifestXML)135			}136		}137		list := []string{}138		if tc.buildspecsExists {139			list = []string{"buildspecs/" + buildspec}140		}141		expectedBucketLists[relpath] = list142		expectedBucketLists[relpath] = list143	}144	expectedLists := make(map[string]map[string][]string)145	for _, bucket := range projects {146		expectedLists[bucket] = expectedBucketLists147	}148	if tc.dryRun {149		expectedWrites = make(map[string][]byte)150	}151	// Set up gs.List expectations.152	expectedLists[externalBuildspecsGSBucketDefault] = map[string][]string{}153	expectedLists[internalBuildspecsGSBucketDefault] = map[string][]string{}154	if tc.watchPaths != nil {155		for prefix, files := range tc.watchPaths {156			expectedLists[externalBuildspecsGSBucketDefault][prefix] = files157			expectedLists[internalBuildspecsGSBucketDefault][prefix] = files158		}159	}160	f := &gs.FakeClient{161		T:              t,162		ExpectedReads:  expectedReads,163		ExpectedWrites: expectedWrites,164		ExpectedLists:  expectedLists,165		ExpectedSetTTL: tc.expectedSetTTL,166	}167	return f, gc168}169func TestCreateProjectBuildspec(t *testing.T) {170	t.Parallel()171	ttl := 90172	tc := testConfig{173		projects: map[string][]string{174			"galaxy": {"milkyway"},175		},176		buildspecs: map[string]bool{177			"full/buildspecs/93/13811.0.0.xml": true,178		},179		branches: []string{"refs/heads/release-R93-13816.B"},180		// Test --ttl feature.181		expectedSetTTL: map[string]time.Duration{182			"gs://chromeos-galaxy/buildspecs/full/buildspecs/93/13811.0.0.xml":          time.Duration(ttl * 24 * int(time.Hour)),183			"gs://chromeos-galaxy-milkyway/buildspecs/full/buildspecs/93/13811.0.0.xml": time.Duration(ttl * 24 * int(time.Hour)),184		},185	}186	f, gc := tc.setUpPPBTest(t)187	b := projectBuildspec{188		buildspec:                  "full/buildspecs/93/13811.0.0.xml",189		projects:                   []string{"galaxy/milkyway"},190		ttl:                        ttl,191		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,192		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,193	}194	assert.NilError(t, b.CreateBuildspecs(f, gc))195}196func TestCreateProjectBuildspecDryRun(t *testing.T) {197	t.Parallel()198	tc := testConfig{199		projects: map[string][]string{200			"galaxy": {"milkyway"},201		},202		buildspecs: map[string]bool{203			"full/buildspecs/93/13811.0.0.xml": true,204		},205		branches: []string{"refs/heads/release-R93-13816.B"},206		dryRun:   true,207	}208	f, gc := tc.setUpPPBTest(t)209	b := projectBuildspec{210		buildspec:                  "full/buildspecs/93/13811.0.0.xml",211		projects:                   []string{"galaxy/milkyway"},212		push:                       false,213		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,214		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,215	}216	assert.NilError(t, b.CreateBuildspecs(f, gc))217}218// Specifically test 96 to check that the tool properly accounts for the219// missing 95.220func TestCreateProjectBuildspecToT(t *testing.T) {221	t.Parallel()222	tc := testConfig{223		projects: map[string][]string{224			"galaxy": {"milkyway"},225		},226		buildspecs: map[string]bool{227			"full/buildspecs/96/13811.0.0-rc2.xml": true,228		},229		branches: []string{"refs/heads/main"},230	}231	f, gc := tc.setUpPPBTest(t)232	b := projectBuildspec{233		buildspec:                  "full/buildspecs/96/13811.0.0-rc2.xml",234		projects:                   []string{"galaxy/milkyway"},235		push:                       true,236		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,237		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,238	}239	assert.NilError(t, b.CreateBuildspecs(f, gc))240}241func TestCreateProjectBuildspecForce(t *testing.T) {242	t.Parallel()243	tc := testConfig{244		projects: map[string][]string{245			"galaxy": {"milkyway"},246		},247		buildspecs: map[string]bool{248			"full/buildspecs/93/13811.0.0.xml": true,249		},250		branches:         []string{"refs/heads/release-R93-13816.B"},251		buildspecsExists: true,252	}253	f, gc := tc.setUpPPBTest(t)254	b := projectBuildspec{255		buildspec:                  "full/buildspecs/93/13811.0.0.xml",256		projects:                   []string{"galaxy/milkyway"},257		force:                      true,258		push:                       true,259		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,260		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,261	}262	assert.NilError(t, b.CreateBuildspecs(f, gc))263}264func TestCreateProjectBuildspecExistsNoForce(t *testing.T) {265	t.Parallel()266	// File shouldn't be written to GS if force is not set.267	tc := testConfig{268		projects: map[string][]string{269			"galaxy": {"milkyway"},270		},271		buildspecs: map[string]bool{272			"full/buildspecs/93/13811.0.0.xml": false,273		},274		branches:         []string{"refs/heads/release-R93-13816.B"},275		buildspecsExists: true,276	}277	f, gc := tc.setUpPPBTest(t)278	b := projectBuildspec{279		buildspec:                  "full/buildspecs/93/13811.0.0.xml",280		projects:                   []string{"galaxy/milkyway"},281		force:                      false,282		push:                       true,283		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,284		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,285	}286	assert.NilError(t, b.CreateBuildspecs(f, gc))287}288func TestCreateProjectBuildspecMultiple(t *testing.T) {289	t.Parallel()290	watchPaths := map[string][]string{291		"full/buildspecs/": {292			"full/buildspecs/93/",293			"full/buildspecs/94/13010.0.0-rc1.xml",294			"full/buildspecs/94/13011.0.0-rc1.xml",295		},296		"buildspecs/": {297			"full/buildspecs/94/13010.0.0.xml",298			"full/buildspecs/94/13011.0.0.xml",299		},300	}301	tc := testConfig{302		projects: map[string][]string{303			"galaxy": {"milkyway"},304		},305		buildspecs: map[string]bool{306			"full/buildspecs/94/13010.0.0-rc1.xml": true,307			"full/buildspecs/94/13011.0.0-rc1.xml": true,308			"buildspecs/94/13010.0.0.xml":          true,309			"buildspecs/94/13011.0.0.xml":          true,310		},311		watchPaths: watchPaths,312		branches:   []string{"refs/heads/release-R94-13904.B"},313	}314	f, gc := tc.setUpPPBTest(t)315	b := projectBuildspec{316		watchPaths:                 []string{"full/buildspecs/", "buildspecs/"},317		minMilestone:               94,318		projects:                   []string{"galaxy/milkyway"},319		push:                       true,320		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,321		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,322	}323	assert.NilError(t, b.CreateBuildspecs(f, gc))324}325func TestCreateProjectBuildspecMultipleProgram(t *testing.T) {326	t.Parallel()327	watchPaths := map[string][]string{328		"full/buildspecs/": {329			"full/buildspecs/93/",330			"full/buildspecs/94/13010.0.0-rc1.xml",331			"full/buildspecs/94/13011.0.0-rc1.xml",332		},333		"buildspecs/": {334			"full/buildspecs/94/13010.0.0.xml",335			"full/buildspecs/94/13011.0.0.xml",336		},337	}338	tc := testConfig{339		projects: map[string][]string{340			"galaxy": {"milkyway", "andromeda"},341		},342		buildspecs: map[string]bool{343			"full/buildspecs/94/13010.0.0-rc1.xml": true,344			"full/buildspecs/94/13011.0.0-rc1.xml": true,345			"buildspecs/94/13010.0.0.xml":          true,346			"buildspecs/94/13011.0.0.xml":          true,347		},348		watchPaths: watchPaths,349		branches:   []string{"refs/heads/release-R94-13904.B"},350		allProjects: []string{351			"chromeos/project/galaxy/milkyway",352			"chromeos/project/galaxy/andromeda",353			"chromeos/project/galaxy/missing",354			"chromeos/foo",355		},356		// Test that a project missing a local manifest file does not doom357		// the overall run, if wildcards are in use.358		noLocalManifestProjects: []string{359			"chromeos/project/galaxy/missing",360		},361	}362	f, gc := tc.setUpPPBTest(t)363	b := projectBuildspec{364		watchPaths:                 []string{"full/buildspecs/", "buildspecs/"},365		minMilestone:               94,366		projects:                   []string{"galaxy/*"},367		push:                       true,368		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,369		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,370	}371	assert.NilError(t, b.CreateBuildspecs(f, gc))372}373func TestCreateProjectBuildspecOtherRepos(t *testing.T) {374	t.Parallel()375	tc := testConfig{376		projects: map[string][]string{377			"galaxy": {"milkyway"},378		},379		otherRepos: []string{"chromeos-vendor-qti-camx"},380		buildspecs: map[string]bool{381			"full/buildspecs/93/13811.0.0.xml": true,382		},383		branches: []string{"refs/heads/release-R93-13816.B"},384	}385	f, gc := tc.setUpPPBTest(t)386	b := projectBuildspec{387		buildspec:                  "full/buildspecs/93/13811.0.0.xml",388		otherRepos:                 []string{"chromeos-vendor-qti-camx"},389		projects:                   []string{"galaxy/milkyway"},390		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,391		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,392	}393	assert.NilError(t, b.CreateBuildspecs(f, gc))394}...

Full Screen

Full Screen

public_buildspec_test.go

Source:public_buildspec_test.go Github

copy

Full Screen

1// Copyright 2021 The Chromium OS Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//go:build !windows5// +build !windows6package main7import (8	"context"9	"infra/cros/internal/assert"10	"infra/cros/internal/gerrit"11	"infra/cros/internal/gs"12	"testing"13	"github.com/golang/mock/gomock"14	gitilespb "go.chromium.org/luci/common/proto/gitiles"15	"go.chromium.org/luci/common/proto/gitiles/mock_gitiles"16)17const (18	internalManifestXML = `<?xml version="1.0" encoding="UTF-8"?>19<manifest>20  <remote name="cros" fetch="https://chromium.googlesource.com">21    <annotation name="public" value="true"/>22  </remote>23  <remote name="cros-internal" fetch="https://chrome-internal.googlesource.com">24    <annotation name="public" value="false"/>25  </remote>26  <default remote="cros" revision="refs/heads/main" sync-j="8"/>27  <project remote="cros-internal" name="foo" path="foo/" revision="123" />28  <project remote="cros" name="bar" path="bar/" revision="456" />29  <project name="baz" path="baz/" revision="789" />30</manifest>`31	internalManifestXMLNoAnnotations = `<?xml version="1.0" encoding="UTF-8"?>32<manifest>33  <remote name="cros" fetch="https://chromium.googlesource.com"/>34  <remote name="cros-internal" fetch="https://chrome-internal.googlesource.com"/>35  <default remote="cros" revision="refs/heads/main" sync-j="8"/>36  <project remote="cros-internal" name="foo" path="foo/" revision="123" />37  <project remote="cros" name="bar" path="bar/" revision="456" />38  <project name="baz" path="baz/" revision="789" />39</manifest>`40	internalManifestXMLDumped = `<?xml version="1.0" encoding="UTF-8"?>41<manifest>42  <remote fetch="https://chromium.googlesource.com" name="cros">43    <annotation name="public" value="true"></annotation>44  </remote>45  <remote fetch="https://chrome-internal.googlesource.com" name="cros-internal">46    <annotation name="public" value="false"></annotation>47  </remote>48  <default remote="cros" revision="refs/heads/main" sync-j="8"></default>49  <project path="foo/" name="foo" revision="123" remote="cros-internal"></project>50  <project path="bar/" name="bar" revision="456" remote="cros"></project>51  <project path="baz/" name="baz" revision="789"></project>52</manifest>`53	externalManifestXML = `<?xml version="1.0" encoding="UTF-8"?>54<manifest>55  <remote fetch="https://chromium.googlesource.com" name="cros">56    <annotation name="public" value="true"></annotation>57  </remote>58  <default remote="cros" revision="refs/heads/main" sync-j="8"></default>59  <project path="bar/" name="bar" revision="456" remote="cros"></project>60  <project path="baz/" name="baz" revision="789"></project>61</manifest>`62)63func TestPublicBuildspec(t *testing.T) {64	t.Parallel()65	expectedLists := map[string]map[string][]string{66		"chromeos-manifest-versions": {67			"test/": {"test/foo.xml"},68		},69		"chromiumos-manifest-versions": {70			"test/": {},71		},72	}73	expectedReads := map[string][]byte{74		"gs://chromeos-manifest-versions/test/foo.xml": []byte(internalManifestXML),75	}76	expectedWrites := map[string][]byte{77		"gs://chromiumos-manifest-versions/test/foo.xml": []byte(externalManifestXML),78	}79	f := &gs.FakeClient{80		T:              t,81		ExpectedLists:  expectedLists,82		ExpectedReads:  expectedReads,83		ExpectedWrites: expectedWrites,84	}85	b := publicBuildspec{86		push:                       true,87		watchPaths:                 []string{"test/"},88		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,89		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,90	}91	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, nil))92}93func TestPublicBuildspecDryRun(t *testing.T) {94	t.Parallel()95	expectedLists := map[string]map[string][]string{96		"chromeos-manifest-versions": {97			"test/": {"test/foo.xml"},98		},99		"chromiumos-manifest-versions": {100			"test/": {},101		},102	}103	expectedReads := map[string][]byte{104		"gs://chromeos-manifest-versions/test/foo.xml": []byte(internalManifestXML),105	}106	f := &gs.FakeClient{107		T:              t,108		ExpectedLists:  expectedLists,109		ExpectedReads:  expectedReads,110		ExpectedWrites: map[string][]byte{},111	}112	b := publicBuildspec{113		push:                       false,114		watchPaths:                 []string{"test/"},115		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,116		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,117	}118	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, nil))119}120func TestPublicBuildspecNoAnnotations(t *testing.T) {121	t.Parallel()122	expectedLists := map[string]map[string][]string{123		"chromeos-manifest-versions": {124			"test/": {"test/foo.xml"},125		},126		"chromiumos-manifest-versions": {127			"test/": {},128		},129	}130	expectedReads := map[string][]byte{131		"gs://chromeos-manifest-versions/test/foo.xml": []byte(internalManifestXMLNoAnnotations),132	}133	expectedWrites := map[string][]byte{134		"gs://chromiumos-manifest-versions/test/foo.xml": []byte(externalManifestXML),135	}136	f := &gs.FakeClient{137		T:              t,138		ExpectedLists:  expectedLists,139		ExpectedReads:  expectedReads,140		ExpectedWrites: expectedWrites,141	}142	// Mock Gitiles controller143	ctl := gomock.NewController(t)144	t.Cleanup(ctl.Finish)145	gitilesMock := mock_gitiles.NewMockGitilesClient(ctl)146	reqLocalManifest := &gitilespb.DownloadFileRequest{147		Project:    "chromeos/manifest-internal",148		Path:       "default.xml",149		Committish: "HEAD",150	}151	gitilesMock.EXPECT().DownloadFile(gomock.Any(), gerrit.DownloadFileRequestEq(reqLocalManifest)).Return(152		&gitilespb.DownloadFileResponse{153			Contents: internalManifestXML,154		},155		nil,156	)157	mockMap := map[string]gitilespb.GitilesClient{158		chromeInternalHost: gitilesMock,159	}160	gc := gerrit.NewTestClient(mockMap)161	b := publicBuildspec{162		push:                       true,163		watchPaths:                 []string{"test/"},164		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,165		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,166	}167	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, gc))168}169func TestPublicBuildspecNoAnnotations_missingAtToT(t *testing.T) {170	t.Parallel()171	expectedLists := map[string]map[string][]string{172		"chromeos-manifest-versions": {173			"test/": {"test/foo.xml"},174		},175		"chromiumos-manifest-versions": {176			"test/": {},177		},178	}179	expectedReads := map[string][]byte{180		"gs://chromeos-manifest-versions/test/foo.xml": []byte(internalManifestXMLNoAnnotations),181	}182	f := &gs.FakeClient{183		T:             t,184		ExpectedLists: expectedLists,185		ExpectedReads: expectedReads,186	}187	// Mock Gitiles controller188	ctl := gomock.NewController(t)189	t.Cleanup(ctl.Finish)190	gitilesMock := mock_gitiles.NewMockGitilesClient(ctl)191	reqLocalManifest := &gitilespb.DownloadFileRequest{192		Project:    "chromeos/manifest-internal",193		Path:       "default.xml",194		Committish: "HEAD",195	}196	gitilesMock.EXPECT().DownloadFile(gomock.Any(), gerrit.DownloadFileRequestEq(reqLocalManifest)).Return(197		&gitilespb.DownloadFileResponse{198			Contents: internalManifestXMLNoAnnotations,199		},200		nil,201	)202	mockMap := map[string]gitilespb.GitilesClient{203		chromeInternalHost: gitilesMock,204	}205	gc := gerrit.NewTestClient(mockMap)206	b := publicBuildspec{207		push:                       true,208		watchPaths:                 []string{"test/"},209		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,210		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,211	}212	assert.ErrorContains(t, b.CreatePublicBuildspecs(context.Background(), f, gc), "could not get public status")213}214func legacyTest(t *testing.T, externalList []string, externalDownloads map[string]string,215	expectedGSWrites map[string][]byte) (*gs.FakeClient, gerrit.Client) {216	t.Helper()217	contents := internalManifestXML218	expectedDownloads := map[gerrit.ExpectedPathParams]*string{219		{220			Host:    chromeInternalHost,221			Project: "chromeos/manifest-versions",222			Path:    "test/foo.xml",223			Ref:     "HEAD",224		}: &contents,225	}226	if externalDownloads != nil {227		for path, contents := range externalDownloads {228			expectedDownloads[gerrit.ExpectedPathParams{229				Host:    chromeExternalHost,230				Project: "chromiumos/manifest-versions",231				Path:    path,232				Ref:     "HEAD",233			}] = &contents234		}235	}236	if externalList == nil {237		externalList = []string{}238	}239	gc := &gerrit.MockClient{240		T: t,241		ExpectedLists: map[gerrit.ExpectedPathParams][]string{242			{243				Host:    chromeInternalHost,244				Project: "chromeos/manifest-versions",245				Path:    "test/",246				Ref:     "HEAD",247			}: {"foo.xml"},248			{249				Host:    chromeExternalHost,250				Project: "chromiumos/manifest-versions",251				Path:    "test/",252				Ref:     "HEAD",253			}: externalList,254		},255		ExpectedDownloads: expectedDownloads,256		ExpectedFileLogs: map[gerrit.ExpectedPathParams][]gerrit.Commit{257			{258				Host:    chromeInternalHost,259				Project: "chromeos/manifest-versions",260				Ref:     "HEAD",261				Path:    "test/foo.xml",262			}: {263				{264					Committer: gerrit.User{265						Name:  "Jack Neus",266						Email: "jackneus@google.com",267						Time:  "Wed Mar 16 11:17:10 2022",268					},269				},270			},271		},272	}273	expectedLists := map[string]map[string][]string{274		"chromiumos-manifest-versions": {275			"test/": {},276		},277	}278	expectedWrites := map[string][]byte{279		"gs://chromeos-manifest-versions/test/foo.xml":   []byte(internalManifestXMLDumped),280		"gs://chromiumos-manifest-versions/test/foo.xml": []byte(externalManifestXML),281	}282	if expectedGSWrites != nil {283		expectedWrites = expectedGSWrites284	}285	expectedMetadata := map[string]map[string]string{286		"gs://chromeos-manifest-versions/test/foo.xml": {287			"create_time_seconds": "1647429430",288		},289		"gs://chromiumos-manifest-versions/test/foo.xml": {290			"create_time_seconds": "1647429430",291		},292	}293	f := &gs.FakeClient{294		T:                t,295		ExpectedLists:    expectedLists,296		ExpectedWrites:   expectedWrites,297		ExpectedMetadata: expectedMetadata,298	}299	return f, gc300}301func TestPublicBuildspecLegacy(t *testing.T) {302	t.Parallel()303	f, gc := legacyTest(t, nil, nil, nil)304	b := publicBuildspec{305		push:                       true,306		watchPaths:                 []string{"test/"},307		readFromManifestVersions:   true,308		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,309		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,310	}311	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, gc))312}313// Check that dry run doesn't upload anything.314func TestPublicBuildspecLegacy_DryRun(t *testing.T) {315	t.Parallel()316	expectedGSWrites := map[string][]byte{}317	f, gc := legacyTest(t, nil, nil, expectedGSWrites)318	b := publicBuildspec{319		push:                       false,320		watchPaths:                 []string{"test/"},321		readFromManifestVersions:   true,322		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,323		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,324	}325	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, gc))326}327// When we're reading from legacy (git) and the public buildspec already328// exists in the public manifest-versions repository, we should use that329// file instead of generating a new one.330func TestPublicBuildspecLegacy_ExternalExists(t *testing.T) {331	t.Parallel()332	externalList := []string{"foo.xml"}333	expectedExternalDownloads := map[string]string{334		"test/foo.xml": "foo",335	}336	expectedGSWrites := map[string][]byte{337		"gs://chromeos-manifest-versions/test/foo.xml":   []byte(internalManifestXMLDumped),338		"gs://chromiumos-manifest-versions/test/foo.xml": []byte("foo"),339	}340	f, gc := legacyTest(t, externalList, expectedExternalDownloads, expectedGSWrites)341	b := publicBuildspec{342		push:                       true,343		watchPaths:                 []string{"test/"},344		readFromManifestVersions:   true,345		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,346		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,347	}348	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, gc))349}350// Check that dry run doesn't upload anything.351func TestPublicBuildspecLegacy_ExternalExists_DryRun(t *testing.T) {352	t.Parallel()353	externalList := []string{"foo.xml"}354	expectedExternalDownloads := map[string]string{355		"test/foo.xml": "foo",356	}357	expectedGSWrites := map[string][]byte{}358	f, gc := legacyTest(t, externalList, expectedExternalDownloads, expectedGSWrites)359	b := publicBuildspec{360		push:                       false,361		watchPaths:                 []string{"test/"},362		readFromManifestVersions:   true,363		internalBuildspecsGSBucket: internalBuildspecsGSBucketDefault,364		externalBuildspecsGSBucket: externalBuildspecsGSBucketDefault,365	}366	assert.NilError(t, b.CreatePublicBuildspecs(context.Background(), f, gc))367}...

Full Screen

Full Screen

build_command.go

Source:build_command.go Github

copy

Full Screen

1package main2import (3	"flag"4	"fmt"5	"os"6	"path/filepath"7	"github.com/cloudfoundry-incubator/stemcell-tracker/vendor/_nuts/github.com/onsi/ginkgo/ginkgo/interrupthandler"8	"github.com/cloudfoundry-incubator/stemcell-tracker/vendor/_nuts/github.com/onsi/ginkgo/ginkgo/testrunner"9)10func BuildBuildCommand() *Command {11	commandFlags := NewBuildCommandFlags(flag.NewFlagSet("build", flag.ExitOnError))12	interruptHandler := interrupthandler.NewInterruptHandler()13	builder := &SpecBuilder{14		commandFlags:     commandFlags,15		interruptHandler: interruptHandler,16	}17	return &Command{18		Name:         "build",19		FlagSet:      commandFlags.FlagSet,20		UsageCommand: "ginkgo build <FLAGS> <PACKAGES>",21		Usage: []string{22			"Build the passed in <PACKAGES> (or the package in the current directory if left blank).",23			"Accepts the following flags:",24		},25		Command: builder.BuildSpecs,26	}27}28type SpecBuilder struct {29	commandFlags     *RunWatchAndBuildCommandFlags30	interruptHandler *interrupthandler.InterruptHandler31}32func (r *SpecBuilder) BuildSpecs(args []string, additionalArgs []string) {33	r.commandFlags.computeNodes()34	suites, _ := findSuites(args, r.commandFlags.Recurse, r.commandFlags.SkipPackage, false)35	if len(suites) == 0 {36		complainAndQuit("Found no test suites")37	}38	passed := true39	for _, suite := range suites {40		runner := testrunner.New(suite, 1, false, r.commandFlags.Race, r.commandFlags.Cover, r.commandFlags.CoverPkg, r.commandFlags.Tags, nil)41		fmt.Printf("Compiling %s...\n", suite.PackageName)42		path, _ := filepath.Abs(filepath.Join(suite.Path, fmt.Sprintf("%s.test", suite.PackageName)))43		err := runner.CompileTo(path)44		if err != nil {45			fmt.Println(err.Error())46			passed = false47		} else {48			fmt.Printf("    compiled %s.test\n", suite.PackageName)49		}50		runner.CleanUp()51	}52	if passed {53		os.Exit(0)54	}55	os.Exit(1)56}...

Full Screen

Full Screen

buildSpecs

Using AI Code Generation

copy

Full Screen

1import java.io.File;2public class BuildSpecsTest {3    public static void main(String[] args) {4        Build build = new Build("1.go");5        System.out.println(build.buildSpecs());6    }7}8import java.io.File;9public class BuildSpecsTest {10    public static void main(String[] args) {11        Build build = new Build("2.go");12        System.out.println(build.buildSpecs());13    }14}15import java.io.File;16public class BuildSpecsTest {17    public static void main(String[] args) {18        Build build = new Build("1.go");19        System.out.println(build.buildSpecs());20    }21}22import java.io.File;23public class BuildSpecsTest {24    public static void main(String[] args) {25        Build build = new Build("2.go");26        System.out.println(build.buildSpecs());27    }28}29import java.io.File;30public class BuildSpecsTest {31    public static void main(String[] args) {32        Build build = new Build("1.go");33        System.out.println(build.buildSpecs());34    }35}36import java.io.File;37public class BuildSpecsTest {38    public static void main(String[] args) {39        Build build = new Build("2.go");40        System.out.println(build.buildSpecs());41    }42}43import java.io.File;44public class BuildSpecsTest {45    public static void main(String[] args) {46        Build build = new Build("1.go");47        System.out.println(build.buildSpecs());48    }49}50import java.io.File;51public class BuildSpecsTest {52    public static void main(String[] args) {53        Build build = new Build("2.go");54        System.out.println(build.buildSpecs());55    }56}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful