xref: /aosp_15_r20/build/soong/provenance/provenance_singleton_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker/*
2*333d2b36SAndroid Build Coastguard Worker * Copyright (C) 2022 The Android Open Source Project
3*333d2b36SAndroid Build Coastguard Worker *
4*333d2b36SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*333d2b36SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*333d2b36SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*333d2b36SAndroid Build Coastguard Worker *
8*333d2b36SAndroid Build Coastguard Worker *      http://www.apache.org/licenses/LICENSE-2.0
9*333d2b36SAndroid Build Coastguard Worker *
10*333d2b36SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*333d2b36SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*333d2b36SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*333d2b36SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*333d2b36SAndroid Build Coastguard Worker * limitations under the License.
15*333d2b36SAndroid Build Coastguard Worker */
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerpackage provenance
18*333d2b36SAndroid Build Coastguard Worker
19*333d2b36SAndroid Build Coastguard Workerimport (
20*333d2b36SAndroid Build Coastguard Worker	"strings"
21*333d2b36SAndroid Build Coastguard Worker	"testing"
22*333d2b36SAndroid Build Coastguard Worker
23*333d2b36SAndroid Build Coastguard Worker	"android/soong/android"
24*333d2b36SAndroid Build Coastguard Worker)
25*333d2b36SAndroid Build Coastguard Worker
26*333d2b36SAndroid Build Coastguard Workerfunc TestProvenanceSingleton(t *testing.T) {
27*333d2b36SAndroid Build Coastguard Worker	result := android.GroupFixturePreparers(
28*333d2b36SAndroid Build Coastguard Worker		PrepareForTestWithProvenanceSingleton,
29*333d2b36SAndroid Build Coastguard Worker		android.PrepareForTestWithAndroidMk).RunTestWithBp(t, "")
30*333d2b36SAndroid Build Coastguard Worker
31*333d2b36SAndroid Build Coastguard Worker	outputs := result.SingletonForTests("provenance_metadata_singleton").AllOutputs()
32*333d2b36SAndroid Build Coastguard Worker	for _, output := range outputs {
33*333d2b36SAndroid Build Coastguard Worker		testingBuildParam := result.SingletonForTests("provenance_metadata_singleton").Output(output)
34*333d2b36SAndroid Build Coastguard Worker		switch {
35*333d2b36SAndroid Build Coastguard Worker		case strings.Contains(output, "soong/provenance_metadata.textproto"):
36*333d2b36SAndroid Build Coastguard Worker			android.AssertStringEquals(t, "Invalid build rule", "android/soong/provenance.mergeProvenanceMetaData", testingBuildParam.Rule.String())
37*333d2b36SAndroid Build Coastguard Worker			android.AssertIntEquals(t, "Invalid input", len(testingBuildParam.Inputs), 0)
38*333d2b36SAndroid Build Coastguard Worker			android.AssertStringDoesContain(t, "Invalid output path", output, "soong/provenance_metadata.textproto")
39*333d2b36SAndroid Build Coastguard Worker			android.AssertIntEquals(t, "Invalid args", len(testingBuildParam.Args), 0)
40*333d2b36SAndroid Build Coastguard Worker
41*333d2b36SAndroid Build Coastguard Worker		case strings.HasSuffix(output, "provenance_metadata"):
42*333d2b36SAndroid Build Coastguard Worker			android.AssertStringEquals(t, "Invalid build rule", "<builtin>:phony", testingBuildParam.Rule.String())
43*333d2b36SAndroid Build Coastguard Worker			android.AssertStringEquals(t, "Invalid input", testingBuildParam.Inputs[0].String(), "out/soong/provenance_metadata.textproto")
44*333d2b36SAndroid Build Coastguard Worker			android.AssertStringEquals(t, "Invalid output path", output, "provenance_metadata")
45*333d2b36SAndroid Build Coastguard Worker			android.AssertIntEquals(t, "Invalid args", len(testingBuildParam.Args), 0)
46*333d2b36SAndroid Build Coastguard Worker		}
47*333d2b36SAndroid Build Coastguard Worker	}
48*333d2b36SAndroid Build Coastguard Worker}
49