github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/apps/distgo/pkg/osarch/osarch_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 osarch_test 16 17 import ( 18 "runtime" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/stretchr/testify/require" 23 24 "github.com/palantir/godel/apps/distgo/pkg/osarch" 25 ) 26 27 func TestOSArchNew(t *testing.T) { 28 for i, currCase := range []struct { 29 input string 30 want osarch.OSArch 31 wantError bool 32 }{ 33 {input: "darwin-amd64", want: osarch.OSArch{OS: "darwin", Arch: "amd64"}}, 34 {input: "foo-bar", want: osarch.OSArch{OS: "foo", Arch: "bar"}}, 35 {input: "foo-bar-baz", wantError: true}, 36 {input: "foo", wantError: true}, 37 {input: "foo-", wantError: true}, 38 {input: "-bar", wantError: true}, 39 {input: "foo-b@r", wantError: true}, 40 {input: "f?o-bar", wantError: true}, 41 {input: "", wantError: true}, 42 } { 43 got, err := osarch.New(currCase.input) 44 if currCase.wantError { 45 assert.EqualError(t, err, "not a valid OSArch value: "+currCase.input, "Case %d", i) 46 } else { 47 require.NoError(t, err, "Case %d", i) 48 assert.Equal(t, currCase.want, got, "Case %d", i) 49 } 50 } 51 } 52 53 func TestOSArchCurrent(t *testing.T) { 54 want := osarch.OSArch{OS: runtime.GOOS, Arch: runtime.GOARCH} 55 assert.Equal(t, want, osarch.Current()) 56 }