From 454edc405b301dad778114c5669db618d6c0770e Mon Sep 17 00:00:00 2001
From: xiadanni1 <xiadanni1@huawei.com>
Date: Tue, 3 Mar 2020 06:29:56 +0800
Subject: [PATCH] containerd:add LLT for containerd-shim timeout requirement

reason:add LLT testcases for containerd-shim timeout requirement.

Change-Id: If422542b72f3550d86a6eba6b19d0cdea2d2a660
Signed-off-by: xiadanni1 <xiadanni1@huawei.com>
---
 .../containerd/go-runc/runc_test.go           | 90 +++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 vendor/github.com/containerd/go-runc/runc_test.go

diff --git a/vendor/github.com/containerd/go-runc/runc_test.go b/vendor/github.com/containerd/go-runc/runc_test.go
new file mode 100644
index 0000000..8f9212d
--- /dev/null
+++ b/vendor/github.com/containerd/go-runc/runc_test.go
@@ -0,0 +1,90 @@
+package runc
+
+import (
+	"context"
+	"os"
+	"os/exec"
+	"testing"
+
+	specs "github.com/opencontainers/runtime-spec/specs-go"
+)
+
+func TestRuncCommandInvoke(t *testing.T) {
+	rc := &Runc{
+		Command: "/bin/true",
+	}
+	ctx := context.Background()
+	id := "containerid"
+	bundle := "bundlepath"
+
+	createOpts := CreateOpts{}
+	err := rc.Create(ctx, id, bundle, &createOpts)
+	if err != nil {
+		t.Errorf("Create command invoke error, %v", err)
+	}
+
+	err = rc.Start(ctx, id)
+	if err != nil {
+		t.Errorf("Start command invoke error, %v", err)
+	}
+
+	execSpec := specs.Process{}
+	nullIO, _ := NewNullIO()
+	execOpts := ExecOpts{IO: nullIO}
+	err = rc.Exec(ctx, id, execSpec, &execOpts)
+	if err != nil {
+		t.Errorf("Exec command invoke error, %v", err)
+	}
+
+	execOptsnil := ExecOpts{}
+	err = rc.Exec(ctx, id, execSpec, &execOptsnil)
+	if err != nil {
+		t.Errorf("Exec command invoke error, %v", err)
+	}
+
+	killOpts := KillOpts{}
+	err = rc.Kill(ctx, id, 9, &killOpts)
+	if err != nil {
+		t.Errorf("Kill command invoke error, %v", err)
+	}
+
+	resource := specs.LinuxResources{}
+	err = rc.Update(ctx, id, &resource)
+	if err != nil {
+		t.Errorf("Update command invoke error, %v", err)
+	}
+
+	_, err = rc.State(ctx, id)
+	if err == nil {
+		t.Errorf("State command invoke should return error")
+	}
+
+	_, err = rc.Ps(ctx, id)
+	if err == nil {
+		t.Errorf("Ps command invoke should return error")
+	}
+}
+
+func TestRunOrErrorTimeout(t *testing.T) {
+	rc := &Runc{}
+
+	cmd := exec.Cmd{Path: "/bin/bash2"}
+	cmd.Stdout = os.Stdout
+	err := rc.runOrErrorTimeout(&cmd, 10)
+	if err == nil {
+		t.Errorf("runOrErrorTimeout should return error")
+	}
+
+	cmd = exec.Cmd{Path: "/usr/bin/sleep", Args: []string{"2"}}
+	cmd.Stdout = os.Stdout
+	rc.runOrErrorTimeout(&cmd, 1)
+	if err == nil {
+		t.Errorf("runOrErrorTimeout should return error")
+	}
+
+	cmd = exec.Cmd{Path: "/usr/bin/sleep", Args: []string{"2"}}
+	rc.runOrErrorTimeout(&cmd, 1)
+	if err == nil {
+		t.Errorf("runOrErrorTimeout should return error")
+	}
+}
-- 
2.33.0

