-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add status object to plugin (#9)
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |