Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(type): worker registration library #307

Merged
merged 13 commits into from
Sep 6, 2023
92 changes: 92 additions & 0 deletions library/worker_registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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

// WorkerRegistration is the library representation of a WorkerRegistration.
//
// swagger:model WorkerRegistration
type WorkerRegistration struct {
RegistrationToken *string `json:"registration_token,omitempty"`
QueuePublicKey *string `json:"queue_public_key,omitempty"`
QueueAddress *string `json:"queue_address,omitempty"`
}

// GetRegistrationToken returns the RegistrationToken field.
//
// When the provided WorkerRegistration type is nil, or the field within
// the type is nil, it returns an empty string for the field.
func (w *WorkerRegistration) GetRegistrationToken() string {
// return zero value if WorkerRegistration type or RegistrationToken field is nil
if w == nil || w.RegistrationToken == nil {
return ""
}

return *w.RegistrationToken
}

// GetPublicKey returns the QueuePublicKey field.
//
// When the provided WorkerRegistration type is nil, or the field within
// the type is nil, it returns an empty string for the field.
func (w *WorkerRegistration) GetPublicKey() string {
// return zero value if WorkerRegistration type or QueuePublicKey field is nil
if w == nil || w.QueuePublicKey == nil {
return ""
}

return *w.QueuePublicKey
}

// GetQueueAddress returns the QueueAddress field.
//
// When the provided WorkerRegistration type is nil, or the field within
// the type is nil, it returns an empty string for the field.
func (w *WorkerRegistration) GetQueueAddress() string {
// return zero value if WorkerRegistration type or QueueAddress field is nil
if w == nil || w.QueueAddress == nil {
return ""
}

return *w.QueueAddress
}

// SetRegistrationToken sets the RegistrationToken field.
//
// When the provided WorkerRegistration type is nil, it
// will set nothing and immediately return.
func (w *WorkerRegistration) SetRegistrationToken(v string) {
// return if WorkerRegistration type is nil
if w == nil {
return
}

w.RegistrationToken = &v
}

// SetPublicKey sets the QueuePublicKey field.
//
// When the provided WorkerRegistration type is nil, it
// will set nothing and immediately return.
func (w *WorkerRegistration) SetPublicKey(v string) {
// return if WorkerRegistration type is nil
if w == nil {
return
}

w.QueuePublicKey = &v
}

// SetQueueAddress sets the QueueAddress field.
//
// When the provided WorkerRegistration type is nil, it
// will set nothing and immediately return.
func (w *WorkerRegistration) SetQueueAddress(v string) {
// return if WorkerRegistration type is nil
if w == nil {
return
}

w.QueueAddress = &v
}
91 changes: 91 additions & 0 deletions library/worker_registration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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_WorkerRegistration_Getters(t *testing.T) {
// setup tests
tests := []struct {
wR *WorkerRegistration
want *WorkerRegistration
}{
{
wR: testWorkerRegistration(),
want: testWorkerRegistration(),
},
{
wR: new(WorkerRegistration),
want: new(WorkerRegistration),
},
}

// run tests
for _, test := range tests {
if test.wR.GetRegistrationToken() != test.want.GetRegistrationToken() {
t.Errorf("GetRegistrationToken is %v, want %v", test.wR.GetRegistrationToken(), test.want.GetRegistrationToken())
}

if test.wR.GetQueueAddress() != test.want.GetQueueAddress() {
t.Errorf("GetQueueAddress is %v, want %v", test.wR.GetQueueAddress(), test.want.GetQueueAddress())
}

if test.wR.GetPublicKey() != test.want.GetPublicKey() {
t.Errorf("GetPublicKey is %v, want %v", test.wR.GetPublicKey(), test.want.GetPublicKey())
}
}
}

func TestLibrary_WorkerRegistration_Setters(t *testing.T) {
// setup types
var w *WorkerRegistration

// setup tests
tests := []struct {
wR *WorkerRegistration
want *WorkerRegistration
}{
{
wR: testWorkerRegistration(),
want: testWorkerRegistration(),
},
{
wR: w,
want: new(WorkerRegistration),
},
}

// run tests
for _, test := range tests {
test.wR.SetRegistrationToken(test.want.GetRegistrationToken())
test.wR.SetQueueAddress(test.want.GetQueueAddress())
test.wR.SetPublicKey(test.want.GetPublicKey())

if test.wR.GetRegistrationToken() != test.want.GetRegistrationToken() {
t.Errorf("GetRegistrationToken is %v, want %v", test.wR.GetRegistrationToken(), test.want.GetRegistrationToken())
}

if test.wR.GetQueueAddress() != test.want.GetQueueAddress() {
t.Errorf("GetQueueAddress is %v, want %v", test.wR.GetQueueAddress(), test.want.GetQueueAddress())
}

if test.wR.GetPublicKey() != test.want.GetPublicKey() {
t.Errorf("GetPublicKey is %v, want %v", test.wR.GetPublicKey(), test.want.GetPublicKey())
}
}
}

// testWorkerRegistration is a test helper function to register a WorkerRegistration
// type with all fields set to a fake value.
func testWorkerRegistration() *WorkerRegistration {
w := new(WorkerRegistration)
w.SetRegistrationToken("1234356")
w.SetQueueAddress("http://localhost:8080")
w.SetPublicKey("isfnw1234")

return w
}
Loading