From f4fc813b71134fc6aa4921eb6b21c17df79eacde Mon Sep 17 00:00:00 2001 From: TimHuynh Date: Wed, 30 Aug 2023 14:20:16 -0500 Subject: [PATCH] queue registration library --- library/queue_registration.go | 61 ++++++++++++++++++++++ library/queue_registration_test.go | 83 ++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 library/queue_registration.go create mode 100644 library/queue_registration_test.go diff --git a/library/queue_registration.go b/library/queue_registration.go new file mode 100644 index 00000000..6bac07d1 --- /dev/null +++ b/library/queue_registration.go @@ -0,0 +1,61 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package library + +// QueueRegistration is the library representation of a QueueRegistration. +// +// swagger:model QueueRegistration +type QueueRegistration struct { + QueuePublicKey *string `json:"queue-public-key,omitempty"` + QueueAddress *string `json:"queue-address,omitempty"` +} + +// GetPublicKey returns the ID field. +// +// When the provided Worker type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (q *QueueRegistration) GetPublicKey() string { + // return zero value if Worker type or ID field is nil + if q == nil || q.QueuePublicKey == nil { + return "" + } + + return *q.QueuePublicKey +} + +func (q *QueueRegistration) GetQueueAddress() string { + // return zero value if Worker type or ID field is nil + if q == nil || q.QueueAddress == nil { + return "" + } + + return *q.QueueAddress +} + +// SetPublicKey sets the ID field. +// +// When the provided Worker type is nil, it +// will set nothing and immediately return. +func (q *QueueRegistration) SetPublicKey(v string) { + // return if Worker type is nil + if q == nil { + return + } + + q.QueuePublicKey = &v +} + +// SetQueueAddress sets the ID field. +// +// When the provided Worker type is nil, it +// will set nothing and immediately return. +func (q *QueueRegistration) SetQueueAddress(v string) { + // return if Worker type is nil + if q == nil { + return + } + + q.QueueAddress = &v +} diff --git a/library/queue_registration_test.go b/library/queue_registration_test.go new file mode 100644 index 00000000..c31f99c9 --- /dev/null +++ b/library/queue_registration_test.go @@ -0,0 +1,83 @@ +// Copyright (c) 2023 Target Brands, Inc. All rights reserved. +// +// Use of this source code is governed by the LICENSE file in this repository. + +package library + +import ( + "testing" +) + +func TestLibrary_Queue_Registration_Getters(t *testing.T) { + // setup tests + tests := []struct { + qR *QueueRegistration + want *QueueRegistration + }{ + { + qR: testQueueRegistration(), + want: testQueueRegistration(), + }, + { + qR: new(QueueRegistration), + want: new(QueueRegistration), + }, + } + + // run tests + for _, test := range tests { + if test.qR.GetQueueAddress() != test.want.GetQueueAddress() { + t.Errorf("GetQueueAddress is %v, want %v", test.qR.GetQueueAddress(), test.want.GetQueueAddress()) + } + + if test.qR.GetPublicKey() != test.want.GetPublicKey() { + t.Errorf("GetPublicKey is %v, want %v", test.qR.GetPublicKey(), test.want.GetPublicKey()) + } + + } +} + +func TestLibrary_QueueRegistration_Setters(t *testing.T) { + // setup types + var w *QueueRegistration + + // setup tests + tests := []struct { + qR *QueueRegistration + want *QueueRegistration + }{ + { + qR: testQueueRegistration(), + want: testQueueRegistration(), + }, + { + qR: w, + want: new(QueueRegistration), + }, + } + + // run tests + for _, test := range tests { + test.qR.SetQueueAddress(test.want.GetQueueAddress()) + test.qR.SetPublicKey(test.want.GetPublicKey()) + + if test.qR.GetQueueAddress() != test.want.GetQueueAddress() { + t.Errorf("GetQueueAddress is %v, want %v", test.qR.GetQueueAddress(), test.want.GetQueueAddress()) + } + + if test.qR.GetPublicKey() != test.want.GetPublicKey() { + t.Errorf("GetPublicKey is %v, want %v", test.qR.GetPublicKey(), test.want.GetPublicKey()) + } + } +} + +// testWorker is a test helper function to create a Worker +// type with all fields set to a fake value. +func testQueueRegistration() *QueueRegistration { + w := new(QueueRegistration) + + w.SetPublicKey("http://localhost:8080") + w.SetPublicKey("worker_0") + + return w +}