MCPcopy
hub / github.com/helm/helm / TestHTTPInstaller

Function TestHTTPInstaller

internal/plugin/installer/http_installer_test.go:81–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

79}
80
81func TestHTTPInstaller(t *testing.T) {
82 ensure.HelmHome(t)
83
84 srv := mockArchiveServer()
85 defer srv.Close()
86 source := srv.URL + "/plugins/fake-plugin-0.0.1.tar.gz"
87
88 if err := os.MkdirAll(helmpath.DataPath("plugins"), 0755); err != nil {
89 t.Fatalf("Could not create %s: %s", helmpath.DataPath("plugins"), err)
90 }
91
92 i, err := NewForSource(source, "0.0.1")
93 if err != nil {
94 t.Fatalf("unexpected error: %s", err)
95 }
96
97 // ensure a HTTPInstaller was returned
98 httpInstaller, ok := i.(*HTTPInstaller)
99 if !ok {
100 t.Fatal("expected a HTTPInstaller")
101 }
102
103 // inject fake http client responding with minimal plugin tarball
104 mockTgz, err := base64.StdEncoding.DecodeString(fakePluginB64)
105 if err != nil {
106 t.Fatalf("Could not decode fake tgz plugin: %s", err)
107 }
108
109 httpInstaller.getter = &TestHTTPGetter{
110 MockResponse: bytes.NewBuffer(mockTgz),
111 }
112
113 // install the plugin
114 if err := Install(i); err != nil {
115 t.Fatal(err)
116 }
117 if i.Path() != helmpath.DataPath("plugins", "fake-plugin") {
118 t.Fatalf("expected path '$XDG_CONFIG_HOME/helm/plugins/fake-plugin', got %q", i.Path())
119 }
120
121 // Install again to test plugin exists error
122 if err := Install(i); err == nil {
123 t.Fatal("expected error for plugin exists, got none")
124 } else if err.Error() != "plugin already exists" {
125 t.Fatalf("expected error for plugin exists, got (%v)", err)
126 }
127
128}
129
130func TestHTTPInstallerNonExistentVersion(t *testing.T) {
131 ensure.HelmHome(t)

Callers

nothing calls this directly

Calls 10

HelmHomeFunction · 0.92
DataPathFunction · 0.92
mockArchiveServerFunction · 0.85
NewForSourceFunction · 0.85
CloseMethod · 0.80
FatalfMethod · 0.80
FatalMethod · 0.80
InstallFunction · 0.70
PathMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…