Skip to content

Commit

Permalink
queue registration library
Browse files Browse the repository at this point in the history
  • Loading branch information
timhuynh94 committed Aug 30, 2023
1 parent 14b3758 commit f4fc813
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
61 changes: 61 additions & 0 deletions library/queue_registration.go
Original file line number Diff line number Diff line change
@@ -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
}
83 changes: 83 additions & 0 deletions library/queue_registration_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

Check failure on line 36 in library/queue_registration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] library/queue_registration_test.go#L36

unnecessary trailing newline (whitespace)
Raw output
library/queue_registration_test.go:36: unnecessary trailing newline (whitespace)

	}
}

Check failure on line 37 in library/queue_registration_test.go

View workflow job for this annotation

GitHub Actions / full-review

block should not end with a whitespace (or comment) (wsl)

Check failure on line 37 in library/queue_registration_test.go

View workflow job for this annotation

GitHub Actions / diff-review

block should not end with a whitespace (or comment) (wsl)

Check failure on line 37 in library/queue_registration_test.go

View workflow job for this annotation

GitHub Actions / diff-review

block should not end with a whitespace (or comment) (wsl)

Check failure on line 37 in library/queue_registration_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] library/queue_registration_test.go#L37

block should not end with a whitespace (or comment) (wsl)
Raw output
library/queue_registration_test.go:37:2: block should not end with a whitespace (or comment) (wsl)
	}
	^
}

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
}

0 comments on commit f4fc813

Please sign in to comment.