github.com/paketoio/libpak@v1.3.1/sherpa/resolve_version_test.go (about) 1 /* 2 * Copyright 2018-2020 the original author or 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 * https://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 sherpa_test 18 19 import ( 20 "os" 21 "testing" 22 23 "github.com/buildpacks/libcnb" 24 . "github.com/onsi/gomega" 25 "github.com/paketoio/libpak/sherpa" 26 "github.com/sclevine/spec" 27 ) 28 29 func testResolveVersion(t *testing.T, context spec.G, it spec.S) { 30 var ( 31 Expect = NewWithT(t).Expect 32 ) 33 34 context("Environment Variable", func() { 35 it.Before(func() { 36 Expect(os.Setenv("TEST_ENV_VAR_KEY", "test-env-var-value")) 37 }) 38 39 it.After(func() { 40 Expect(os.Unsetenv("TEST_ENV_VAR_KEY")) 41 }) 42 43 it("chooses environment variable", func() { 44 v := sherpa.ResolveVersion("TEST_ENV_VAR_KEY", libcnb.BuildpackPlanEntry{}, "", nil) 45 Expect(v).To(Equal("test-env-var-value")) 46 }) 47 48 }) 49 50 it("chooses entry", func() { 51 v := sherpa.ResolveVersion("", libcnb.BuildpackPlanEntry{Version: "test-buildpack-plan-entry-value"}, "", nil) 52 Expect(v).To(Equal("test-buildpack-plan-entry-value")) 53 }) 54 55 it("chooses default version", func() { 56 v := sherpa.ResolveVersion("", libcnb.BuildpackPlanEntry{}, "test-default-versions-key", map[string]string{"test-default-versions-key": "test-default-versions-value"}) 57 Expect(v).To(Equal("test-default-versions-value")) 58 }) 59 60 it("chooses empty version", func() { 61 v := sherpa.ResolveVersion("", libcnb.BuildpackPlanEntry{}, "", map[string]string{}) 62 Expect(v).To(Equal("")) 63 }) 64 }