/* Copyright (c) 2018 Red Hat, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // This file contains the implementation of the resource that manages the collection of // job templates. package awx import ( "net/url" "reflect" "testing" ) func TestNewJobsResource(t *testing.T) { want := new(JobsResource) want.connection = Connection{} want.path = "jobs" type args struct { connection Connecter path string } tests := []struct { name string args args want JobActions }{ {"Resource creation", args{Connection{}, "jobs"}, want}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := NewJobsResource(tt.args.connection, tt.args.path); !reflect.DeepEqual(got, tt.want) { t.Errorf("NewJobsResource() = %v, want %v", got, tt.want) } }) } } func TestJobsResource_Get(t *testing.T) { want := new(JobsGetRequest) want.resource = &Resource{} want.addFilter("page_size", "1000") type fields struct { Resource Resource } tests := []struct { name string fields fields want Sender }{ {"Resource assignment", fields{Resource{}}, want}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &JobsResource{ Resource: tt.fields.Resource, } if got := r.Get(); !reflect.DeepEqual(got, tt.want) { t.Errorf("JobsResource.Get() = %v, want %v", got, tt.want) } }) } } func TestJobsResource_ID(t *testing.T) { want := NewJobResource(Connection{}, "jobs/1") jobsResource := new(Resource) jobsResource.connection = Connection{} jobsResource.path = "jobs" type fields struct { Resource Resource } type args struct { id int } tests := []struct { name string fields fields args args want Getter }{ {"Path creation", fields{*jobsResource}, args{1}, want}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &JobsResource{ Resource: tt.fields.Resource, } if got := r.ID(tt.args.id); !reflect.DeepEqual(got, tt.want) { t.Errorf("JobsResource.ID() = %v, want %v", got, tt.want) } }) } } func TestJobsResource_JobEvents(t *testing.T) { want := new(JobEventsResource) want.connection = Connection{} want.path = "jobs/1/job_events" jobsResource := new(Resource) jobsResource.connection = Connection{} jobsResource.path = "jobs" type fields struct { Resource Resource } type args struct { id int } tests := []struct { name string fields fields args args want Getter }{ {"Resource creation", fields{*jobsResource}, args{1}, want}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &JobsResource{ Resource: tt.fields.Resource, } if got := r.JobEvents(tt.args.id); !reflect.DeepEqual(got, tt.want) { t.Errorf("JobsResource.JobEvents() = %v, want %v", got, tt.want) } }) } } func TestJobsGetRequest_Filter(t *testing.T) { filteredRequest := new(JobsGetRequest) filteredRequest.query = make(url.Values) filteredRequest.query.Add("param1", "val") type fields struct { Request Request } type args struct { name string value interface{} } tests := []struct { name string fields fields args args want Sender }{ {"Applying filtering", fields{*new(Request)}, args{"param1", "val"}, filteredRequest}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := &JobsGetRequest{ Request: tt.fields.Request, } if got := r.Filter(tt.args.name, tt.args.value); !reflect.DeepEqual(got, tt.want) { t.Errorf("JobsGetRequest.Filter() = %v, want %v", got, tt.want) } }) } }