github.com/ystia/yorc/v4@v4.3.0/plugin/definitions_test.go (about) 1 // Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. 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 plugin 16 17 import ( 18 "reflect" 19 "testing" 20 21 plugin "github.com/hashicorp/go-plugin" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func createClientServer(t *testing.T, opts *ServeOpts) (*plugin.RPCClient, *plugin.RPCServer) { 26 return plugin.TestPluginRPCConn(t, getPlugins(opts), nil) 27 } 28 29 func TestDefinitionsClient_GetDefinitions(t *testing.T) { 30 t.Parallel() 31 32 tests := []struct { 33 name string 34 want map[string][]byte 35 wantErr bool 36 }{ 37 {"TestOneDefinition", map[string][]byte{"TestOne": []byte{0}}, false}, 38 {"TestThreeDefinitions", map[string][]byte{"TestOne": []byte{0}, "TestTwo": []byte{0, 1}, "TestThree": []byte{0, 1, 2}}, false}, 39 {"TestNoDefinitions", map[string][]byte{}, false}, 40 {"TestNilDefinitions", nil, false}, 41 } 42 for _, tt := range tests { 43 t.Run(tt.name, func(t *testing.T) { 44 t.Parallel() 45 c, _ := createClientServer(t, &ServeOpts{Definitions: tt.want}) 46 defer c.Close() 47 raw, err := c.Dispense(DefinitionsPluginName) 48 require.Nil(t, err) 49 def := raw.(Definitions) 50 got, err := def.GetDefinitions() 51 if (err != nil) != tt.wantErr { 52 t.Errorf("DefinitionsClient.GetDefinitions() error = %v, wantErr %v", err, tt.wantErr) 53 return 54 } 55 if !reflect.DeepEqual(got, tt.want) { 56 t.Errorf("DefinitionsClient.GetDefinitions() = %v, want %v", got, tt.want) 57 } 58 }) 59 } 60 }