diff --git a/internal/api/api_helpers.go b/internal/api/api_helpers.go index b2a09f6e..fef022b8 100644 --- a/internal/api/api_helpers.go +++ b/internal/api/api_helpers.go @@ -34,6 +34,14 @@ import ( "github.com/OpenCHAMI/power-control/v2/internal/model" ) +type IDList struct { + IDs []uuid.UUID `json:"ids"` +} + +type IDResp struct { + ID uuid.UUID `json:"id"` +} + // WriteJSON - writes JSON to the open http connection func WriteJSON(w http.ResponseWriter, i interface{}) { obj, err := json.Marshal(i) @@ -57,9 +65,9 @@ func WriteHeaders(w http.ResponseWriter, pb model.Passback) { w.WriteHeader(pb.StatusCode) switch val := pb.Obj.(type) { case []uuid.UUID: - WriteJSON(w, model.IDList{IDs: val}) + WriteJSON(w, IDList{IDs: val}) case uuid.UUID: - WriteJSON(w, model.IDResp{ID: val}) + WriteJSON(w, IDResp{ID: val}) default: WriteJSON(w, pb.Obj) } diff --git a/internal/api/api_test_setup_handler.go b/internal/api/api_test_setup_handler.go deleted file mode 100644 index 3b5d5a66..00000000 --- a/internal/api/api_test_setup_handler.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - * (C) Copyright [2021-2023] Hewlett Packard Enterprise Development LP - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package api - -import ( - "net/http" - "sync" -) - -// mutex - protects the CreateRouterAndHandler -var mutex = &sync.Mutex{} - -// IsHandled - setups protection for the mutex -var IsHandled bool - -// CreateRouterAndHandler - Create a singleton for setting up routing for the UnitTests -func CreateRouterAndHandler() { - mutex.Lock() - if !IsHandled { - IsHandled = true - //This setups the production routs - router := NewRouter() - //this creates the handle - http.Handle("/", router) - } - mutex.Unlock() -} diff --git a/internal/model/models.go b/internal/model/models.go deleted file mode 100644 index 9216ee7a..00000000 --- a/internal/model/models.go +++ /dev/null @@ -1,97 +0,0 @@ -/* - * (C) Copyright [2021-2023] Hewlett Packard Enterprise Development LP - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package model - -import ( - "fmt" - - "github.com/google/uuid" -) - -type IDList struct { - IDs []uuid.UUID `json:"ids"` -} - -type IDResp struct { - ID uuid.UUID `json:"id"` -} - -func UUIDSliceEquals(obj []uuid.UUID, other []uuid.UUID) bool { - if len(obj) != len(other) { - return false - } - objMap := make(map[uuid.UUID]int) - otherMap := make(map[uuid.UUID]int) - - for _, objE := range obj { - objMap[objE]++ - } - for _, otherE := range other { - otherMap[otherE]++ - } - for objKey, objVal := range objMap { - if otherMap[objKey] != objVal { - return false - } - } - return true -} - -func StringSliceEquals(obj []string, other []string) bool { - if len(obj) != len(other) { - return false - } else if len(obj) == 0 && len(other) == 0 { - return true - } else if obj == nil && other == nil { - return true - } - objMap := make(map[string]int) - otherMap := make(map[string]int) - - for _, objE := range obj { - objMap[objE]++ - } - for _, otherE := range other { - otherMap[otherE]++ - } - for objKey, objVal := range objMap { - if otherMap[objKey] != objVal { - return false - } - } - return true -} - -func NewInvalidInputError(Message string, CompIDs []string) (err error) { - err = fmt.Errorf("%s: %v", Message, CompIDs) - return err -} - -func Find(slice []string, val string) (int, bool) { - for i, item := range slice { - if item == val { - return i, true - } - } - return -1, false -} diff --git a/internal/model/models_test.go b/internal/model/models_test.go deleted file mode 100644 index fc9136e1..00000000 --- a/internal/model/models_test.go +++ /dev/null @@ -1,70 +0,0 @@ -//go:build !integration_tests - -/* - * (C) Copyright [2021-2023] Hewlett Packard Enterprise Development LP - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -package model - -import ( - "strings" - "testing" - - "github.com/google/uuid" - "github.com/stretchr/testify/suite" -) - -type ModelsTS struct { - suite.Suite -} - -func (suite *ModelsTS) TestUUIDSliceEquals() { - u1 := []uuid.UUID{uuid.New(), uuid.New(), uuid.New()} - u2 := []uuid.UUID{uuid.New(), uuid.New()} - u3 := []uuid.UUID{uuid.New(), uuid.New()} - suite.True(UUIDSliceEquals(u1, u1)) - suite.True(UUIDSliceEquals(u2, u2)) - suite.False(UUIDSliceEquals(u1, u2)) - suite.False(UUIDSliceEquals(u3, u2)) -} - -func (suite *ModelsTS) TestStringSliceEquals() { - s1 := []string{"a1", "a2", "a3"} - s2 := []string{"a3", "a2", "a1"} - s3 := []string{"a3", "a2"} - s4 := []string{"a3", "a2", "a4"} - suite.True(StringSliceEquals(s1, s2)) - suite.True(StringSliceEquals(s2, s1)) - suite.False(StringSliceEquals(s3, s1)) - suite.False(StringSliceEquals(s3, s4)) - suite.False(StringSliceEquals(s1, s4)) -} - -func (suite *ModelsTS) TestNewInvalidInputError() { - err := NewInvalidInputError("Message", []string{"a1", "a2", "a3"}) - suite.True(strings.Contains(err.Error(), "Message")) - suite.True(strings.Contains(err.Error(), "[a1 a2 a3]")) -} - -func TestModelsSuite(t *testing.T) { - - suite.Run(t, new(ModelsTS)) -} diff --git a/internal/storage/power_status.go b/internal/storage/power_status.go deleted file mode 100644 index 1d9b03e4..00000000 --- a/internal/storage/power_status.go +++ /dev/null @@ -1,23 +0,0 @@ -// MIT License -// -// (C) Copyright [2022-2023] Hewlett Packard Enterprise Development LP -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR -// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. - -package storage diff --git a/internal/storage/transition_size_test.go b/internal/storage/transition_size_test.go index 2b841d30..2e16f895 100644 --- a/internal/storage/transition_size_test.go +++ b/internal/storage/transition_size_test.go @@ -64,9 +64,9 @@ func createProviders(t *testing.T, settings *EtcdTestSettings) (StorageProvider, t.Errorf("Storage Init() failed: %v", err) } - err = ds.Init(nil) + ds.Init(nil) if err != nil { - t.Errorf("DistributedLockProvider Init() failed: %v", err) + t.Errorf("DistLock Init() failed: %v", err) } if e, ok := ms.(*ETCDStorage); ok {