| 128 | } |
| 129 | |
| 130 | func TestPluginPackageSigningFailure(t *testing.T) { |
| 131 | // Create a test plugin directory |
| 132 | tempDir := t.TempDir() |
| 133 | pluginDir := filepath.Join(tempDir, "test-plugin") |
| 134 | if err := os.MkdirAll(pluginDir, 0755); err != nil { |
| 135 | t.Fatal(err) |
| 136 | } |
| 137 | |
| 138 | // Create a plugin.yaml file |
| 139 | if err := os.WriteFile(filepath.Join(pluginDir, "plugin.yaml"), []byte(testPluginYAML), 0644); err != nil { |
| 140 | t.Fatal(err) |
| 141 | } |
| 142 | |
| 143 | // Create package options with sign flag but invalid keyring |
| 144 | o := &pluginPackageOptions{ |
| 145 | sign: true, |
| 146 | keyring: "/non/existent/keyring", // This will cause signing to fail |
| 147 | pluginPath: pluginDir, |
| 148 | destination: tempDir, |
| 149 | } |
| 150 | |
| 151 | // Run the package command |
| 152 | out := &bytes.Buffer{} |
| 153 | err := o.run(out) |
| 154 | |
| 155 | // Should get an error |
| 156 | if err == nil { |
| 157 | t.Error("expected error when signing fails, got nil") |
| 158 | } |
| 159 | |
| 160 | // Check that no tarball was created |
| 161 | tarballPath := filepath.Join(tempDir, "test-plugin.tgz") |
| 162 | if _, err := os.Stat(tarballPath); !os.IsNotExist(err) { |
| 163 | t.Error("tarball should not exist when signing fails") |
| 164 | } |
| 165 | |
| 166 | // Output should not contain success message |
| 167 | if bytes.Contains(out.Bytes(), []byte("Successfully packaged")) { |
| 168 | t.Error("should not print success message when signing fails") |
| 169 | } |
| 170 | } |