Skip to content

Commit

Permalink
rename from DisplayName to Name
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Jul 4, 2018
1 parent 592dfec commit 522eb25
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/server/handler_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func createStorage(ctx *web.Context) {

session := sp.Mongo.NewSession()
session.C(entity.StorageCollectionName).EnsureIndex(mgo.Index{
Key: []string{"displayName"},
Key: []string{"name"},
Unique: true,
})
defer session.Close()
Expand All @@ -54,7 +54,7 @@ func createStorage(ctx *web.Context) {
storage.CreatedAt = timeutils.Now()
if err := session.Insert(entity.StorageCollectionName, &storage); err != nil {
if mgo.IsDup(err) {
response.Conflict(req.Request, resp.ResponseWriter, fmt.Errorf("Storage Provider Name: %s already existed", storage.DisplayName))
response.Conflict(req.Request, resp.ResponseWriter, fmt.Errorf("Storage Provider Name: %s already existed", storage.Name))
} else {
response.InternalServerError(req.Request, resp.ResponseWriter, err)
}
Expand Down
48 changes: 24 additions & 24 deletions src/server/handler_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (suite *StorageTestSuite) TestCreateStorage() {
//Testing parameter
tName := namesgenerator.GetRandomName(0)
storage := entity.Storage{
Type: entity.FakeStorageType,
DisplayName: tName,
Type: entity.FakeStorageType,
Name: tName,
Fake: entity.FakeStorage{
FakeParameter: "fake~",
},
Expand All @@ -77,7 +77,7 @@ func (suite *StorageTestSuite) TestCreateStorage() {
httpRequest.Header.Add("Content-Type", "application/json")
httpWriter := httptest.NewRecorder()
suite.wc.Dispatch(httpWriter, httpRequest)
defer suite.session.Remove(entity.StorageCollectionName, "displayName", tName)
defer suite.session.Remove(entity.StorageCollectionName, "name", tName)
assertResponseCode(suite.T(), http.StatusOK, httpWriter)
//Empty data
//We use the new write but empty input
Expand All @@ -101,23 +101,23 @@ func (suite *StorageTestSuite) TestCreateStorageFail() {
errorCode int
}{
{"InvalidParameter", entity.Storage{
DisplayName: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Name: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Fake: entity.FakeStorage{
FakeParameter: "",
}},
http.StatusBadRequest},
{"CreateFail", entity.Storage{
DisplayName: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Name: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Fake: entity.FakeStorage{
FakeParameter: "Yo",
IWantFail: true,
}},
http.StatusInternalServerError},
{"StorageTypeError", entity.Storage{
DisplayName: namesgenerator.GetRandomName(0),
Type: "non-exist",
Name: namesgenerator.GetRandomName(0),
Type: "non-exist",
Fake: entity.FakeStorage{
FakeParameter: "Yo",
IWantFail: true,
Expand Down Expand Up @@ -147,16 +147,16 @@ func (suite *StorageTestSuite) TestDeleteStorage() {
//Testing parameter
tName := namesgenerator.GetRandomName(0)
storage := entity.Storage{
ID: bson.NewObjectId(),
Type: entity.FakeStorageType,
DisplayName: tName,
ID: bson.NewObjectId(),
Type: entity.FakeStorageType,
Name: tName,
Fake: entity.FakeStorage{
FakeParameter: "fake~",
},
}

suite.session.C(entity.StorageCollectionName).Insert(storage)
defer suite.session.Remove(entity.StorageCollectionName, "displayName", tName)
defer suite.session.Remove(entity.StorageCollectionName, "name", tName)

bodyBytes, err := json.MarshalIndent(storage, "", " ")
suite.NoError(err)
Expand Down Expand Up @@ -195,18 +195,18 @@ func (suite *StorageTestSuite) TestDeleteStorageFail() {
errorCode int
}{
{"DeleteStorage", entity.Storage{
ID: bson.NewObjectId(),
DisplayName: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
ID: bson.NewObjectId(),
Name: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Fake: entity.FakeStorage{
FakeParameter: "Yo-Delete-Fail",
IWantFail: true,
}},
http.StatusInternalServerError},
{"StorageTypeError", entity.Storage{
ID: bson.NewObjectId(),
DisplayName: namesgenerator.GetRandomName(0),
Type: "non-exist",
ID: bson.NewObjectId(),
Name: namesgenerator.GetRandomName(0),
Type: "non-exist",
Fake: entity.FakeStorage{
FakeParameter: "Yo-Delete-Fail",
IWantFail: true,
Expand All @@ -217,7 +217,7 @@ func (suite *StorageTestSuite) TestDeleteStorageFail() {
for _, tc := range testCases {
suite.T().Run(tc.cases, func(t *testing.T) {
suite.session.C(entity.StorageCollectionName).Insert(tc.storage)
defer suite.session.Remove(entity.StorageCollectionName, "displayName", tc.storage.DisplayName)
defer suite.session.Remove(entity.StorageCollectionName, "name", tc.storage.Name)

httpRequest, err := http.NewRequest("DELETE", "http://localhost:7890/v1/storage/"+tc.storage.ID.Hex(), nil)
suite.NoError(err)
Expand All @@ -236,8 +236,8 @@ func (suite *StorageTestSuite) TestListStorage() {
count := 3
for i := 0; i < count; i++ {
storages = append(storages, entity.Storage{
DisplayName: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Name: namesgenerator.GetRandomName(0),
Type: entity.FakeStorageType,
Fake: entity.FakeStorage{
FakeParameter: "Yo",
IWantFail: false,
Expand All @@ -257,7 +257,7 @@ func (suite *StorageTestSuite) TestListStorage() {

for _, v := range storages {
err := suite.session.C(entity.StorageCollectionName).Insert(v)
defer suite.session.Remove(entity.StorageCollectionName, "displayName", v.DisplayName)
defer suite.session.Remove(entity.StorageCollectionName, "name", v.Name)
suite.NoError(err)
}

Expand All @@ -282,7 +282,7 @@ func (suite *StorageTestSuite) TestListStorage() {
suite.NoError(err)
suite.Equal(tc.expectSize, len(retStorages))
for i, v := range retStorages {
suite.Equal(storages[i].DisplayName, v.DisplayName)
suite.Equal(storages[i].Name, v.Name)
fmt.Println(v.Type)
fmt.Println(storages[i].Type)
suite.Equal(storages[i].Type, v.Type)
Expand Down
4 changes: 2 additions & 2 deletions src/server/handler_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func createVolume(ctx *web.Context) {
defer session.Close()

// Check the storageClass is existed
couunt, err := session.Count(entity.StorageCollectionName, bson.M{"displayName": volume.StorageName})
couunt, err := session.Count(entity.StorageCollectionName, bson.M{"name": volume.StorageName})
if err != nil {
response.InternalServerError(req.Request, resp.ResponseWriter, err)
return
Expand All @@ -41,7 +41,7 @@ func createVolume(ctx *web.Context) {
return
}

// Check whether this displayname has been used
// Check whether this name has been used
volume.ID = bson.NewObjectId()
volume.CreatedAt = timeutils.Now()
//Generate the metaName for PVC meta name and we will use it future
Expand Down
8 changes: 4 additions & 4 deletions src/server/handler_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (suite *VolumeTestSuite) SetupSuite() {
suite.wc.Add(service)
//init a Storage
suite.storage = entity.Storage{
ID: bson.NewObjectId(),
Type: "nfs",
DisplayName: namesgenerator.GetRandomName(0),
ID: bson.NewObjectId(),
Type: "nfs",
Name: namesgenerator.GetRandomName(0),
}
err := suite.session.Insert(entity.StorageCollectionName, suite.storage)
suite.NoError(err)
Expand All @@ -65,7 +65,7 @@ func (suite *VolumeTestSuite) TestCreateVolume() {
tCapacity := "500G"
volume := entity.Volume{
Name: tName,
StorageName: suite.storage.DisplayName,
StorageName: suite.storage.Name,
Capacity: tCapacity,
AccessMode: tAccessMode,
}
Expand Down

0 comments on commit 522eb25

Please sign in to comment.