From e18be28e77134478bf28466d8cd841c24c5e5ef5 Mon Sep 17 00:00:00 2001 From: Jordan Brockopp Date: Wed, 12 Feb 2020 09:35:10 -0600 Subject: [PATCH] feat: add status object to plugin (#9) --- cmd/vela-kubernetes/status.go | 37 +++++++++++++++++++++++ cmd/vela-kubernetes/status_test.go | 47 ++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 cmd/vela-kubernetes/status.go create mode 100644 cmd/vela-kubernetes/status_test.go diff --git a/cmd/vela-kubernetes/status.go b/cmd/vela-kubernetes/status.go new file mode 100644 index 0000000..7db3899 --- /dev/null +++ b/cmd/vela-kubernetes/status.go @@ -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 +} diff --git a/cmd/vela-kubernetes/status_test.go b/cmd/vela-kubernetes/status_test.go new file mode 100644 index 0000000..b470a46 --- /dev/null +++ b/cmd/vela-kubernetes/status_test.go @@ -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") + } +}