-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Juniper/document-versions-supported
Add version support to generated provider documentation
- Loading branch information
Showing
8 changed files
with
188 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package compatibility | ||
|
||
import ( | ||
"github.com/Juniper/apstra-go-sdk/apstra" | ||
"strings" | ||
) | ||
|
||
func SupportedApiVersions() []string { | ||
us := []string{ | ||
"4.1.0", | ||
"4.1.1", | ||
"4.1.2", | ||
} | ||
them := apstra.ApstraApiSupportedVersions() | ||
|
||
var result []string | ||
for i := range us { | ||
if them.Includes(us[i]) { | ||
result = append(result, us[i]) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
func SupportedApiVersionsPretty() string { | ||
supportedVers := SupportedApiVersions() | ||
stop := len(supportedVers) - 1 | ||
|
||
for i := range supportedVers { | ||
if i == stop { | ||
supportedVers[i] = "and " + supportedVers[i] | ||
break | ||
} | ||
supportedVers[i] = supportedVers[i] + "," | ||
} | ||
|
||
return strings.Join(supportedVers, " ") | ||
} |
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,28 @@ | ||
package compatibility | ||
|
||
import ( | ||
"terraform-provider-apstra/apstra/utils" | ||
"testing" | ||
) | ||
|
||
func TestSupportedApiVersions(t *testing.T) { | ||
expected := []string{ | ||
"4.1.0", | ||
"4.1.1", | ||
"4.1.2", | ||
} | ||
|
||
result := SupportedApiVersions() | ||
|
||
if !utils.SlicesMatch(expected, result) { | ||
t.Fatalf("expected %v, got %v", expected, result) | ||
} | ||
} | ||
|
||
func TestSupportedApiVersionsPretty(t *testing.T) { | ||
expected := "4.1.0, 4.1.1, and 4.1.2" | ||
result := SupportedApiVersionsPretty() | ||
if expected != result { | ||
t.Fatalf("expected %q; got %q", expected, result) | ||
} | ||
} |
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,15 @@ | ||
package utils | ||
|
||
func SlicesMatch[A comparable](a, b []A) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
|
||
for i := range a { | ||
if a[i] != b[i] { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
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,80 @@ | ||
package utils | ||
|
||
import "testing" | ||
|
||
func TestSlicesMatch(t *testing.T) { | ||
|
||
type intTestCase struct { | ||
a []int | ||
b []int | ||
expected bool | ||
} | ||
|
||
type stringTestCase struct { | ||
a []string | ||
b []string | ||
expected bool | ||
} | ||
|
||
intTestCases := []intTestCase{ | ||
{ | ||
a: []int{1, 3, 4}, | ||
b: []int{1, 3, 4}, | ||
expected: true, | ||
}, | ||
{ | ||
a: []int{1, 3, 4, 5}, | ||
b: []int{1, 3, 4}, | ||
expected: false, | ||
}, | ||
{ | ||
a: []int{1, 3, 4}, | ||
b: []int{1, 3, 4, 5}, | ||
expected: false, | ||
}, | ||
{ | ||
a: []int{0, 3, 4}, | ||
b: []int{1, 3, 4}, | ||
expected: false, | ||
}, | ||
{ | ||
a: []int{1, 3, 0}, | ||
b: []int{1, 3, 4}, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for i, tc := range intTestCases { | ||
result := SlicesMatch(tc.a, tc.b) | ||
if tc.expected != result { | ||
t.Fatalf("int test case %d: expected %t; got %t", i, tc.expected, result) | ||
} | ||
|
||
} | ||
|
||
stringTestCases := []stringTestCase{ | ||
{ | ||
a: []string{"foo", "bar"}, | ||
b: []string{"foo", "bar"}, | ||
expected: true, | ||
}, | ||
{ | ||
a: []string{"fOo", "bar"}, | ||
b: []string{"foo", "bar"}, | ||
expected: false, | ||
}, | ||
{ | ||
a: []string{"foo", "bar", "baz"}, | ||
b: []string{"foo", "bar"}, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for i, tc := range stringTestCases { | ||
result := SlicesMatch(tc.a, tc.b) | ||
if tc.expected != result { | ||
t.Fatalf("string test case %d: expected %t; got %t", i, tc.expected, result) | ||
} | ||
|
||
} | ||
} |
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