forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite versions related functions (GoogleCloudPlatform#10181)
- Loading branch information
1 parent
1af6fd0
commit 0409b50
Showing
7 changed files
with
632 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package api | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/GoogleCloudPlatform/magic-modules/mmv1/api/product" | ||
) | ||
|
||
func TestProductLowestVersion(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
description string | ||
obj Product | ||
expected string | ||
}{ | ||
{ | ||
description: "lowest version is ga", | ||
obj: Product{ | ||
Versions: []*product.Version{ | ||
&product.Version{ | ||
Name: "beta", | ||
BaseUrl: "beta_url", | ||
}, | ||
&product.Version{ | ||
Name: "ga", | ||
BaseUrl: "ga_url", | ||
}, | ||
&product.Version{ | ||
Name: "alpha", | ||
BaseUrl: "alpha_url", | ||
}, | ||
}, | ||
}, | ||
expected: "ga", | ||
}, | ||
{ | ||
description: "lowest version is ga", | ||
obj: Product{ | ||
Versions: []*product.Version{ | ||
&product.Version{ | ||
Name: "beta", | ||
BaseUrl: "beta_url", | ||
}, | ||
&product.Version{ | ||
Name: "alpha", | ||
BaseUrl: "alpha_url", | ||
}, | ||
}, | ||
}, | ||
expected: "beta", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
|
||
t.Run(tc.description, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
versionObj := tc.obj.lowestVersion() | ||
|
||
if got, want := versionObj.Name, tc.expected; !reflect.DeepEqual(got, want) { | ||
t.Errorf("expected %v to be %v", got, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestProductVersionObjOrClosest(t *testing.T) { | ||
t.Parallel() | ||
|
||
cases := []struct { | ||
description string | ||
obj Product | ||
input string | ||
expected string | ||
}{ | ||
{ | ||
description: "closest version object to ga", | ||
obj: Product{ | ||
Versions: []*product.Version{ | ||
&product.Version{ | ||
Name: "beta", | ||
BaseUrl: "beta_url", | ||
}, | ||
&product.Version{ | ||
Name: "ga", | ||
BaseUrl: "ga_url", | ||
}, | ||
}, | ||
}, | ||
input: "ga", | ||
expected: "ga", | ||
}, | ||
{ | ||
description: "closest version object to alpha", | ||
obj: Product{ | ||
Versions: []*product.Version{ | ||
&product.Version{ | ||
Name: "beta", | ||
BaseUrl: "beta_url", | ||
}, | ||
&product.Version{ | ||
Name: "ga", | ||
BaseUrl: "ga_url", | ||
}, | ||
}, | ||
}, | ||
input: "alpha", | ||
expected: "beta", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
tc := tc | ||
|
||
t.Run(tc.description, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
versionObj := tc.obj.VersionObjOrClosest(tc.input) | ||
|
||
if got, want := versionObj.Name, tc.expected; !reflect.DeepEqual(got, want) { | ||
t.Errorf("expected %v to be %v", got, want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.