Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 219 additions & 49 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Lint
uses: golangci/golangci-lint-action@v8
with:
Expand All @@ -20,104 +18,276 @@ jobs:
test:
name: Unit Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Test
run: make test

test-sysdig-monitor:
name: Sysdig Monitor Acceptance Tests
# ============================================
# Sysdig Secure - Dynamic Matrix
# ============================================
list-sysdig-secure-tests:
name: List Secure Tests
runs-on: ubuntu-latest
needs: test

outputs:
matrix: ${{ steps.list.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- id: list
run: |
files=$(grep -l "tf_acc_sysdig_secure" sysdig/*_test.go | xargs -I{} basename {} .go || echo "")
Comment thread
tembleking marked this conversation as resolved.
if [ -z "$files" ]; then
echo "matrix=[]" >> $GITHUB_OUTPUT
else
matrix=$(echo "$files" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
fi

- name: Set up Go
uses: actions/setup-go@v5
test-sysdig-secure:
name: "Secure: ${{ matrix.file }}"
runs-on: ubuntu-latest
needs: list-sysdig-secure-tests
strategy:
fail-fast: false
max-parallel: 20
matrix:
file: ${{ fromJson(needs.list-sysdig-secure-tests.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Test
run: make testacc
- name: Run tests from ${{ matrix.file }}
run: |
tests=$(grep -oh "func Test[A-Za-z0-9_]*" sysdig/${{ matrix.file }}.go | sed 's/func //' | tr '\n' '|' | sed 's/|$//')
Comment thread
tembleking marked this conversation as resolved.
if [ -n "$tests" ]; then
echo "Running tests: $tests"
CGO_ENABLED=1 TF_ACC=1 go test ./sysdig -v -tags=tf_acc_sysdig_secure -timeout 30m -race -run "^($tests)$"
else
echo "No tests found in file"
fi
env:
Comment thread
tembleking marked this conversation as resolved.
TEST_SUITE: tf_acc_sysdig_monitor
SYSDIG_MONITOR_API_TOKEN: ${{ secrets.KUBELAB_MONITOR_API_TOKEN }}
SYSDIG_SECURE_API_TOKEN: ${{ secrets.KUBELAB_SECURE_API_TOKEN }}

test-sysdig-secure:
name: Sysdig Secure Acceptance Tests
# ============================================
# Sysdig Monitor - Dynamic Matrix
# ============================================
list-sysdig-monitor-tests:
name: List Monitor Tests
runs-on: ubuntu-latest
needs: test

outputs:
matrix: ${{ steps.list.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- id: list
run: |
files=$(grep -l "tf_acc_sysdig_monitor" sysdig/*_test.go | xargs -I{} basename {} .go || echo "")
Comment thread
tembleking marked this conversation as resolved.
Comment thread
tembleking marked this conversation as resolved.
if [ -z "$files" ]; then
echo "matrix=[]" >> $GITHUB_OUTPUT
else
matrix=$(echo "$files" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
fi

- name: Set up Go
uses: actions/setup-go@v5
test-sysdig-monitor:
name: "Monitor: ${{ matrix.file }}"
runs-on: ubuntu-latest
needs: list-sysdig-monitor-tests
strategy:
fail-fast: false
max-parallel: 20
matrix:
file: ${{ fromJson(needs.list-sysdig-monitor-tests.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Test
run: make testacc
- name: Run tests from ${{ matrix.file }}
run: |
tests=$(grep -oh "func Test[A-Za-z0-9_]*" sysdig/${{ matrix.file }}.go | sed 's/func //' | tr '\n' '|' | sed 's/|$//')
Comment thread
tembleking marked this conversation as resolved.
if [ -n "$tests" ]; then
echo "Running tests: $tests"
CGO_ENABLED=1 TF_ACC=1 go test ./sysdig -v -tags=tf_acc_sysdig_monitor -timeout 30m -race -run "^($tests)$"
Comment thread
tembleking marked this conversation as resolved.
else
echo "No tests found in file"
fi
env:
TEST_SUITE: tf_acc_sysdig_secure
SYSDIG_MONITOR_API_TOKEN: ${{ secrets.KUBELAB_MONITOR_API_TOKEN }}
SYSDIG_SECURE_API_TOKEN: ${{ secrets.KUBELAB_SECURE_API_TOKEN }}

test-ibm-monitor:
name: IBM Monitor Acceptance Tests
# ============================================
# IBM Monitor - Dynamic Matrix
# ============================================
list-ibm-monitor-tests:
name: List IBM Monitor Tests
runs-on: ubuntu-latest
needs: test

outputs:
matrix: ${{ steps.list.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- id: list
run: |
files=$(grep -l "tf_acc_ibm_monitor" sysdig/*_test.go | xargs -I{} basename {} .go || echo "")
Comment thread
tembleking marked this conversation as resolved.
Outdated
Comment thread
tembleking marked this conversation as resolved.
Outdated
if [ -z "$files" ]; then
echo "matrix=[]" >> $GITHUB_OUTPUT
else
matrix=$(echo "$files" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
fi

- name: Set up Go
uses: actions/setup-go@v5
test-ibm-monitor:
name: "IBM Monitor: ${{ matrix.file }}"
runs-on: ubuntu-latest
needs: list-ibm-monitor-tests
strategy:
fail-fast: false
max-parallel: 3
matrix:
file: ${{ fromJson(needs.list-ibm-monitor-tests.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Test
run: make testacc
- name: Run tests from ${{ matrix.file }}
run: |
tests=$(grep -oh "func Test[A-Za-z0-9_]*" sysdig/${{ matrix.file }}.go | sed 's/func //' | tr '\n' '|' | sed 's/|$//')
Comment thread
tembleking marked this conversation as resolved.
Outdated
if [ -n "$tests" ]; then
echo "Running tests: $tests"
CGO_ENABLED=1 TF_ACC=1 go test ./sysdig -v -tags=tf_acc_ibm_monitor -timeout 30m -race -run "^($tests)$"
Comment thread
tembleking marked this conversation as resolved.
Outdated
else
echo "No tests found in file"
fi
env:
TEST_SUITE: tf_acc_ibm_monitor
SYSDIG_IBM_MONITOR_API_KEY: ${{ secrets.TERRAFORM_IBM_API_KEY }}
SYSDIG_IBM_MONITOR_INSTANCE_ID: ${{ secrets.TERRAFORM_IBM_MONITOR_INSTANCE_ID }}
SYSDIG_IBM_MONITOR_IAM_URL: "https://iam.cloud.ibm.com"
SYSDIG_MONITOR_URL: "https://eu-gb.monitoring.cloud.ibm.com"
IBM_EVENT_NOTIFICATION_INSTANCE_ID: ${{ secrets.IBM_EVENT_NOTIFICATION_INSTANCE_ID }}

test-ibm-secure:
name: IBM Secure Acceptance Tests
# ============================================
# IBM Secure - Dynamic Matrix
# ============================================
list-ibm-secure-tests:
name: List IBM Secure Tests
runs-on: ubuntu-latest
needs: test

outputs:
matrix: ${{ steps.list.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- id: list
run: |
files=$(grep -l "tf_acc_ibm_secure" sysdig/*_test.go | xargs -I{} basename {} .go || echo "")
Comment thread
tembleking marked this conversation as resolved.
Outdated
Comment thread
tembleking marked this conversation as resolved.
Outdated
if [ -z "$files" ]; then
echo "matrix=[]" >> $GITHUB_OUTPUT
else
matrix=$(echo "$files" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
fi

- name: Set up Go
uses: actions/setup-go@v5
test-ibm-secure:
name: "IBM Secure: ${{ matrix.file }}"
runs-on: ubuntu-latest
needs: list-ibm-secure-tests
strategy:
fail-fast: false
max-parallel: 3
matrix:
file: ${{ fromJson(needs.list-ibm-secure-tests.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Test
run: make testacc
- name: Run tests from ${{ matrix.file }}
run: |
tests=$(grep -oh "func Test[A-Za-z0-9_]*" sysdig/${{ matrix.file }}.go | sed 's/func //' | tr '\n' '|' | sed 's/|$//')
Comment thread
tembleking marked this conversation as resolved.
Outdated
if [ -n "$tests" ]; then
echo "Running tests: $tests"
CGO_ENABLED=1 TF_ACC=1 go test ./sysdig -v -tags=tf_acc_ibm_secure -timeout 30m -race -run "^($tests)$"
Comment thread
tembleking marked this conversation as resolved.
Outdated
else
echo "No tests found in file"
fi
env:
TEST_SUITE: tf_acc_ibm_secure
SYSDIG_IBM_SECURE_API_KEY: ${{ secrets.TERRAFORM_IBM_API_KEY }}
SYSDIG_IBM_SECURE_INSTANCE_ID: ${{ secrets.TERRAFORM_IBM_SECURE_INSTANCE_ID }}
SYSDIG_IBM_SECURE_IAM_URL: "https://iam.cloud.ibm.com"
SYSDIG_SECURE_URL: "https://eu-gb.monitoring.cloud.ibm.com"

# ============================================
# Aggregator Jobs - Collect matrix results
# ============================================
sysdig-secure-result:
name: Sysdig Secure Tests Result
runs-on: ubuntu-latest
needs: [list-sysdig-secure-tests, test-sysdig-secure]
if: always()
steps:
- name: Check test results
run: |
if [ "${{ needs.test-sysdig-secure.result }}" == "success" ] || [ "${{ needs.test-sysdig-secure.result }}" == "skipped" ]; then
echo "All Sysdig Secure tests passed"
exit 0
else
echo "Some Sysdig Secure tests failed"
exit 1
fi

sysdig-monitor-result:
name: Sysdig Monitor Tests Result
runs-on: ubuntu-latest
needs: [list-sysdig-monitor-tests, test-sysdig-monitor]
if: always()
steps:
- name: Check test results
run: |
if [ "${{ needs.test-sysdig-monitor.result }}" == "success" ] || [ "${{ needs.test-sysdig-monitor.result }}" == "skipped" ]; then
echo "All Sysdig Monitor tests passed"
exit 0
else
echo "Some Sysdig Monitor tests failed"
exit 1
fi

ibm-monitor-result:
name: IBM Monitor Tests Result
runs-on: ubuntu-latest
needs: [list-ibm-monitor-tests, test-ibm-monitor]
if: always()
steps:
- name: Check test results
run: |
if [ "${{ needs.test-ibm-monitor.result }}" == "success" ] || [ "${{ needs.test-ibm-monitor.result }}" == "skipped" ]; then
echo "All IBM Monitor tests passed"
exit 0
else
echo "Some IBM Monitor tests failed"
exit 1
fi

ibm-secure-result:
name: IBM Secure Tests Result
runs-on: ubuntu-latest
needs: [list-ibm-secure-tests, test-ibm-secure]
if: always()
steps:
- name: Check test results
run: |
if [ "${{ needs.test-ibm-secure.result }}" == "success" ] || [ "${{ needs.test-ibm-secure.result }}" == "skipped" ]; then
echo "All IBM Secure tests passed"
exit 0
else
echo "Some IBM Secure tests failed"
exit 1
fi
22 changes: 21 additions & 1 deletion sysdig/data_source_sysdig_secure_rule_stateful_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package sysdig_test
import (
"fmt"
"os"
"strconv"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Comment thread
tembleking marked this conversation as resolved.

"github.com/draios/terraform-provider-sysdig/sysdig"
)
Expand All @@ -35,13 +37,31 @@ func TestAccRuleStatefulCountDataSource(t *testing.T) {
{
Config: ruleStatefulCountDataSource(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.sysdig_secure_rule_stateful_count.data_stateful_rule_append", "rule_count", "2"),
testCheckRuleCountAtLeast("data.sysdig_secure_rule_stateful_count.data_stateful_rule_append", 2),
),
},
},
})
}

func testCheckRuleCountAtLeast(resourceName string, minCount int) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("resource not found: %s", resourceName)
}
countStr := rs.Primary.Attributes["rule_count"]
count, err := strconv.Atoi(countStr)
if err != nil {
return fmt.Errorf("rule_count is not a valid integer: %s", countStr)
}
if count < minCount {
return fmt.Errorf("rule_count expected >= %d, got %d", minCount, count)
}
return nil
}
}

func ruleStatefulCountDataSource() string {
return fmt.Sprintf(`
%s
Expand Down
Loading
Loading