package argo import ( "bytes" "encoding/json" "fmt" "os" "testing" "github.com/stretchr/testify/assert" ) func TestGenerateStarted(t *testing.T) { tests := []struct { argo *argo expected string }{ { &argo{ startedTimestamp: "2024-08-09T19:00:07Z", machine: "edge-runner-2", pull: "10272", commit: "c4d41a9f151695a417b523cf56b250289ffd9152", repo: "edge-infra", rosaVersionString: "0.20.0+commit.c4d41a9", }, "testdata/started.json", }, } for i, test := range tests { argo := &argo{} t.Run(fmt.Sprintf("%s_%d", t.Name(), i), func(t *testing.T) { argo = test.argo result, err := argo.generateStarted() assert.NoError(t, err) // pretty print the json string dst := &bytes.Buffer{} err = json.Indent(dst, []byte(result), "", " ") assert.NoError(t, err) // file contents should already be pretty dat, err := os.ReadFile(test.expected) assert.NoError(t, err) assert.EqualValues(t, dst.String(), string(dat)) }) } } func TestGenerateFinished(t *testing.T) { tests := []struct { argo *argo expected string }{ { &argo{ finishedTimestamp: "2024-08-09T19:10:07Z", passed: "Succeeded", machine: "vroom-vroom-machine", runID: "123", workflow: "hourly-stable", metadata: `{"clusterType":"gke","clusterVersion":"1.28.10-gke"}`, }, "testdata/finished.json", }, } for i, test := range tests { argo := &argo{} t.Run(fmt.Sprintf("%s_%d", t.Name(), i), func(t *testing.T) { argo = test.argo result, err := argo.generateFinished("123-ab45c") assert.NoError(t, err) // pretty print the json string dst := &bytes.Buffer{} err = json.Indent(dst, []byte(result), "", " ") assert.NoError(t, err) // file contents should already be pretty dat, err := os.ReadFile(test.expected) assert.NoError(t, err) assert.EqualValues(t, dst.String(), string(dat)) }) } }