MCPcopy
hub / github.com/cloudfoundry/cli / Init

Method Init

integration/helpers/plugin_repo.go:61–123  ·  view source on GitHub ↗

Init initializes a server to provide a single configurable_plugin with user provided name, version, and platform.

(pluginType string, pluginName string, version string, platform string, shouldCalculateChecksum bool)

Source from the content-addressed store, hash-verified

59
60// Init initializes a server to provide a single configurable_plugin with user provided name, version, and platform.
61func (pluginRepoServer *PluginRepositoryServerWithPlugin) Init(pluginType string, pluginName string, version string, platform string, shouldCalculateChecksum bool) {
62 pluginPath := BuildConfigurablePlugin(pluginType, pluginName, version,
63 []PluginCommand{
64 {Name: "some-command", Help: "some-command-help"},
65 },
66 )
67
68 repoServer := NewServer()
69
70 pluginRepoServer.server = repoServer
71 pluginRepoServer.pluginPath = pluginPath
72
73 var (
74 checksum []byte
75 err error
76 )
77
78 if shouldCalculateChecksum {
79 checksum, err = util.NewSha1Checksum(pluginPath).ComputeFileSha1()
80 Expect(err).NotTo(HaveOccurred())
81 }
82
83 baseFile := fmt.Sprintf("/%s", generic.ExecutableFilename(filepath.Base(pluginPath)))
84 downloadURL := fmt.Sprintf("%s%s", repoServer.URL(), baseFile)
85 pluginRepo := PluginRepository{
86 Plugins: []Plugin{
87 {
88 Name: pluginName,
89 Version: version,
90 Binaries: []Binary{
91 {
92 Checksum: fmt.Sprintf("%x", checksum),
93 Platform: platform,
94 URL: downloadURL,
95 },
96 },
97 },
98 }}
99
100 // Suppresses ginkgo server logs
101 repoServer.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
102
103 jsonBytes, err := json.Marshal(pluginRepo)
104 Expect(err).ToNot(HaveOccurred())
105
106 pluginData, err := os.ReadFile(pluginPath)
107 Expect(err).ToNot(HaveOccurred())
108
109 repoServer.AppendHandlers(
110 CombineHandlers(
111 VerifyRequest(http.MethodGet, "/list"),
112 RespondWith(http.StatusOK, jsonBytes),
113 ),
114 CombineHandlers(
115 VerifyRequest(http.MethodGet, "/list"),
116 RespondWith(http.StatusOK, jsonBytes),
117 ),
118 CombineHandlers(

Callers 1

Calls 6

NewSha1ChecksumFunction · 0.92
ExecutableFilenameFunction · 0.92
BuildConfigurablePluginFunction · 0.85
NewServerFunction · 0.85
ComputeFileSha1Method · 0.65
URLMethod · 0.45

Tested by

no test coverage detected