Skip to content

Commit

Permalink
change name from pod to deploymnet
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Aug 20, 2018
1 parent e48f282 commit cf6452c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/entity/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Deployment struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Namespace string `bson:"namespace" json:"namespace" validate:"required"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,alphanum,endkeys,required,alphanum"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,printascii,endkeys,required,printascii"`
EnvVars map[string]string `bson:"envVars,omitempty" json:"envVars" validate:"required,dive,keys,printascii,endkeys,required,printascii"`
Containers []Container `bson:"containers" json:"containers" validate:"required,dive,required"`
Volumes []DeploymentVolume `bson:"volumes,omitempty" json:"volumes" validate:"required,dive,required"`
Expand Down
42 changes: 21 additions & 21 deletions src/server/handler_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (suite *DeploymentTestSuite) TestCreateDeployment() {
},
}
tName := namesgenerator.GetRandomName(0)
pod := entity.Deployment{
deploy := entity.Deployment{
Name: tName,
Namespace: namespace,
Labels: map[string]string{},
Expand All @@ -73,7 +73,7 @@ func (suite *DeploymentTestSuite) TestCreateDeployment() {
NodeAffinity: []string{},
Replicas: 1,
}
bodyBytes, err := json.MarshalIndent(pod, "", " ")
bodyBytes, err := json.MarshalIndent(deploy, "", " ")
suite.NoError(err)

bodyReader := strings.NewReader(string(bodyBytes))
Expand All @@ -84,15 +84,15 @@ func (suite *DeploymentTestSuite) TestCreateDeployment() {
httpWriter := httptest.NewRecorder()
suite.wc.Dispatch(httpWriter, httpRequest)
assertResponseCode(suite.T(), http.StatusCreated, httpWriter)
defer suite.session.Remove(entity.DeploymentCollectionName, "name", pod.Name)
defer suite.session.Remove(entity.DeploymentCollectionName, "name", deploy.Name)

//load data to check
retDeployment := entity.Deployment{}
err = suite.session.FindOne(entity.DeploymentCollectionName, bson.M{"name": pod.Name}, &retDeployment)
err = suite.session.FindOne(entity.DeploymentCollectionName, bson.M{"name": deploy.Name}, &retDeployment)
suite.NoError(err)
suite.NotEqual("", retDeployment.ID)
suite.Equal(pod.Name, retDeployment.Name)
suite.Equal(len(pod.Containers), len(retDeployment.Containers))
suite.Equal(deploy.Name, retDeployment.Name)
suite.Equal(len(deploy.Containers), len(retDeployment.Containers))

//We use the new write but empty input which will cause the readEntity Error
httpWriter = httptest.NewRecorder()
Expand Down Expand Up @@ -121,7 +121,7 @@ func (suite *DeploymentTestSuite) TestCreateDeploymentFail() {
},
}
tName := namesgenerator.GetRandomName(0)
pod := entity.Deployment{
deploy := entity.Deployment{
Name: tName,
Namespace: namespace,
Containers: containers,
Expand All @@ -130,7 +130,7 @@ func (suite *DeploymentTestSuite) TestCreateDeploymentFail() {
},
}

bodyBytes, err := json.MarshalIndent(pod, "", " ")
bodyBytes, err := json.MarshalIndent(deploy, "", " ")
suite.NoError(err)

bodyReader := strings.NewReader(string(bodyBytes))
Expand All @@ -153,7 +153,7 @@ func (suite *DeploymentTestSuite) TestDeleteDeployment() {
},
}
tName := namesgenerator.GetRandomName(0)
pod := entity.Deployment{
deploy := entity.Deployment{
ID: bson.NewObjectId(),
Name: tName,
Namespace: namespace,
Expand All @@ -164,25 +164,25 @@ func (suite *DeploymentTestSuite) TestDeleteDeployment() {
Replicas: 1,
}

err := p.CreateDeployment(suite.sp, &pod)
err := p.CreateDeployment(suite.sp, &deploy)
suite.NoError(err)

err = suite.session.Insert(entity.DeploymentCollectionName, &pod)
err = suite.session.Insert(entity.DeploymentCollectionName, &deploy)
suite.NoError(err)

bodyBytes, err := json.MarshalIndent(pod, "", " ")
bodyBytes, err := json.MarshalIndent(deploy, "", " ")
suite.NoError(err)

bodyReader := strings.NewReader(string(bodyBytes))
httpRequest, err := http.NewRequest("DELETE", "http://localhost:7890/v1/deployments/"+pod.ID.Hex(), bodyReader)
httpRequest, err := http.NewRequest("DELETE", "http://localhost:7890/v1/deployments/"+deploy.ID.Hex(), bodyReader)
suite.NoError(err)

httpRequest.Header.Add("Content-Type", "application/json")
httpWriter := httptest.NewRecorder()
suite.wc.Dispatch(httpWriter, httpRequest)
assertResponseCode(suite.T(), http.StatusOK, httpWriter)

n, err := suite.session.Count(entity.DeploymentCollectionName, bson.M{"_id": pod.ID})
n, err := suite.session.Count(entity.DeploymentCollectionName, bson.M{"_id": deploy.ID})
suite.NoError(err)
suite.Equal(0, n)
}
Expand All @@ -208,29 +208,29 @@ func (suite *DeploymentTestSuite) TestGetDeployment() {
},
}
tName := namesgenerator.GetRandomName(0)
pod := entity.Deployment{
deploy := entity.Deployment{
ID: bson.NewObjectId(),
Name: tName,
Namespace: namespace,
Containers: containers,
}

//Create data into mongo manually
suite.session.C(entity.DeploymentCollectionName).Insert(pod)
suite.session.C(entity.DeploymentCollectionName).Insert(deploy)
defer suite.session.Remove(entity.DeploymentCollectionName, "name", tName)

httpRequest, err := http.NewRequest("GET", "http://localhost:7890/v1/deployments/"+pod.ID.Hex(), nil)
httpRequest, err := http.NewRequest("GET", "http://localhost:7890/v1/deployments/"+deploy.ID.Hex(), nil)
suite.NoError(err)

httpWriter := httptest.NewRecorder()
suite.wc.Dispatch(httpWriter, httpRequest)
assertResponseCode(suite.T(), http.StatusOK, httpWriter)

pod = entity.Deployment{}
err = json.Unmarshal(httpWriter.Body.Bytes(), &pod)
deploy = entity.Deployment{}
err = json.Unmarshal(httpWriter.Body.Bytes(), &deploy)
suite.NoError(err)
suite.Equal(tName, pod.Name)
suite.Equal(len(containers), len(pod.Containers))
suite.Equal(tName, deploy.Name)
suite.Equal(len(containers), len(deploy.Containers))
}

func (suite *DeploymentTestSuite) TestGetDeploymentWithInvalidID() {
Expand Down

0 comments on commit cf6452c

Please sign in to comment.