github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/apiv3/model/host_test.go (about)

     1  package model
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/evergreen-ci/evergreen/model/distro"
     8  	"github.com/evergreen-ci/evergreen/model/host"
     9  	"github.com/evergreen-ci/evergreen/model/task"
    10  	. "github.com/smartystreets/goconvey/convey"
    11  )
    12  
    13  type hostCompare struct {
    14  	ah APIHost
    15  	sh host.Host
    16  	st task.Task
    17  }
    18  
    19  func TestHostBuildFromService(t *testing.T) {
    20  	Convey("With list of model pairs", t, func() {
    21  		timeNow := time.Now()
    22  		// List of hosts to compare. Should make adding hosts in the future easy
    23  		// if some case is not present.
    24  		modelPairs := []hostCompare{
    25  			{
    26  				ah: APIHost{
    27  					Id: APIString("testId"),
    28  					Distro: distroInfo{
    29  						Id:       APIString("testDistroId"),
    30  						Provider: APIString("testDistroProvider"),
    31  					},
    32  					Provisioned: true,
    33  					StartedBy:   APIString("testStarter"),
    34  					Type:        APIString("testType"),
    35  					User:        APIString("testUser"),
    36  					Status:      APIString("testStatus"),
    37  					RunningTask: taskInfo{
    38  						Id:           APIString("testRunningTaskId"),
    39  						Name:         APIString("testRTName"),
    40  						DispatchTime: APITime(timeNow),
    41  						VersionId:    APIString("testVersionId"),
    42  						BuildId:      APIString("testBuildId"),
    43  					},
    44  				},
    45  				sh: host.Host{
    46  					Id: "testId",
    47  					Distro: distro.Distro{
    48  						Id:       "testDistroId",
    49  						Provider: "testDistroProvider",
    50  					},
    51  					Provisioned:  true,
    52  					StartedBy:    "testStarter",
    53  					InstanceType: "testType",
    54  					UserData:     "testUser",
    55  					Status:       "testStatus",
    56  				},
    57  				st: task.Task{
    58  					Id:           "testRunningTaskId",
    59  					DisplayName:  "testRTName",
    60  					DispatchTime: timeNow,
    61  					Version:      "testVersionId",
    62  					BuildId:      "testBuildId",
    63  				},
    64  			},
    65  			// Empty on purpose to ensure zero values are correctly converted
    66  			{
    67  				ah: APIHost{},
    68  				sh: host.Host{},
    69  				st: task.Task{},
    70  			},
    71  		}
    72  		Convey("running BuildFromService() should produce the equivalent model", func() {
    73  			for _, hc := range modelPairs {
    74  				apiHost := &APIHost{}
    75  				err := apiHost.BuildFromService(hc.st)
    76  				So(err, ShouldBeNil)
    77  				err = apiHost.BuildFromService(hc.sh)
    78  				So(err, ShouldBeNil)
    79  				So(apiHost, ShouldResemble, &hc.ah)
    80  			}
    81  		})
    82  	})
    83  }