blob: 3ab5e79b40ce74105bf0b795f0e731301f7f5eb5 [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package tasks
Akash Sonid36d23b2023-08-18 12:51:40 +053017
18import (
19 "context"
20 "testing"
21
22 "github.com/stretchr/testify/assert"
23)
24
25func TestNewTasks(t *testing.T) {
26 type args struct {
27 ctx context.Context
28 }
29 tasks := &Tasks{}
30 tests := []struct {
31 name string
32 args args
33 want *Tasks
34 }{
35 {
36 name: "NewTasks",
37 args: args{
38 ctx: context.Background(),
39 },
40 want: tasks,
41 },
42 }
43 for _, tt := range tests {
44 t.Run(tt.name, func(t *testing.T) {
45 got := NewTasks(tt.args.ctx)
46 assert.NotNil(t, got)
47 })
48 }
49}
50
51func TestTasks_CheckAndInitialize(t *testing.T) {
52 type args struct {
53 ctx context.Context
54 }
55 tests := []struct {
56 name string
57 args args
58 }{
59 {
60 name: "Tasks_CheckAndInitialize",
61 args: args{
62 ctx: context.Background(),
63 },
64 },
65 }
66 for _, tt := range tests {
67 t.Run(tt.name, func(t *testing.T) {
68 ts := &Tasks{}
69 ts.CheckAndInitialize(tt.args.ctx)
70 })
71 }
72}
73
74func TestTasks_StopAll(t *testing.T) {
75 task := []Task{
76 NewTaskSet("task1"),
77 }
78 tests := []struct {
79 name string
80 }{
81 {
82 name: "Tasks_StopAll",
83 },
84 }
85 for _, tt := range tests {
86 t.Run(tt.name, func(t *testing.T) {
87 ts := &Tasks{
88 queued: task,
89 }
90 ts.StopAll()
91 })
92 }
93}
94
95func TestTasks_executeTasks(t *testing.T) {
96 task := []Task{
97 NewTaskSet("task1"),
98 }
99 tests := []struct {
100 name string
101 }{
102 {
103 name: "Tasks_executeTasks",
104 },
105 }
106 for _, tt := range tests {
107 t.Run(tt.name, func(t *testing.T) {
108 ts := &Tasks{
109 queued: task,
110 }
111 ts.executeTasks()
112 })
113 }
114}
115
116func TestTaskSet_Start(t *testing.T) {
117 type args struct {
118 ctx context.Context
119 taskID uint8
120 }
121 task := []Task{
122 NewTaskSet("task1"),
123 }
124 tests := []struct {
125 name string
126 args args
127 wantErr bool
128 }{
129 {
130 name: "Tasks_TaskSet_Start",
131 args: args{
132 ctx: context.Background(),
133 taskID: 25,
134 },
135 wantErr: false,
136 },
137 }
138 for _, tt := range tests {
139 t.Run(tt.name, func(t *testing.T) {
140 ts := &TaskSet{
141 queued: task,
142 }
143 if err := ts.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
144 t.Errorf("TaskSet.Start() error = %v, wantErr %v", err, tt.wantErr)
145 }
146 })
147 }
148}