github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/apps/distgo/cmd/docker/products_test.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 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 15 package docker 16 17 import ( 18 "sort" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/stretchr/testify/require" 23 24 "github.com/palantir/godel/apps/distgo/params" 25 ) 26 27 func Test_ProductsToDistAndBuild_ValidInput(t *testing.T) { 28 project := params.Project{ 29 Products: map[string]params.Product{ 30 "foo": { 31 DockerImages: []params.DockerImage{ 32 { 33 Deps: []params.DockerDep{ 34 { 35 Product: "bar", 36 Type: params.DockerDepDocker, 37 }, 38 }, 39 }, 40 }, 41 }, 42 "bar": { 43 DockerImages: []params.DockerImage{ 44 { 45 Deps: []params.DockerDep{ 46 { 47 Product: "bar", 48 Type: params.DockerDepSLS, 49 }, 50 { 51 Product: "baz", 52 Type: params.DockerDepDocker, 53 }, 54 }, 55 }, 56 }, 57 }, 58 "baz": { 59 DockerImages: []params.DockerImage{ 60 { 61 Deps: []params.DockerDep{ 62 { 63 Product: "baz", 64 Type: params.DockerDepSLS, 65 }, 66 }, 67 }, 68 }, 69 }, 70 }, 71 } 72 distProducts, imageProducts, err := productsToDistAndBuildImage([]string{"foo"}, project) 73 require.NoError(t, err) 74 sort.Strings(distProducts) 75 sort.Strings(imageProducts) 76 require.Equal(t, []string{"bar", "baz"}, distProducts) 77 require.Equal(t, []string{"bar", "baz", "foo"}, imageProducts) 78 } 79 80 func Test_ProductsToDistAndBuild_InvalidProduct(t *testing.T) { 81 project := params.Project{ 82 Products: map[string]params.Product{ 83 "abc": { 84 DockerImages: []params.DockerImage{ 85 { 86 Repository: "test-repo", 87 }, 88 }, 89 }, 90 "foo": { 91 DockerImages: []params.DockerImage{ 92 { 93 Repository: "test-repo", 94 }, 95 }, 96 }, 97 "xyz": { 98 DockerImages: []params.DockerImage{ 99 { 100 Repository: "test-repo", 101 }, 102 }, 103 }, 104 }, 105 } 106 _, _, err := productsToDistAndBuildImage([]string{"baz", "bar", "abc"}, project) 107 require.Error(t, err) 108 assert.EqualError(t, err, `Invalid products: [bar baz]. Valid products are: [abc foo xyz]`) 109 }