Skip to content

Commit

Permalink
test: add new testing for runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jia <chuanchang.jia@gmail.com>
  • Loading branch information
chuanchang committed Dec 27, 2018
1 parent 54dd513 commit 9633324
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion apis/opts/config/runtime_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"fmt"
"reflect"
"testing"

"github.com/alibaba/pouch/apis/types"
Expand All @@ -20,6 +22,95 @@ func TestNewRuntime(t *testing.T) {
} {
runtime := NewRuntime(r)
// just test no panic here
assert.NoError(runtime.Set("foo=bar"))
assert.NotEmpty(t, runtime)
}
}

func TestRuntimeSet(t *testing.T) {
type args struct {
value string
}
tests := []struct {
name string
args args
want error
wantErr bool
wantStr string
}{
{
name: "valid runtime format",
args: args{
value: "foo=bar",
},
wantErr: false,
},
{
name: "invalid runtime format",
args: args{
value: "foo=",
},
want: fmt.Errorf("invalid runtime foo=, correct format must be runtime=path"),
wantErr: true,
},
{
name: "duplicate runtime",
args: args{
value: "foo=bar",
},
want: fmt.Errorf("runtime foo already registers to daemon"),
wantErr: true,
},
}

for _, r := range []*map[string]types.Runtime{
{
"a": {},
"b": {Path: "foo"},
},
} {
runtime := NewRuntime(r)
assert.NotEmpty(t, runtime)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rt := runtime.Set(tt.args.value)
if (rt != nil) != tt.wantErr {
t.Errorf("Runtime.Set() error = %v, wantErr %v", rt, tt.wantErr)
return
}
if tt.wantErr && !reflect.DeepEqual(rt, tt.want) {
t.Errorf("Runtime.Set() = %v, want %v", rt, tt.want)
}
})
}
}
}

func TestRuntimeType(t *testing.T) {
type args struct {
val string
}
tests := []struct {
name string
args args
err error
wantErr bool
wantStr string
}{
{
name: "get type of Runtime",
wantErr: false,
wantStr: "runtime",
},
}
{
ul := &Runtime{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := ul.Type()
if !tt.wantErr && !reflect.DeepEqual(out, tt.wantStr) {
t.Errorf("Runtime.Type() = %v, want %v", out, tt.wantStr)
}
})
}
}
}

0 comments on commit 9633324

Please sign in to comment.