Skip to content

Commit

Permalink
Merge pull request #112 from linkernetworks/johnlin/pod-entity-valida…
Browse files Browse the repository at this point in the history
…te-fix

johnlin/pod entity validate fix

Former-commit-id: b0f1ff2fde2558b750e5bf19c6a4096f4fd8449e [formerly 9b7508a]
Former-commit-id: 1b36e028d92f4fd1de2ea9ffcec645c6bd8b3b31
  • Loading branch information
Hung-Wei Chiu authored Jul 18, 2018
2 parents c5f9d33 + 3c6bdc4 commit 76eefd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/entity/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
type Container struct {
Name string `bson:"name" json:"name" validate:"required"`
Image string `bson:"image" json:"image" validate:"required"`
Command []string `bson:"command" json:"command" validate:"-"`
Command []string `bson:"command" json:"command" validate:"required,dive,required"`
}

type PodVolume struct {
Expand All @@ -25,10 +25,10 @@ type Pod struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required"`
Namespace string `bson:"namespace" json:"namespace" validate:"required"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"-"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,alphanum,endkeys,required,alphanum"`
Containers []Container `bson:"containers" json:"containers" validate:"required,dive,required"`
Volumes []PodVolume `bson:"volumes,omitempty" json:"volumes" validate:"required,dive,required"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
Volumes []PodVolume `bson:"volumes,omitempty" json:"volumes" validate:"-"`
}

//GetCollection - get model mongo collection name.
Expand Down
5 changes: 3 additions & 2 deletions src/server/handler_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (suite *PodTestSuite) SetupSuite() {
suite.wc.Add(service)
}

func (suite *PodTestSuite) TearDownSuite() {
}
func (suite *PodTestSuite) TearDownSuite() {}

func TestPodSuite(t *testing.T) {
suite.Run(t, new(PodTestSuite))
Expand All @@ -64,7 +63,9 @@ func (suite *PodTestSuite) TestCreatePod() {
pod := entity.Pod{
Name: tName,
Namespace: namespace,
Labels: map[string]string{},
Containers: containers,
Volumes: []entity.PodVolume{},
}

bodyBytes, err := json.MarshalIndent(pod, "", " ")
Expand Down

0 comments on commit 76eefd3

Please sign in to comment.