Skip to content

Commit

Permalink
feat: add status object to plugin (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp authored Feb 12, 2020
1 parent 0a968cb commit e18be28
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cmd/vela-kubernetes/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2020 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package main

import (
"fmt"
"time"

"github.com/sirupsen/logrus"
)

// Status represents the plugin configuration for Status config information.
type Status struct {
// Kubernetes resources to watch status of
Resources []string
// total time allowed to watch Kubernetes resources
Timeout time.Duration
}

// Validate verifies the Status is properly configured.
func (s *Status) Validate() error {
logrus.Trace("validating status configuration")

// verify resources are provided
if len(s.Resources) == 0 {
return fmt.Errorf("no status resources provided")
}

// verify timeout is provided
if s.Timeout <= 0 {
return fmt.Errorf("no status timeout provided")
}

return nil
}
47 changes: 47 additions & 0 deletions cmd/vela-kubernetes/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2020 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package main

import (
"testing"
"time"
)

func TestKubernetes_Status_Validate(t *testing.T) {
// setup types
s := &Status{
Resources: []string{"resources"},
Timeout: 5 * time.Minute,
}

err := s.Validate()
if err != nil {
t.Errorf("Validate returned err: %v", err)
}
}

func TestKubernetes_Status_Validate_NoResources(t *testing.T) {
// setup types
s := &Status{
Timeout: 5 * time.Minute,
}

err := s.Validate()
if err == nil {
t.Errorf("Validate should have returned err")
}
}

func TestKubernetes_Status_Validate_NoTimeout(t *testing.T) {
// setup types
s := &Status{
Resources: []string{"resources"},
}

err := s.Validate()
if err == nil {
t.Errorf("Validate should have returned err")
}
}

0 comments on commit e18be28

Please sign in to comment.