Skip to content

Commit

Permalink
modified current unit tests to support the new modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwinhr716 committed Mar 13, 2024
1 parent 623f132 commit b573351
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cluster-autoscaler/cloudprovider/gce/gce_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func newTestGceManager(t *testing.T, testServerURL string, regional bool) *gceMa
{"us-central1-f", "n1-standard-1"}: {Name: "n1-standard-1", CPU: 1, Memory: 1},
},
migTargetSizeCache: map[GceRef]int64{},
instanceTemplateNameCache: map[GceRef]string{},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{},
kubeEnvCache: map[GceRef]KubeEnv{},
migBaseNameCache: map[GceRef]string{},
Expand Down
50 changes: 25 additions & 25 deletions cluster-autoscaler/cloudprovider/gce/mig_info_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type mockAutoscalingGceClient struct {
fetchMigTargetSize func(GceRef) (int64, error)
fetchMigBasename func(GceRef) (string, error)
fetchMigInstances func(GceRef) ([]GceInstance, error)
fetchMigTemplateName func(GceRef) (string, error)
fetchMigTemplateName func(GceRef) (InstanceTemplateNameType, error)
fetchMigTemplate func(GceRef, string) (*gce.InstanceTemplate, error)
fetchMachineType func(string, string) (*gce.MachineType, error)
fetchListManagedInstancesResults func(GceRef) (string, error)
Expand Down Expand Up @@ -87,12 +87,12 @@ func (client *mockAutoscalingGceClient) FetchMigInstances(migRef GceRef) ([]GceI
return client.fetchMigInstances(migRef)
}

func (client *mockAutoscalingGceClient) FetchMigTemplateName(migRef GceRef) (string, error) {
func (client *mockAutoscalingGceClient) FetchMigTemplateName(migRef GceRef) (InstanceTemplateNameType, error) {
return client.fetchMigTemplateName(migRef)
}

func (client *mockAutoscalingGceClient) FetchMigTemplate(migRef GceRef, templateName string) (*gce.InstanceTemplate, error) {
return client.fetchMigTemplate(migRef, templateName)
func (client *mockAutoscalingGceClient) FetchMigTemplate(migRef GceRef, templateName string, regional bool) (*gce.InstanceTemplate, error) {
return client.fetchMigTemplate(migRef, templateName, regional)
}

func (client *mockAutoscalingGceClient) FetchMigsWithName(_ string, _ *regexp.Regexp) ([]string, error) {
Expand Down Expand Up @@ -859,15 +859,15 @@ func TestGetMigInstanceTemplateName(t *testing.T) {
name string
cache *GceCache
fetchMigs func(string) ([]*gce.InstanceGroupManager, error)
fetchMigTemplateName func(GceRef) (string, error)
fetchMigTemplateName func(GceRef) (InstanceTemplateNameType, error)
expectedTemplateName string
expectedErr error
}{
{
name: "template name in cache",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{templateName, false}},
},
expectedTemplateName: templateName,
},
Expand All @@ -881,14 +881,14 @@ func TestGetMigInstanceTemplateName(t *testing.T) {
name: "cache fill without mig, fallback success",
cache: emptyCache(),
fetchMigs: fetchMigsConst([]*gce.InstanceGroupManager{}),
fetchMigTemplateName: fetchMigTemplateNameConst(templateName),
fetchMigTemplateName: fetchMigTemplateNameConst(InstanceTemplateNameType{templateName, false}),
expectedTemplateName: templateName,
},
{
name: "cache fill failure, fallback success",
cache: emptyCache(),
fetchMigs: fetchMigsFail,
fetchMigTemplateName: fetchMigTemplateNameConst(templateName),
fetchMigTemplateName: fetchMigTemplateNameConst(InstanceTemplateNameType{templateName, false}),
expectedTemplateName: templateName,
},
{
Expand Down Expand Up @@ -944,8 +944,8 @@ func TestGetMigInstanceTemplate(t *testing.T) {
name string
cache *GceCache
fetchMigs func(string) ([]*gce.InstanceGroupManager, error)
fetchMigTemplateName func(GceRef) (string, error)
fetchMigTemplate func(GceRef, string) (*gce.InstanceTemplate, error)
fetchMigTemplateName func(GceRef) (InstanceTemplateNameType, error)
fetchMigTemplate func(GceRef, string, bool) (*gce.InstanceTemplate, error)
expectedTemplate *gce.InstanceTemplate
expectedCachedTemplate *gce.InstanceTemplate
expectedErr error
Expand All @@ -954,7 +954,7 @@ func TestGetMigInstanceTemplate(t *testing.T) {
name: "template in cache",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): template},
},
expectedTemplate: template,
Expand All @@ -964,7 +964,7 @@ func TestGetMigInstanceTemplate(t *testing.T) {
name: "cache without template, fetch success",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{templateName, false}},
instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate),
},
fetchMigTemplate: fetchMigTemplateConst(template),
Expand All @@ -975,7 +975,7 @@ func TestGetMigInstanceTemplate(t *testing.T) {
name: "cache with old template, fetch success",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): oldTemplate},
},
fetchMigTemplate: fetchMigTemplateConst(template),
Expand All @@ -986,7 +986,7 @@ func TestGetMigInstanceTemplate(t *testing.T) {
name: "cache without template, fetch failure",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{templateName, false}},
instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate),
},
fetchMigTemplate: fetchMigTemplateFail,
Expand All @@ -996,7 +996,7 @@ func TestGetMigInstanceTemplate(t *testing.T) {
name: "cache with old template, fetch failure",
cache: &GceCache{
migs: map[GceRef]Mig{mig.GceRef(): mig},
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): templateName},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{templateName, false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{mig.GceRef(): oldTemplate},
},
fetchMigTemplate: fetchMigTemplateFail,
Expand Down Expand Up @@ -1251,7 +1251,7 @@ func TestGetMigMachineType(t *testing.T) {
},
}
cache := &GceCache{
instanceTemplateNameCache: map[GceRef]string{mig.GceRef(): "template"},
instanceTemplateNameCache: map[GceRef]InstanceTemplateNameType{mig.GceRef(): InstanceTemplateNameType{"template", false}},
instanceTemplatesCache: map[GceRef]*gce.InstanceTemplate{
mig.GceRef(): {
Name: "template",
Expand Down Expand Up @@ -1377,7 +1377,7 @@ func emptyCache() *GceCache {
migTargetSizeCache: make(map[GceRef]int64),
migBaseNameCache: make(map[GceRef]string),
listManagedInstancesResultsCache: make(map[GceRef]string),
instanceTemplateNameCache: make(map[GceRef]string),
instanceTemplateNameCache: make(map[GceRef]InstanceTemplateNameType),
instanceTemplatesCache: make(map[GceRef]*gce.InstanceTemplate),
instancesFromUnknownMig: make(map[GceRef]bool),
}
Expand Down Expand Up @@ -1436,22 +1436,22 @@ func fetchMigBasenameConst(basename string) func(GceRef) (string, error) {
}
}

func fetchMigTemplateNameFail(_ GceRef) (string, error) {
return "", errFetchMigTemplateName
func fetchMigTemplateNameFail(_ GceRef) (InstanceTemplateNameType, error) {
return InstanceTemplateNameType{}, errFetchMigTemplateName
}

func fetchMigTemplateNameConst(templateName string) func(GceRef) (string, error) {
return func(GceRef) (string, error) {
return templateName, nil
func fetchMigTemplateNameConst(instanceTemplateNameType InstanceTemplateNameType) func(GceRef) (InstanceTemplateNameType, error) {
return func(GceRef) (InstanceTemplateNameType, error) {
return instanceTemplateNameType, nil
}
}

func fetchMigTemplateFail(_ GceRef, _ string) (*gce.InstanceTemplate, error) {
func fetchMigTemplateFail(_ GceRef, _ string, _ bool) (*gce.InstanceTemplate, error) {
return nil, errFetchMigTemplate
}

func fetchMigTemplateConst(template *gce.InstanceTemplate) func(GceRef, string) (*gce.InstanceTemplate, error) {
return func(GceRef, string) (*gce.InstanceTemplate, error) {
func fetchMigTemplateConst(template *gce.InstanceTemplate) func(GceRef, string, bool) (*gce.InstanceTemplate, error) {
return func(GceRef, string, bool) (*gce.InstanceTemplate, error) {
return template, nil
}
}
Expand Down

0 comments on commit b573351

Please sign in to comment.