Skip to content

Commit c8e9cd3

Browse files
committed
Install kubectl to the github action
1 parent 316a427 commit c8e9cd3

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ RUN apk add --no-cache \
3333
COPY entrypoint.sh /entrypoint.sh
3434
COPY --from=builder /workspace/atest /usr/bin/atest
3535
COPY --from=hd /usr/local/bin/hd /usr/local/bin/hd
36+
RUN hd i kubernetes-sigs/kubectl
3637

3738
ENTRYPOINT ["/entrypoint.sh"]

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build:
2+
mkdir -p bin
3+
go build -o bin/atest cmd/*.go
4+
5+
copy: build
6+
cp bin/atest /usr/local/bin/

cmd/root.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/linuxsuren/api-testing/pkg/testing"
66
"github.com/spf13/cobra"
77
"os"
8+
"path"
89
"path/filepath"
910
)
1011

@@ -42,10 +43,20 @@ func (o *option) runE(cmd *cobra.Command, args []string) (err error) {
4243
return
4344
}
4445

46+
setRelativeDir(item, testcase)
47+
4548
if err = runner.RunTestCase(testcase); err != nil {
4649
return
4750
}
4851
}
4952
}
5053
return
5154
}
55+
56+
func setRelativeDir(configFile string, testcase *testing.TestCase) {
57+
dir := filepath.Dir(configFile)
58+
59+
for i := range testcase.Prepare.Kubernetes {
60+
testcase.Prepare.Kubernetes[i] = path.Join(dir, testcase.Prepare.Kubernetes[i])
61+
}
62+
}

cmd/root_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
import atesting "github.com/linuxsuren/api-testing/pkg/testing"
8+
9+
func Test_setRelativeDir(t *testing.T) {
10+
type args struct {
11+
configFile string
12+
testcase *atesting.TestCase
13+
}
14+
tests := []struct {
15+
name string
16+
args args
17+
verify func(*testing.T, *atesting.TestCase)
18+
}{{
19+
name: "normal",
20+
args: args{
21+
configFile: "a/b/c.yaml",
22+
testcase: &atesting.TestCase{
23+
Prepare: atesting.Prepare{
24+
Kubernetes: []string{"deploy.yaml"},
25+
},
26+
},
27+
},
28+
verify: func(t *testing.T, testCase *atesting.TestCase) {
29+
assert.Equal(t, "a/b/deploy.yaml", testCase.Prepare.Kubernetes[0])
30+
},
31+
}}
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
setRelativeDir(tt.args.configFile, tt.args.testcase)
35+
tt.verify(t, tt.args.testcase)
36+
})
37+
}
38+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ go 1.17
55
require (
66
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
77
github.com/spf13/cobra v1.4.0
8+
github.com/stretchr/testify v1.4.0
89
gopkg.in/yaml.v2 v2.4.0
910
)
1011

1112
require (
13+
github.com/davecgh/go-spew v1.1.1 // indirect
1214
github.com/inconshreveable/mousetrap v1.0.0 // indirect
15+
github.com/pmezard/go-difflib v1.0.0 // indirect
1316
github.com/sergi/go-diff v1.2.0 // indirect
1417
github.com/spf13/pflag v1.0.5 // indirect
1518
)

0 commit comments

Comments
 (0)