github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/resource/deploy/deploytest/languageruntime.go (about) 1 // Copyright 2016-2018, Pulumi Corporation. 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 deploytest 16 17 import ( 18 "context" 19 20 "github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin" 21 "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" 22 "github.com/pulumi/pulumi/sdk/v3/go/common/workspace" 23 ) 24 25 type ProgramFunc func(runInfo plugin.RunInfo, monitor *ResourceMonitor) error 26 27 func NewLanguageRuntime(program ProgramFunc, requiredPlugins ...workspace.PluginSpec) plugin.LanguageRuntime { 28 return &languageRuntime{ 29 requiredPlugins: requiredPlugins, 30 program: program, 31 } 32 } 33 34 type languageRuntime struct { 35 requiredPlugins []workspace.PluginSpec 36 program ProgramFunc 37 } 38 39 func (p *languageRuntime) Close() error { 40 return nil 41 } 42 43 func (p *languageRuntime) GetRequiredPlugins(info plugin.ProgInfo) ([]workspace.PluginSpec, error) { 44 return p.requiredPlugins, nil 45 } 46 47 func (p *languageRuntime) Run(info plugin.RunInfo) (string, bool, error) { 48 monitor, err := dialMonitor(context.Background(), info.MonitorAddress) 49 if err != nil { 50 return "", false, err 51 } 52 defer contract.IgnoreClose(monitor) 53 54 // Run the program. 55 done := make(chan error) 56 go func() { 57 done <- p.program(info, monitor) 58 }() 59 if progerr := <-done; progerr != nil { 60 return progerr.Error(), false, nil 61 } 62 return "", false, nil 63 } 64 65 func (p *languageRuntime) GetPluginInfo() (workspace.PluginInfo, error) { 66 return workspace.PluginInfo{Name: "TestLanguage"}, nil 67 } 68 69 func (p *languageRuntime) InstallDependencies(directory string) error { 70 return nil 71 } 72 73 func (p *languageRuntime) About() (plugin.AboutInfo, error) { 74 return plugin.AboutInfo{}, nil 75 } 76 77 func (p *languageRuntime) GetProgramDependencies( 78 info plugin.ProgInfo, transitiveDependencies bool) ([]plugin.DependencyInfo, error) { 79 return nil, nil 80 }