github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/jib/jvm_test.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package jib 18 19 import ( 20 "context" 21 "errors" 22 "os" 23 "testing" 24 25 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" 26 "github.com/GoogleContainerTools/skaffold/testutil" 27 ) 28 29 func TestMain(m *testing.M) { 30 // these tests don't actually require a JVM 31 JVMFound = func(context.Context) bool { return true } 32 os.Exit(m.Run()) 33 } 34 35 func TestResolveJVM(t *testing.T) { 36 tests := []struct { 37 name string 38 cmd *testutil.FakeCmd 39 expected bool 40 }{ 41 {name: "found", cmd: testutil.CmdRun("java -version"), expected: true}, 42 {name: "not found", cmd: testutil.CmdRunErr("java -version", errors.New("not found")), expected: false}, 43 } 44 for _, test := range tests { 45 testutil.Run(t, test.name, func(t *testutil.T) { 46 t.Override(&util.DefaultExecCommand, test.cmd) 47 48 result := resolveJVM(context.Background()) 49 t.CheckDeepEqual(test.expected, result) 50 }) 51 } 52 }