Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: api_runtime_test: add new checkpoints #2329

Merged
merged 1 commit into from
Dec 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}
}
}