Skip to content

Commit 82a6925

Browse files
fix(datasource-feeds): add feed_type field and tests (#115)
1 parent 598a1c9 commit 82a6925

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

octopusdeploy_framework/datasource_feeds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (e *feedsDataSource) Read(ctx context.Context, req datasource.ReadRequest,
4141

4242
query := feeds.FeedsQuery{
4343
Name: data.Name.ValueString(),
44+
FeedType: data.FeedType.ValueString(),
4445
IDs: util.GetIds(data.IDs),
4546
PartialName: data.PartialName.ValueString(),
4647
Skip: util.GetNumber(data.Skip),

octopusdeploy_framework/datasource_feeds_test.go

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,41 @@ func TestAccDataSourceFeeds(t *testing.T) {
2525
{
2626
Check: resource.ComposeTestCheckFunc(
2727
testAccCheckFeedsDataSourceID(prefix),
28-
// Check that at least the feeds we created exist (there may be more in the test environment)
2928
resource.TestCheckResourceAttrSet(prefix, "feeds.#"),
29+
resource.TestCheckResourceAttrSet(prefix, "feeds.0.feed_type"),
3030
),
3131
Config: testAccDataSourceFeedsConfig(localName, take),
3232
},
33+
{
34+
Check: func(s *terraform.State) error {
35+
nugetPrefix := fmt.Sprintf("data.octopusdeploy_feeds.%s_nuget", localName)
36+
return resource.ComposeTestCheckFunc(
37+
testAccCheckFeedsDataSourceID(nugetPrefix),
38+
testAccCheckFeedsFilteredByType(nugetPrefix, "NuGet"),
39+
)(s)
40+
},
41+
Config: testAccDataSourceFeedsWithFilterConfig(localName+"_nuget", "NuGet"),
42+
},
43+
{
44+
Check: func(s *terraform.State) error {
45+
mavenPrefix := fmt.Sprintf("data.octopusdeploy_feeds.%s_maven", localName)
46+
return resource.ComposeTestCheckFunc(
47+
testAccCheckFeedsDataSourceID(mavenPrefix),
48+
testAccCheckFeedsFilteredByType(mavenPrefix, "Maven"),
49+
)(s)
50+
},
51+
Config: testAccDataSourceFeedsWithFilterConfig(localName+"_maven", "Maven"),
52+
},
53+
{
54+
Check: func(s *terraform.State) error {
55+
helmPrefix := fmt.Sprintf("data.octopusdeploy_feeds.%s_helm", localName)
56+
return resource.ComposeTestCheckFunc(
57+
testAccCheckFeedsDataSourceID(helmPrefix),
58+
testAccCheckFeedsFilteredByType(helmPrefix, "Helm"),
59+
)(s)
60+
},
61+
Config: testAccDataSourceFeedsWithFilterConfig(localName+"_helm", "Helm"),
62+
},
3363
{
3464
Check: resource.ComposeTestCheckFunc(
3565
testAccCheckFeedsDataSourceID(prefix),
@@ -65,6 +95,44 @@ func testAccDataSourceFeedsEmpty(localName string) string {
6595
return fmt.Sprintf(`data "octopusdeploy_feeds" "%s" {}`, localName)
6696
}
6797

98+
func testAccCheckFeedsFilteredByType(n string, expectedType string) resource.TestCheckFunc {
99+
return func(s *terraform.State) error {
100+
rs, ok := s.RootModule().Resources[n]
101+
if !ok {
102+
return fmt.Errorf("cannot find Feeds data source: %s", n)
103+
}
104+
105+
count := rs.Primary.Attributes["feeds.#"]
106+
if count == "" {
107+
return fmt.Errorf("feeds count not set")
108+
}
109+
110+
if count == "0" {
111+
return nil
112+
}
113+
114+
feedCount := 0
115+
for key, value := range rs.Primary.Attributes {
116+
if key == fmt.Sprintf("feeds.%d.feed_type", feedCount) {
117+
if value != expectedType {
118+
return fmt.Errorf("feed %d has unexpected type: expected %s, got %s", feedCount, expectedType, value)
119+
}
120+
feedCount++
121+
}
122+
}
123+
124+
return nil
125+
}
126+
}
127+
128+
func testAccDataSourceFeedsWithFilterConfig(localName string, feedType string) string {
129+
return fmt.Sprintf(`%s
130+
131+
data "octopusdeploy_feeds" "%s" {
132+
feed_type = "%s"
133+
}`, createTestAccDataSourceFeedsConfig(), localName, feedType)
134+
}
135+
68136
func createTestAccDataSourceFeedsConfig() string {
69137
return `resource "octopusdeploy_nuget_feed" "nuget_feed" {
70138
feed_uri = "https://api.nuget.org/v3/index.json"

0 commit comments

Comments
 (0)