github.com/splunk/qbec@v0.15.2/vm/internal/ds/factory/datasource_test.go (about) 1 /* 2 Copyright 2021 Splunk Inc. 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 factory 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestDataSourceSuccess(t *testing.T) { 27 ds, err := Create("exec://foo?configVar=bar") 28 require.NoError(t, err) 29 assert.IsType(t, &lazySource{}, ds) 30 } 31 32 func TestNegativeCases(t *testing.T) { 33 tests := []struct { 34 name string 35 uri string 36 msg string 37 }{ 38 { 39 name: "bad-url", 40 uri: "exec://bar\x00?configVar=test", 41 msg: "parse URL", 42 }, 43 { 44 name: "bad-kind", 45 uri: "exec-foo://bar?configVar=test", 46 msg: "unsupported scheme 'exec-foo", 47 }, 48 { 49 name: "no-name", 50 uri: "exec://?configVar=test", 51 msg: "does not have a name", 52 }, 53 { 54 name: "forgot-slash", 55 uri: "exec:foobar?configVar=test", 56 msg: "did you forget the '//' after the ':'", 57 }, 58 { 59 name: "no-cfg-var", 60 uri: "exec://foo?config=test", 61 msg: "must have a configVar param", 62 }, 63 } 64 for _, test := range tests { 65 t.Run(test.name, func(t *testing.T) { 66 _, err := Create(test.uri) 67 require.Error(t, err) 68 assert.Contains(t, err.Error(), test.msg) 69 }) 70 } 71 }