-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathruby_test.go
More file actions
61 lines (51 loc) · 2.1 KB
/
Copy pathruby_test.go
File metadata and controls
61 lines (51 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"os/exec"
"testing"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/stretchr/testify/assert"
)
// These tests exercise the `jf ruby <gem|bundle>` command wiring end-to-end without
// requiring a live Artifactory: help/version sub-commands bypass auth injection and
// Artifactory calls, so they validate the dispatcher, flag extraction and native exec.
func rubyToolAvailable(t *testing.T, tool string) {
if _, err := exec.LookPath(tool); err != nil {
t.Skipf("'%s' is not installed; skipping ruby command test", tool)
}
}
func TestRubyGemVersionPassthrough(t *testing.T) {
rubyToolAvailable(t, "gem")
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// `jf ruby gem --version` must pass straight through to the gem binary.
assert.NoError(t, jfrogCli.Exec("ruby", "gem", "--version"))
}
func TestRubyBundleVersionPassthrough(t *testing.T) {
rubyToolAvailable(t, "bundle")
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
assert.NoError(t, jfrogCli.Exec("ruby", "bundle", "--version"))
}
func TestRubyGemHelpPassthrough(t *testing.T) {
rubyToolAvailable(t, "gem")
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// `help` sub-command bypasses auth and must not error.
assert.NoError(t, jfrogCli.Exec("ruby", "gem", "help"))
}
func TestRubyUnsupportedToolErrors(t *testing.T) {
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// An unsupported native tool must be rejected by RubyCommand.Run.
err := jfrogCli.Exec("ruby", "npm", "install")
assert.Error(t, err)
}
func TestRubyNoArgsErrors(t *testing.T) {
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// `jf ruby` with no native tool must report a usage error, not panic.
err := jfrogCli.Exec("ruby")
assert.Error(t, err)
}
func TestRubyRepoFlagPassthrough(t *testing.T) {
rubyToolAvailable(t, "gem")
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
// --repo is consumed by jf and should not be passed to gem.
// `gem help` should still work fine with --repo being stripped.
assert.NoError(t, jfrogCli.Exec("ruby", "gem", "help", "--repo", "gems-virtual"))
}