blob: 30e891ced5ac1248282074a5b0d61161a791c080 [file] [log] [blame]
Ramy Medhat9a90fe52020-04-13 13:21:23 -04001// Copyright 2020 Google Inc. All rights reserved.
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
15package remoteexec
16
17import (
18 "fmt"
19 "testing"
20)
21
22func TestTemplate(t *testing.T) {
23 tests := []struct {
24 name string
25 params *REParams
26 want string
27 }{
28 {
29 name: "basic",
30 params: &REParams{
31 Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
32 Inputs: []string{"$in"},
33 OutputFiles: []string{"$out"},
34 Platform: map[string]string{
35 ContainerImageKey: DefaultImage,
36 PoolKey: "default",
37 },
38 },
39 want: fmt.Sprintf("${remoteexec.Wrapper} --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=local --inputs=$in --output_files=$out -- ", DefaultImage),
40 },
41 {
42 name: "all params",
43 params: &REParams{
44 Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
45 Inputs: []string{"$in"},
46 OutputFiles: []string{"$out"},
47 ExecStrategy: "remote",
48 RSPFile: "$out.rsp",
49 ToolchainInputs: []string{"clang++"},
50 Platform: map[string]string{
51 ContainerImageKey: DefaultImage,
52 PoolKey: "default",
53 },
54 },
55 want: fmt.Sprintf("${remoteexec.Wrapper} --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=remote --inputs=$in --input_list_paths=$out.rsp --output_files=$out --toolchain_inputs=clang++ -- ", DefaultImage),
56 },
57 }
58 for _, test := range tests {
59 t.Run(test.name, func(t *testing.T) {
60 if got := test.params.Template(); got != test.want {
61 t.Errorf("Template() returned\n%s\nwant\n%s", got, test.want)
62 }
63 })
64 }
65}
66
67func TestTemplateDeterminism(t *testing.T) {
68 r := &REParams{
69 Labels: map[string]string{"type": "compile", "lang": "cpp", "compiler": "clang"},
70 Inputs: []string{"$in"},
71 OutputFiles: []string{"$out"},
72 Platform: map[string]string{
73 ContainerImageKey: DefaultImage,
74 PoolKey: "default",
75 },
76 }
77 want := fmt.Sprintf("${remoteexec.Wrapper} --labels=compiler=clang,lang=cpp,type=compile --platform=\"Pool=default,container-image=%s\" --exec_strategy=local --inputs=$in --output_files=$out -- ", DefaultImage)
78 for i := 0; i < 1000; i++ {
79 if got := r.Template(); got != want {
80 t.Fatalf("Template() returned\n%s\nwant\n%s", got, want)
81 }
82 }
83}