Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Oct 10, 2023
1 parent 1a07a33 commit 976793e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/actions/validate-endpoints/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,13 @@ runs:
exit 1
fi
fi
- name: Validate /app/metrics endpoint
shell: bash
run: |
appStatusMetric=$(curl -s --fail --show-error localhost:8888/api/v1/app/metrics | jq '."X-Replicated-AppStatus"' | tr -d '\n')
if [ "$appStatusMetric" != "ready" ]; then
echo "Expected app status metric 'X-Replicated-AppStatus' to be 'ready', but is set to '$appStatusMetric'."
exit 1
fi
3 changes: 1 addition & 2 deletions pkg/handlers/types/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package types

type ErrorResponse struct {
Error string `json:"error,omitempty"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
31 changes: 31 additions & 0 deletions pkg/heartbeat/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,42 @@ package heartbeat
import (
"testing"

"github.com/replicatedhq/replicated-sdk/pkg/heartbeat/types"
"github.com/replicatedhq/replicated-sdk/pkg/k8sutil"
"github.com/replicatedhq/replicated-sdk/pkg/util"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/kubernetes/fake"
)

func TestGetHeartbeatInfoHeaders(t *testing.T) {
heartbeatInfo := &types.HeartbeatInfo{
AppStatus: "ready",
ClusterID: "cluster-123",
InstanceID: "instance-456",
ChannelID: "channel-789",
ChannelSequence: 42,
K8sVersion: "v1.20.2+k3s1",
K8sDistribution: "k3s",
}

headers := GetHeartbeatInfoHeaders(heartbeatInfo)

expectedHeaders := map[string]string{
"X-Replicated-K8sVersion": "v1.20.2+k3s1",
"X-Replicated-AppStatus": "ready",
"X-Replicated-ClusterID": "cluster-123",
"X-Replicated-InstanceID": "instance-456",
"X-Replicated-DownstreamChannelID": "channel-789",
"X-Replicated-DownstreamChannelSequence": "42",
"X-Replicated-K8sDistribution": "k3s",
}

assert.Equal(t, expectedHeaders, headers)

nilHeaders := GetHeartbeatInfoHeaders(nil)
assert.Empty(t, nilHeaders)
}

func TestCanReport(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 976793e

Please sign in to comment.