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

Unit Test Added for DetachVolume Method #1881

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
54 changes: 53 additions & 1 deletion daemon/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/spf13/pflag"
// "fmt"
// "strings"
)

func TestIterateConfig(t *testing.T) {
Expand Down Expand Up @@ -49,7 +53,55 @@ func TestConfigValidate(t *testing.T) {
}

func TestGetConflictConfigurations(t *testing.T) {
// TODO
// 'Baiji' Group 1, Zeyu Sun
assert := assert.New(t)
// Command Line Flags
commandLineFlags := pflag.NewFlagSet("commandLineFlags", pflag.ContinueOnError)
// Adding Flags
commandLineFlags.String("f1", "1", "first String Flag")
commandLineFlags.String("f2", "", "second String Flag")
commandLineFlags.IntSlice("f3", []int{}, "slice Type Flag")

// Config File
configFileFlags := map[string]interface{}{
// "f1" : "2",
}

// commandLineFlags.Visit(func(f *pflag.Flag) {
// flagType := f.Value.Type()
// if strings.Contains(flagType, "Slice") {
// fmt.Println("SLICE")
// return
// }

// })

/* 4. If commandLineFlagsSet contains 'Slice' type */
commandLineFlags.Set("f3", "[]")
configFileFlags["f3"] = "1"
assert.Equal(nil, getConflictConfigurations(commandLineFlags, configFileFlags))

commandLineFlags.Set("f1", "2")
configFileFlags["f1"] = "2"
// fmt.Println(commandLineFlags.Lookup("f1").Value.Type())
/* 1. With Same Flag name(Same Value), Conflict */
assert.Error(getConflictConfigurations(commandLineFlags, configFileFlags))
assert.Equal(getConflictConfigurations(commandLineFlags, configFileFlags).Error(),
"found conflict flags in command line and config file: from flag: 2 and from config file: 2")

/* 2. With Same Flag name(Different Value), Conflict */
commandLineFlags.Set("f1", "1")
assert.Error(getConflictConfigurations(commandLineFlags, configFileFlags))
assert.Equal(getConflictConfigurations(commandLineFlags, configFileFlags).Error(),
"found conflict flags in command line and config file: from flag: 1 and from config file: 2")

/* 3. Two Configs's flag Intersects */
commandLineFlags.Set("f2", "0")
configFileFlags["f4"] = "3"
assert.Error(getConflictConfigurations(commandLineFlags, configFileFlags))
assert.Equal(getConflictConfigurations(commandLineFlags, configFileFlags).Error(),
"found conflict flags in command line and config file: from flag: 1 and from config file: 2")

}

func TestGetUnknownFlags(t *testing.T) {
Expand Down
35 changes: 34 additions & 1 deletion storage/volume/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,38 @@ func TestAttachVolume(t *testing.T) {
}

func TestDetachVolume(t *testing.T) {
// TODO
// Create A Volume For Test
volName0 := "vol0"
driverName := "fake_dirver"
volid0 := types.VolumeID{Name: volName0, Driver: driverName}
dir, err := ioutil.TempDir("", "TestVolumePath")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

core, err := createVolumeCore(dir)
if err != nil {
t.Fatal(err)
}

driver.Register(driver.NewFakeDriver(driverName))
defer driver.Unregister(driverName)

v, err1 := core.CreateVolume(volid0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first attach a volume then detach it

if err1 != nil {
t.Fatal(err1)
}

/* 1. Reference Not Null */
v.Spec.Extra = map[string]string{}
v.SetOption(types.OptionRef, "withRef")

v_ret, err := core.DetachVolume(volid0, nil)
if err != nil {
t.Fatal(err)
}
if v_ret.Name != volName0 {
t.Fatalf("Expect the returned volume name %s equals the input volume name %s", v_ret.Name, volName0)
}
}