-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_test.go
More file actions
138 lines (131 loc) · 3.24 KB
/
plugin_test.go
File metadata and controls
138 lines (131 loc) · 3.24 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"os"
"reflect"
"testing"
)
func TestPlugin_generateArgs(t *testing.T) {
tests := []struct {
name string
plugin Plugin
expected []string
}{
{
name: "basic configuration",
plugin: Plugin{
Token: "test-token",
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t)},
},
{
name: "with name",
plugin: Plugin{
Token: "test-token",
Name: "test-name",
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--name", "test-name"},
},
{
name: "with flags",
plugin: Plugin{
Token: "test-token",
Flags: []string{"flag1", "flag2"},
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--flags", "flag1,flag2"},
},
{
name: "with env",
plugin: Plugin{
Token: "test-token",
Env: []string{"env1", "env2"},
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--env", "env1,env2"},
},
{
name: "with dry run",
plugin: Plugin{
Token: "test-token",
DryRun: true,
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--dryRun"},
},
{
name: "with required",
plugin: Plugin{
Token: "test-token",
Required: true,
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--nonZero"},
},
{
name: "with files",
plugin: Plugin{
Token: "test-token",
Files: []string{"file1.out", "file2.json"},
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--file", "file1.out", "--file", "file2.json"},
},
{
name: "with paths",
plugin: Plugin{
Token: "test-token",
Paths: []string{"path1", "path2"},
},
expected: []string{"-Q", "woodpecker", "--rootDir", mustGetwd(t), "--dir", "path1", "--dir", "path2"},
},
{
name: "with all options",
plugin: Plugin{
Token: "test-token",
Name: "test-name",
Flags: []string{"flag1", "flag2"},
Env: []string{"env1", "env2"},
DryRun: true,
Required: true,
Files: []string{"file1.out", "file2.json"},
Paths: []string{"path1", "path2"},
Verbose: true,
},
expected: []string{
"-Q", "woodpecker",
"--rootDir", mustGetwd(t),
"--name", "test-name",
"--flags", "flag1,flag2",
"--env", "env1,env2",
"--dryRun",
"--nonZero",
"--file", "file1.out",
"--file", "file2.json",
"--dir", "path1",
"--dir", "path2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
args := tt.plugin.generateArgs()
if !reflect.DeepEqual(args, tt.expected) {
t.Errorf("generateArgs() = %v, want %v", args, tt.expected)
}
})
}
}
func TestPlugin_command(t *testing.T) {
p := &Plugin{}
args := []string{"--arg1", "--arg2"}
cmd := p.command(args)
if cmd.Path != "/bin/codecov" {
t.Errorf("command() path = %v, want %v", cmd.Path, "/bin/codecov")
}
if !reflect.DeepEqual(cmd.Args, append([]string{"/bin/codecov"}, args...)) {
t.Errorf("command() args = %v, want %v", cmd.Args, append([]string{"/bin/codecov"}, args...))
}
}
// Helper function to get current working directory for tests
func mustGetwd(t *testing.T) string {
path, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get working directory: %v", err)
}
return path
}