Correct rebase issue and add e2e test

This commit is contained in:
zzxwill
2020-07-30 23:31:01 +08:00
parent e91dceac4b
commit 318f9e59ae
6 changed files with 82 additions and 10 deletions
+3 -1
View File
@@ -28,4 +28,6 @@ bin
vendor/
# Vscode files
.vscode
.vscode
pkg/test/rudr
+6
View File
@@ -64,5 +64,11 @@ workloaddefinition.core.oam.dev/deployments.apps deployment
workloaddefinition.core.oam.dev/statefulsets.apps statefulsets.apps
```
## Test
```
$ go test ./pkg/test
ok github.com/cloud-native-application/rudrx/pkg/test 14.662s
```
## Make a pull request
Remember to write unit-test and e2e test before making a pull request.
+1 -1
View File
@@ -84,7 +84,7 @@ func newCommand() *cobra.Command {
cmds.AddCommand(
cmd.NewRunCommand(f, client, ioStream, os.Args[1:]),
cmd.NewTraitsCommand(f, client, ioStream),
cmd.NewWorkloadsCommand(f, client, ioStream, args),
cmd.NewWorkloadsCommand(f, client, ioStream, os.Args[1:]),
cmd.NewBindCommand(f, client, ioStream),
cmd.NewInitCommand(f, client, ioStream),
cmd.NewDeleteCommand(f, client, ioStream, os.Args[1:]),
+7 -6
View File
@@ -32,21 +32,22 @@ func NewTraitsCommand(f cmdutil.Factory, c client.Client, ioStreams cmdutil.IOSt
}
func printTraitList(ctx context.Context, c client.Client, workloadName *string, ioStreams cmdutil.IOStreams) error {
traitList, err := RetrieveTraitsByWorkload(ctx, c, *workloadName)
traitList, err := RetrieveTraitsByWorkload(ctx, c, "", *workloadName)
table := uitable.New()
table.MaxColWidth = 60
//if err != nil {
// errMsg := fmt.Sprintf("Listing Trait Definition hit an issue: %s", err)
// cmdutil.PrintErrorMessage(errMsg, 1)
//}
if err != nil {
return fmt.Errorf("Listing Trait Definition hit an issue: %s", err)
}
table.AddRow("NAME", "Alias", "DEFINITION", "APPLIES TO", "STATUS")
for _, r := range traitList {
table.AddRow(r.Name, r.Short, r.Definition, r.AppliesTo, r.Status)
}
fmt.Print(table.String())
ioStreams.Info(table.String())
return nil
}
type TraitMeta struct {
+2 -2
View File
@@ -32,7 +32,7 @@ type Template struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Alias string `json:alias,omitempty`
Object unstructured.Unstructured `json:"object"`
Object unstructured.Unstructured `json:"object,omitempty"`
LastCommandParam string `json:"lastCommandParam,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
}
@@ -48,7 +48,7 @@ type Parameter struct {
}
// ConvertTemplateJson2Object convert spec.extension to object
func ConvertTemplateJson2Object(in runtime.RawExtension) (Template, error) {
func ConvertTemplateJson2Object(in *runtime.RawExtension) (Template, error) {
var t Template
var extension Template
err := json.Unmarshal(in.Raw, &extension)
+63
View File
@@ -0,0 +1,63 @@
package test
import (
"os"
"os/exec"
"path"
"testing"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
var (
rudrPath, _ = os.Getwd()
)
func createKubernetesClient() (client.Client, error) {
c, err := client.New(config.GetConfigOrDie(), client.Options{})
return c, err
}
func TestCreateKubernetesClient(t *testing.T) {
_, err := createKubernetesClient()
if err != nil {
t.Errorf("Failed to create a Kubernetes client: %s", err)
}
}
// TestBuildCliBinary is to build rudr binary.
func TestBuildCliBinary(t *testing.T) {
rudrPath, err := os.Getwd()
mainPath := path.Join(rudrPath, "../../cmd/rudrx/main.go")
if err != nil {
t.Errorf("Failed to build rudr binary: %s", err)
}
cmd := exec.Command("go", "build", "-o", path.Join(rudrPath, "rudr"), mainPath)
stdout, err := cmd.Output()
if err != nil {
t.Errorf("Failed to build rudr binary: %s", err)
}
t.Log(stdout, err)
// TODO(zzxwill) If this failed, all other test-cases should be terminated
}
func Command(name string, arg ...string) *exec.Cmd {
commandName := path.Join(rudrPath, name)
return exec.Command(commandName, arg...)
}
func TestTraitsList(t *testing.T) {
cmd := Command("rudr", []string{"traits", "list"}...)
stdout, err := cmd.Output()
t.Log(string(stdout), err)
if err != nil {
t.Errorf("Failed to list traits: %s", err)
}
}